Implemented datasette.permission_allowed(), refs #699

This commit is contained in:
Simon Willison 2020-05-30 15:24:43 -07:00
commit 9315bacf6f
5 changed files with 75 additions and 4 deletions

View file

@ -134,3 +134,11 @@ def actor_from_request(datasette, request):
return {"id": "bot"}
else:
return None
@hookimpl
def permission_allowed(actor, action):
if action == "this_is_allowed":
return True
elif action == "this_is_denied":
return False

View file

@ -107,3 +107,16 @@ def actor_from_request(datasette, request):
return None
return inner
@hookimpl
def permission_allowed(datasette, actor, action):
# Testing asyncio version of permission_allowed
async def inner():
assert 2 == (await datasette.get_database().execute("select 1 + 1")).first()[0]
if action == "this_is_allowed_async":
return True
elif action == "this_is_denied_async":
return False
return inner