Module supertokens_python.recipe.userroles.interfaces

Expand source code
from abc import ABC, abstractmethod
from typing import Any, Dict, List, Union


class AddRoleToUserOkResult:
    def __init__(self, did_user_already_have_role: bool):
        self.did_user_already_have_role = did_user_already_have_role


class UnknownRoleError:
    pass


class RemoveUserRoleOkResult:
    def __init__(self, did_user_have_role: bool):
        self.did_user_have_role = did_user_have_role


class GetRolesForUserOkResult:
    def __init__(self, roles: List[str]):
        self.roles = roles


class GetUsersThatHaveRoleOkResult:
    def __init__(self, users: List[str]):
        self.users = users


class CreateNewRoleOrAddPermissionsOkResult:
    def __init__(self, created_new_role: bool):
        self.created_new_role = created_new_role


class GetPermissionsForRoleOkResult:
    def __init__(self, permissions: List[str]):
        self.permissions = permissions


class RemovePermissionsFromRoleOkResult:
    pass


class GetRolesThatHavePermissionOkResult:
    def __init__(self, roles: List[str]):
        self.roles = roles


class DeleteRoleOkResult:
    def __init__(self, did_role_exist: bool):
        self.did_role_exist = did_role_exist


class GetAllRolesOkResult:
    def __init__(self, roles: List[str]):
        self.roles = roles


class RecipeInterface(ABC):
    @abstractmethod
    async def add_role_to_user(
        self,
        user_id: str,
        role: str,
        tenant_id: str,
        user_context: Dict[str, Any],
    ) -> Union[AddRoleToUserOkResult, UnknownRoleError]:
        pass

    @abstractmethod
    async def remove_user_role(
        self,
        user_id: str,
        role: str,
        tenant_id: str,
        user_context: Dict[str, Any],
    ) -> Union[RemoveUserRoleOkResult, UnknownRoleError]:
        pass

    @abstractmethod
    async def get_roles_for_user(
        self, user_id: str, tenant_id: str, user_context: Dict[str, Any]
    ) -> GetRolesForUserOkResult:
        pass

    @abstractmethod
    async def get_users_that_have_role(
        self, role: str, tenant_id: str, user_context: Dict[str, Any]
    ) -> Union[GetUsersThatHaveRoleOkResult, UnknownRoleError]:
        pass

    @abstractmethod
    async def create_new_role_or_add_permissions(
        self, role: str, permissions: List[str], user_context: Dict[str, Any]
    ) -> CreateNewRoleOrAddPermissionsOkResult:
        pass

    @abstractmethod
    async def get_permissions_for_role(
        self, role: str, user_context: Dict[str, Any]
    ) -> Union[GetPermissionsForRoleOkResult, UnknownRoleError]:
        pass

    @abstractmethod
    async def remove_permissions_from_role(
        self, role: str, permissions: List[str], user_context: Dict[str, Any]
    ) -> Union[RemovePermissionsFromRoleOkResult, UnknownRoleError]:
        pass

    @abstractmethod
    async def get_roles_that_have_permission(
        self, permission: str, user_context: Dict[str, Any]
    ) -> GetRolesThatHavePermissionOkResult:
        pass

    @abstractmethod
    async def delete_role(
        self, role: str, user_context: Dict[str, Any]
    ) -> DeleteRoleOkResult:
        pass

    @abstractmethod
    async def get_all_roles(self, user_context: Dict[str, Any]) -> GetAllRolesOkResult:
        pass


class APIInterface(ABC):
    pass

Classes

class APIInterface

Helper class that provides a standard way to create an ABC using inheritance.

Expand source code
class APIInterface(ABC):
    pass

Ancestors

  • abc.ABC
class AddRoleToUserOkResult (did_user_already_have_role: bool)
Expand source code
class AddRoleToUserOkResult:
    def __init__(self, did_user_already_have_role: bool):
        self.did_user_already_have_role = did_user_already_have_role
class CreateNewRoleOrAddPermissionsOkResult (created_new_role: bool)
Expand source code
class CreateNewRoleOrAddPermissionsOkResult:
    def __init__(self, created_new_role: bool):
        self.created_new_role = created_new_role
class DeleteRoleOkResult (did_role_exist: bool)
Expand source code
class DeleteRoleOkResult:
    def __init__(self, did_role_exist: bool):
        self.did_role_exist = did_role_exist
class GetAllRolesOkResult (roles: List[str])
Expand source code
class GetAllRolesOkResult:
    def __init__(self, roles: List[str]):
        self.roles = roles
class GetPermissionsForRoleOkResult (permissions: List[str])
Expand source code
class GetPermissionsForRoleOkResult:
    def __init__(self, permissions: List[str]):
        self.permissions = permissions
class GetRolesForUserOkResult (roles: List[str])
Expand source code
class GetRolesForUserOkResult:
    def __init__(self, roles: List[str]):
        self.roles = roles
class GetRolesThatHavePermissionOkResult (roles: List[str])
Expand source code
class GetRolesThatHavePermissionOkResult:
    def __init__(self, roles: List[str]):
        self.roles = roles
class GetUsersThatHaveRoleOkResult (users: List[str])
Expand source code
class GetUsersThatHaveRoleOkResult:
    def __init__(self, users: List[str]):
        self.users = users
class RecipeInterface

Helper class that provides a standard way to create an ABC using inheritance.

Expand source code
class RecipeInterface(ABC):
    @abstractmethod
    async def add_role_to_user(
        self,
        user_id: str,
        role: str,
        tenant_id: str,
        user_context: Dict[str, Any],
    ) -> Union[AddRoleToUserOkResult, UnknownRoleError]:
        pass

    @abstractmethod
    async def remove_user_role(
        self,
        user_id: str,
        role: str,
        tenant_id: str,
        user_context: Dict[str, Any],
    ) -> Union[RemoveUserRoleOkResult, UnknownRoleError]:
        pass

    @abstractmethod
    async def get_roles_for_user(
        self, user_id: str, tenant_id: str, user_context: Dict[str, Any]
    ) -> GetRolesForUserOkResult:
        pass

    @abstractmethod
    async def get_users_that_have_role(
        self, role: str, tenant_id: str, user_context: Dict[str, Any]
    ) -> Union[GetUsersThatHaveRoleOkResult, UnknownRoleError]:
        pass

    @abstractmethod
    async def create_new_role_or_add_permissions(
        self, role: str, permissions: List[str], user_context: Dict[str, Any]
    ) -> CreateNewRoleOrAddPermissionsOkResult:
        pass

    @abstractmethod
    async def get_permissions_for_role(
        self, role: str, user_context: Dict[str, Any]
    ) -> Union[GetPermissionsForRoleOkResult, UnknownRoleError]:
        pass

    @abstractmethod
    async def remove_permissions_from_role(
        self, role: str, permissions: List[str], user_context: Dict[str, Any]
    ) -> Union[RemovePermissionsFromRoleOkResult, UnknownRoleError]:
        pass

    @abstractmethod
    async def get_roles_that_have_permission(
        self, permission: str, user_context: Dict[str, Any]
    ) -> GetRolesThatHavePermissionOkResult:
        pass

    @abstractmethod
    async def delete_role(
        self, role: str, user_context: Dict[str, Any]
    ) -> DeleteRoleOkResult:
        pass

    @abstractmethod
    async def get_all_roles(self, user_context: Dict[str, Any]) -> GetAllRolesOkResult:
        pass

Ancestors

  • abc.ABC

Subclasses

Methods

async def add_role_to_user(self, user_id: str, role: str, tenant_id: str, user_context: Dict[str, Any]) ‑> Union[AddRoleToUserOkResultUnknownRoleError]
Expand source code
@abstractmethod
async def add_role_to_user(
    self,
    user_id: str,
    role: str,
    tenant_id: str,
    user_context: Dict[str, Any],
) -> Union[AddRoleToUserOkResult, UnknownRoleError]:
    pass
async def create_new_role_or_add_permissions(self, role: str, permissions: List[str], user_context: Dict[str, Any]) ‑> CreateNewRoleOrAddPermissionsOkResult
Expand source code
@abstractmethod
async def create_new_role_or_add_permissions(
    self, role: str, permissions: List[str], user_context: Dict[str, Any]
) -> CreateNewRoleOrAddPermissionsOkResult:
    pass
async def delete_role(self, role: str, user_context: Dict[str, Any]) ‑> DeleteRoleOkResult
Expand source code
@abstractmethod
async def delete_role(
    self, role: str, user_context: Dict[str, Any]
) -> DeleteRoleOkResult:
    pass
async def get_all_roles(self, user_context: Dict[str, Any]) ‑> GetAllRolesOkResult
Expand source code
@abstractmethod
async def get_all_roles(self, user_context: Dict[str, Any]) -> GetAllRolesOkResult:
    pass
async def get_permissions_for_role(self, role: str, user_context: Dict[str, Any]) ‑> Union[GetPermissionsForRoleOkResultUnknownRoleError]
Expand source code
@abstractmethod
async def get_permissions_for_role(
    self, role: str, user_context: Dict[str, Any]
) -> Union[GetPermissionsForRoleOkResult, UnknownRoleError]:
    pass
async def get_roles_for_user(self, user_id: str, tenant_id: str, user_context: Dict[str, Any]) ‑> GetRolesForUserOkResult
Expand source code
@abstractmethod
async def get_roles_for_user(
    self, user_id: str, tenant_id: str, user_context: Dict[str, Any]
) -> GetRolesForUserOkResult:
    pass
async def get_roles_that_have_permission(self, permission: str, user_context: Dict[str, Any]) ‑> GetRolesThatHavePermissionOkResult
Expand source code
@abstractmethod
async def get_roles_that_have_permission(
    self, permission: str, user_context: Dict[str, Any]
) -> GetRolesThatHavePermissionOkResult:
    pass
async def get_users_that_have_role(self, role: str, tenant_id: str, user_context: Dict[str, Any]) ‑> Union[GetUsersThatHaveRoleOkResultUnknownRoleError]
Expand source code
@abstractmethod
async def get_users_that_have_role(
    self, role: str, tenant_id: str, user_context: Dict[str, Any]
) -> Union[GetUsersThatHaveRoleOkResult, UnknownRoleError]:
    pass
async def remove_permissions_from_role(self, role: str, permissions: List[str], user_context: Dict[str, Any]) ‑> Union[RemovePermissionsFromRoleOkResultUnknownRoleError]
Expand source code
@abstractmethod
async def remove_permissions_from_role(
    self, role: str, permissions: List[str], user_context: Dict[str, Any]
) -> Union[RemovePermissionsFromRoleOkResult, UnknownRoleError]:
    pass
async def remove_user_role(self, user_id: str, role: str, tenant_id: str, user_context: Dict[str, Any]) ‑> Union[RemoveUserRoleOkResultUnknownRoleError]
Expand source code
@abstractmethod
async def remove_user_role(
    self,
    user_id: str,
    role: str,
    tenant_id: str,
    user_context: Dict[str, Any],
) -> Union[RemoveUserRoleOkResult, UnknownRoleError]:
    pass
class RemovePermissionsFromRoleOkResult
Expand source code
class RemovePermissionsFromRoleOkResult:
    pass
class RemoveUserRoleOkResult (did_user_have_role: bool)
Expand source code
class RemoveUserRoleOkResult:
    def __init__(self, did_user_have_role: bool):
        self.did_user_have_role = did_user_have_role
class UnknownRoleError
Expand source code
class UnknownRoleError:
    pass