mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
New check_visibility() utility function, refs #811
This commit is contained in:
parent
9397d71834
commit
e18f8c3f87
3 changed files with 43 additions and 34 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue