"""Module for shared types.""" from dataclasses import dataclass from enum import StrEnum from permissions.constants import constants @dataclass class ProfileInfo: """A minimal representation of a Profile.""" profile_type: str profile_id: int roles: list[str] uuid: str class TenantType(StrEnum): """Enum for the different types of tenants supported in Settings.""" PARENT_COMPANY = constants.PARENT_COMPANY_TENANT_TYPE ACCOUNT = constants.ACCOUNT_TENANT_TYPE SUBACCOUNT = constants.SUBACCOUNT_TENANT_TYPE LABEL_PARTICIPANT = constants.LABEL_PARTICIPANT_TENANT_TYPE COLLABORATOR = constants.COLLABORATOR_TENANT_TYPE @dataclass class Tenant: """A tenant object (Vendor, SubAccount, Collaborator, LabelParticipant, or ParentCompany).""" # These are the attributes all of them definitely have. # Otherwise, it depends on the type of tenant. tenant_type: TenantType tenant_uuid: str def is_vendor_star( self, ) -> bool: """Check if the Tenant is considered Vendor*.""" return self.tenant_uuid == constants.VENDOR_STAR_UUID @dataclass class TenantWithName(Tenant): """Object extending Tenant with a name.""" tenant_name: str @dataclass class AccessibleTenant(Tenant): """Object extending Tenant and indicating whether it's accessible.""" access: bool = False @dataclass() class TenantWithV2Roles(Tenant): """Object containing a tenant uuid, type, and the v2 roles a user has for that tenant.""" roles: list[str] = None @dataclass class AdminableTenant: """Dict containing a tenant and a user's profiles linked to it.""" tenant: Tenant profiles: list[ProfileInfo] @dataclass class AdminableTenantDataloader: """Dict containing a tenant and a user's profiles linked to it.""" identity_uuid: str tenants: list[AdminableTenant] @dataclass class IdentityTenantsWithV2Roles: """Dict containing a tenant and a user's profiles linked to it.""" identity_uuid: str tenants: list[TenantWithV2Roles] @dataclass class TenantRolesInput: """Representation of a diff in access to apply for a user and tenant.""" roles_to_attach: list[str] roles_to_detach: list[str] tenant: Tenant @dataclass class IdentityInput: """An Identity object.""" email: str first_name: str last_name: str @dataclass class Identity: """Representation of a neo4j identity.""" id: str # noqa: A003 first_name: str last_name: str name: str email: str auth0_user_id: str active: str user_types: list[str] default_brand: str | None def is_pending(self) -> bool: """Check if the Identity is in pending status.""" return self.id == self.auth0_user_id or not self.auth0_user_id @dataclass class Auth0Context: """Auth0-specific information about an identity.""" organizations: list[str] auth0_user_id: str @dataclass class IdentityWithAuth0(Identity): """An identity object with Auth0 data.""" auth0_context: Auth0Context | None @dataclass class IdentityComplete(IdentityWithAuth0): """A complete Identity object with Auth0 and Profiles.""" profiles: list[ProfileInfo] @dataclass class AdminIdentity(Identity): """An identity object with admin data.""" settings_profile: ProfileInfo @dataclass class Vendor: """A Vendor object.""" vendor_uuid: str vendor_id: int | str @dataclass class Subaccount: """A Subaccount object.""" subaccount_uuid: str subaccount_id: int @dataclass class ProfileInfoWithTenantRelationship(ProfileInfo): """A ProfileInfo object with a tenant relationship attribute.""" tenant_relationship: str @dataclass class Auth0UserMetadata: """Metadata from Auth0 user_metadata field.""" defaultBrand: str | None = None @dataclass class Auth0UserResponse: """Response from ows-users /auth0/users/{auth0_user_id} endpoint.""" user_metadata: Auth0UserMetadata