Skip to content

Permission Checker

permission_checker

Protocol for permission-checking implementations.

PermissionChecker

Bases: Protocol

Protocol for any callable that decides whether a permission is granted.

Class Type Parameters:

Name Bound or Constraints Description Default
PermissionCheckContext

The application-defined context for permission checks.

required
Example
class MyChecker(PermissionChecker[dict]):
    async def check(self, context: dict, permission: Permission) -> bool:
        return permission in context.get("grants", set())


checker = MyChecker()
result = await checker.check({"grants": {Permission.READ}}, Permission.READ)
Source code in src/forging_blocks/domain/permissions/permission_checker.py
@runtime_checkable
class PermissionChecker[PermissionCheckContext](Protocol):
    """Protocol for any callable that decides whether a permission is granted.

    Type Args:
        PermissionCheckContext: The application-defined context for permission checks.

    Example:
        ```python
        class MyChecker(PermissionChecker[dict]):
            async def check(self, context: dict, permission: Permission) -> bool:
                return permission in context.get("grants", set())


        checker = MyChecker()
        result = await checker.check({"grants": {Permission.READ}}, Permission.READ)
        ```
    """

    async def check(self, context: PermissionCheckContext, permission: Permission) -> bool:
        """Return ``True`` if *permission* is granted in *context*."""
        ...

check(context: PermissionCheckContext, permission: Permission) -> bool async

Return True if permission is granted in context.

Source code in src/forging_blocks/domain/permissions/permission_checker.py
async def check(self, context: PermissionCheckContext, permission: Permission) -> bool:
    """Return ``True`` if *permission* is granted in *context*."""
    ...