mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Implemented datasette.permission_allowed(), refs #699
This commit is contained in:
parent
461c82838d
commit
9315bacf6f
5 changed files with 75 additions and 4 deletions
|
|
@ -406,6 +406,25 @@ class Datasette:
|
|||
# pylint: disable=no-member
|
||||
pm.hook.prepare_connection(conn=conn, database=database, datasette=self)
|
||||
|
||||
async def permission_allowed(
|
||||
self, actor, action, resource_type=None, resource_identifier=None, default=False
|
||||
):
|
||||
"Check permissions using the permissions_allowed plugin hook"
|
||||
for check in pm.hook.permission_allowed(
|
||||
datasette=self,
|
||||
actor=actor,
|
||||
action=action,
|
||||
resource_type=resource_type,
|
||||
resource_identifier=resource_identifier,
|
||||
):
|
||||
if callable(check):
|
||||
check = check()
|
||||
if asyncio.iscoroutine(check):
|
||||
check = await check
|
||||
if check is not None:
|
||||
return check
|
||||
return default
|
||||
|
||||
async def execute(
|
||||
self,
|
||||
db_name,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue