mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
/-/permissions?filter=exclude-yours/only-yours - closes #2460
This commit is contained in:
parent
4dff846271
commit
f57977a08f
3 changed files with 71 additions and 10 deletions
|
|
@ -112,6 +112,12 @@ debugPost.addEventListener('submit', function(ev) {
|
|||
|
||||
<h1>Recent permissions checks</h1>
|
||||
|
||||
<p>
|
||||
{% if filter != "all" %}<a href="?filter=all">All</a>{% else %}<strong>All</strong>{% endif %},
|
||||
{% if filter != "exclude-yours" %}<a href="?filter=exclude-yours">Exclude yours</a>{% else %}<strong>Exclude yours</strong>{% endif %},
|
||||
{% if filter != "only-yours" %}<a href="?filter=only-yours">Only yours</a>{% else %}<strong>Only yours</strong>{% endif %}
|
||||
</p>
|
||||
|
||||
{% for check in permission_checks %}
|
||||
<div class="check">
|
||||
<h2>
|
||||
|
|
|
|||
|
|
@ -121,12 +121,27 @@ class PermissionsDebugView(BaseView):
|
|||
await self.ds.ensure_permissions(request.actor, ["view-instance"])
|
||||
if not await self.ds.permission_allowed(request.actor, "permissions-debug"):
|
||||
raise Forbidden("Permission denied")
|
||||
filter_ = request.args.get("filter") or "all"
|
||||
permission_checks = list(reversed(self.ds._permission_checks))
|
||||
if filter_ == "exclude-yours":
|
||||
permission_checks = [
|
||||
check
|
||||
for check in permission_checks
|
||||
if (check["actor"] or {}).get("id") != request.actor["id"]
|
||||
]
|
||||
elif filter_ == "only-yours":
|
||||
permission_checks = [
|
||||
check
|
||||
for check in permission_checks
|
||||
if (check["actor"] or {}).get("id") == request.actor["id"]
|
||||
]
|
||||
return await self.render(
|
||||
["permissions_debug.html"],
|
||||
request,
|
||||
# list() avoids error if check is performed during template render:
|
||||
{
|
||||
"permission_checks": list(reversed(self.ds._permission_checks)),
|
||||
"permission_checks": permission_checks,
|
||||
"filter": filter_,
|
||||
"permissions": [
|
||||
{
|
||||
"name": p.name,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue