Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend permission-checking methods to return additional information #241

Open
atemate opened this issue Aug 14, 2019 · 2 comments
Open

Extend permission-checking methods to return additional information #241

atemate opened this issue Aug 14, 2019 · 2 comments

Comments

@atemate
Copy link

atemate commented Aug 14, 2019

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:

  1. 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:
    ...
  1. 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
@bitnom
Copy link

bitnom commented Mar 8, 2020

You mean to check multiple permissions?

@atemate
Copy link
Author

atemate commented Mar 10, 2020

Yes. To check multiple permissions and get the set of missing permissions in the answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants