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

Remove check_permission() from BaseView #1677

Closed
simonw opened this issue Mar 21, 2022 · 1 comment
Closed

Remove check_permission() from BaseView #1677

simonw opened this issue Mar 21, 2022 · 1 comment

Comments

@simonw
Copy link
Owner

simonw commented Mar 21, 2022

Follow-on from:

Refs:

@simonw simonw added this to the Datasette 1.0 milestone Mar 21, 2022
@simonw
Copy link
Owner Author

simonw commented Mar 21, 2022

async def check_permission(self, request, action, resource=None):
ok = await self.ds.permission_allowed(
request.actor,
action,
resource=resource,
default=True,
)
if not ok:
raise Forbidden(action)

This is weirdly different from how check_permissions() used to work, in that it doesn't differentiate between None and False.

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)

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

No branches or pull requests

1 participant