diff --git a/corporate/views.py b/corporate/views.py index 66c99890e9..42c7e6b53e 100644 --- a/corporate/views.py +++ b/corporate/views.py @@ -192,14 +192,7 @@ def sponsorship(request: HttpRequest, user: UserProfile, realm = user.realm requested_by = user.full_name - - role_id_to_name_map = { - UserProfile.ROLE_REALM_OWNER: "Realm owner", - UserProfile.ROLE_REALM_ADMINISTRATOR: "Realm adminstrator", - UserProfile.ROLE_MEMBER: "Member", - UserProfile.ROLE_GUEST: "Guest" - } - user_role = role_id_to_name_map[user.role] + user_role = user.get_role_name() support_realm_uri = get_realm(settings.STAFF_SUBDOMAIN).uri support_url = urljoin(support_realm_uri, urlunsplit(("", "", reverse('analytics.views.support'), diff --git a/zerver/models.py b/zerver/models.py index bc72efbe8b..dbac96581c 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -1124,6 +1124,16 @@ class UserProfile(AbstractBaseUser, PermissionsMixin): presence_enabled=bool, ) + ROLE_ID_TO_NAME_MAP = { + ROLE_REALM_OWNER: "Realm owner", + ROLE_REALM_ADMINISTRATOR: "Realm adminstrator", + ROLE_MEMBER: "Member", + ROLE_GUEST: "Guest" + } + + def get_role_name(self) -> str: + return self.ROLE_ID_TO_NAME_MAP[self.role] + @property def profile_data(self) -> ProfileData: values = CustomProfileFieldValue.objects.filter(user_profile=self)