You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Extend async def check_permission(request, permission, context=None) -> bool to return back additional information.
Method check_permission() calls method async def permits(...) -> bool declared in AuthPolicy and defined in user-defined policies that inherit AuthPolicy. We need to have a general and unified way to return back information from permits() (and thus check_permission()).
Use case: check_permission is called on a bunch of permissions and the calling code wants to know which exactly permission check was failed.
Possible solutions:
More narrow approach. In order to preserve backward compatibility, we could add method check_permissions() -> PermissionCheckResult (in addition to permits() -> bool) that returns a general dataclass (or json object) that will consolidate information on the permission check, for example:
T = TypeVar('T')
@dataclass
class PermissionCheckResult:
success: bool
missing: Set[T]
async def check_permissions(...) -> PermissionCheckResult:
...
More general and more pythonic approach. Keep permits() -> bool, but allow it to raise a pre-defined exception for providing additional information:
class PermissionDeniedException(Exception):
def __init__(self, missing_permissions):
pass
The text was updated successfully, but these errors were encountered:
Extend
async def check_permission(request, permission, context=None) -> bool
to return back additional information.Method
check_permission()
calls methodasync def permits(...) -> bool
declared inAuthPolicy
and defined in user-defined policies that inheritAuthPolicy
. We need to have a general and unified way to return back information frompermits()
(and thuscheck_permission()
).Use case:
check_permission
is called on a bunch of permissions and the calling code wants to know which exactly permission check was failed.Possible solutions:
check_permissions() -> PermissionCheckResult
(in addition topermits() -> bool
) that returns a general dataclass (or json object) that will consolidate information on the permission check, for example:permits() -> bool
, but allow it to raise a pre-defined exception for providing additional information:The text was updated successfully, but these errors were encountered: