tgpm.resource_permission package¶
Submodules¶
tgpm.resource_permission.repository module¶
- class tgpm.resource_permission.repository.ResourcePermissionRepository(session: AsyncSession, statement_generator: ResourcePermissionStatementGenerator)¶
Bases:
Generic
Repository class for resource permissions.
- async get_permissions(permission_queries: Sequence[Select]) list[PermissionModelProtocol] ¶
Execute a list of query and return a permission if matching or none for each query
- Parameters:
permission_queries (Sequence[Select]) – the list of queries to execute
- Returns:
a list of permission models or None
- async has_permission_on(user_id: Any, resource_id: Any, permission_type: PermissionType) bool ¶
Check if the user has permission on the resource.
- Parameters:
user_id (T1) – The user ID.
resource_id (T2) – The resource ID.
permission_type (PermissionType) – The permission type.
- Returns:
True if the user has permission, False otherwise.
- Return type:
bool
tgpm.resource_permission.statement_generator module¶
- class tgpm.resource_permission.statement_generator.ResourcePermissionStatementGenerator(registry: Registry, resource_type: type[DeclarativeBase])¶
Bases:
Generic
Class to generate permission statements for a given resource.
- get_parent_permission_queries(user_id: Any, resource_id: Any, permission_type: PermissionType)¶
Get parent permission queries for a given user, resource, and permission type.
- Parameters:
user_id (T1) – The user ID.
resource_id (T2) – The resource ID.
permission_type (PermissionType) – The permission type.
- Returns:
List of parent permission queries.
- Return type:
list[Select]
- get_permission_queries(user_id: Any, resource_id: Any, permission_type: PermissionType)¶
Get all permission queries for a given user, resource, and permission type.
- Parameters:
user_id (T1) – The user ID.
resource_id (T2) – The resource ID.
permission_type (PermissionType) – The permission type.
- Returns:
List of permission queries.
- Return type:
list[Select]
- make_query_for_parent_model(permission_model: PermissionModelProtocol, user_id: Any, resource_id: Any, permission_type: PermissionType) Select ¶
Generate a query for the parent permission model.
- Parameters:
permission_model (PermissionModelProtocol) – The permission model.
user_id (T1) – The user ID.
resource_id (T2) – The resource ID.
permission_type (PermissionType) – The permission type.
- Returns:
The generated query.
- Return type:
Select