mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Nested permission checks for all views, refs #811
This commit is contained in:
parent
86dec9e8ff
commit
4340845754
6 changed files with 97 additions and 48 deletions
|
|
@ -842,17 +842,25 @@ if __name__ == "__main__":
|
|||
)
|
||||
|
||||
|
||||
def assert_permission_checked(
|
||||
datasette, action, resource_type=None, resource_identifier=None
|
||||
):
|
||||
assert [
|
||||
pc
|
||||
for pc in datasette._permission_checks
|
||||
if pc["action"] == action
|
||||
and pc["resource_type"] == resource_type
|
||||
and pc["resource_identifier"] == resource_identifier
|
||||
], """Missing expected permission check: action={}, resource_type={}, resource_identifier={}
|
||||
Permission checks seen: {}
|
||||
""".format(
|
||||
action, resource_type, resource_identifier, datasette._permission_checks
|
||||
)
|
||||
def assert_permissions_checked(datasette, actions):
|
||||
# actions is a list of "action" or (action, resource_type, resource_identifier) tuples
|
||||
for action in actions:
|
||||
if isinstance(action, str):
|
||||
resource_type = None
|
||||
resource_identifier = None
|
||||
else:
|
||||
action, resource_type, resource_identifier = action
|
||||
assert [
|
||||
pc
|
||||
for pc in datasette._permission_checks
|
||||
if pc["action"] == action
|
||||
and pc["resource_type"] == resource_type
|
||||
and pc["resource_identifier"] == resource_identifier
|
||||
], """Missing expected permission check: action={}, resource_type={}, resource_identifier={}
|
||||
Permission checks seen: {}
|
||||
""".format(
|
||||
action,
|
||||
resource_type,
|
||||
resource_identifier,
|
||||
json.dumps(list(datasette._permission_checks), indent=4),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue