Skip to content

Commit

Permalink
Better flash message when updating ACLs, refs #7
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Aug 31, 2024
1 parent 1da7447 commit a20c0b9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
16 changes: 15 additions & 1 deletion datasette_acl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,9 @@ async def table_acls(request, datasette):
"operation_by": request.actor["id"],
},
)
datasette.add_message(request, f"Made changes: {repr(changes_made)}")
if changes_made:
message = generate_changes_message(changes_made)
datasette.add_message(request, message)
return Response.redirect(request.path)

return Response.html(
Expand All @@ -408,6 +410,18 @@ async def table_acls(request, datasette):
)


def generate_changes_message(changes_made):
messages = []
for action, changes in changes_made.items():
for group, permission in changes:
messages.append(f"{action} group '{group}' can {permission}")
if not messages:
return None
message = ", ".join(messages)
# Capitalize first letter
return message[0].upper() + message[1:]


@hookimpl
def register_permissions(datasette):
return [
Expand Down
8 changes: 8 additions & 0 deletions tests/test_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,11 @@ async def test_permission_allowed():
"operation": "added",
},
]
# Let's check the message it set
messages = datasette.unsign(response2.cookies["ds_messages"], "messages")
assert messages == [
[
"Added group 'admin' can alter-table, removed group 'admin' can insert-row",
1,
]
]

0 comments on commit a20c0b9

Please sign in to comment.