New check_visibility() utility function, refs #811

This commit is contained in:
Simon Willison 2020-06-08 06:49:55 -07:00
commit e18f8c3f87
3 changed files with 43 additions and 34 deletions

View file

@ -874,3 +874,26 @@ def actor_matches_allow(actor, allow):
if actor_values.intersection(values):
return True
return False
async def check_visibility(
datasette, actor, action, resource_type, resource_identifier, default=True
):
"Returns (visible, private) - visible = can you see it, private = can others see it too"
visible = await datasette.permission_allowed(
actor,
action,
resource_type=resource_type,
resource_identifier=resource_identifier,
default=default,
)
if not visible:
return (False, False)
private = not await datasette.permission_allowed(
None,
action,
resource_type=resource_type,
resource_identifier=resource_identifier,
default=default,
)
return visible, private