scim: Extract ROLE_TYPE_TO_NAME dict to UserProfile.

This allows these mappings to used in other APIs. Specifically, we want
to use this for syncing role during SAML auth.
This commit is contained in:
Mateusz Mandera
2024-08-16 00:29:51 +02:00
committed by Tim Abbott
parent 76b41e433a
commit 8c1a1ea8db
3 changed files with 15 additions and 14 deletions

View File

@@ -603,6 +603,17 @@ class UserProfile(AbstractBaseUser, PermissionsMixin, UserBaseSettings):
ROLE_GUEST: gettext_lazy("Guest"),
}
# Mapping of role ids to simple string identifiers for the roles,
# to be used in API contexts such as SCIM provisioning.
ROLE_ID_TO_API_NAME = {
ROLE_REALM_OWNER: "owner",
ROLE_REALM_ADMINISTRATOR: "administrator",
ROLE_MODERATOR: "moderator",
ROLE_MEMBER: "member",
ROLE_GUEST: "guest",
}
ROLE_API_NAME_TO_ID = {v: k for k, v in ROLE_ID_TO_API_NAME.items()}
class Meta:
indexes = [
models.Index(Upper("email"), name="upper_userprofile_email_idx"),