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

Make cascading permission checks available to plugins #1092

Closed
simonw opened this issue Nov 13, 2020 · 1 comment
Closed

Make cascading permission checks available to plugins #1092

simonw opened this issue Nov 13, 2020 · 1 comment

Comments

@simonw
Copy link
Owner

simonw commented Nov 13, 2020

The BaseView class has a method for cascading permission checks, but it's not easily accessible to plugins.

async def check_permissions(self, request, permissions):
"permissions is a list of (action, resource) tuples or 'action' strings"
for permission in permissions:
if isinstance(permission, str):
action = permission
resource = None
elif isinstance(permission, (tuple, list)) and len(permission) == 2:
action, resource = permission
else:
assert (
False
), "permission should be string or tuple of two items: {}".format(
repr(permission)
)
ok = await self.ds.permission_allowed(
request.actor,
action,
resource=resource,
default=None,
)
if ok is not None:
if ok:
return
else:
raise Forbidden(action)

This leaves plugins like datasette-graphql having to implement their own versions of this logic, which is bad: simonw/datasette-graphql#65

First check view-database - if that says False then disallow access, if it says True then allow access. If it says None check view-instance.

This should become a supported API that plugins are encouraged to use.

@simonw
Copy link
Owner Author

simonw commented Aug 30, 2023

@simonw simonw closed this as completed Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant