Skip to content

Commit 6b3f34f

Browse files
Merge pull request #2563 from IFRCGo/feature/admin-page-to-query-users
Expose Permissions query entry under Authentication and Authorization
2 parents f398583 + 1a34a70 commit 6b3f34f

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

api/admin.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from django.conf import settings
55
from django.contrib import admin, messages
66
from django.contrib.auth.admin import UserAdmin
7-
from django.contrib.auth.models import User
7+
from django.contrib.auth.models import Permission, User
88
from django.contrib.gis import admin as geoadmin
99
from django.core.exceptions import ValidationError
1010
from django.http import HttpResponse, HttpResponseRedirect
@@ -1052,6 +1052,40 @@ class ExportTokenAdmin(admin.ModelAdmin):
10521052
pass
10531053

10541054

1055+
try:
1056+
admin.site.unregister(Permission)
1057+
except admin.sites.NotRegistered:
1058+
pass
1059+
1060+
1061+
@admin.register(Permission)
1062+
class PermissionReportAdmin(admin.ModelAdmin):
1063+
# Show the menu entry, but route to the Users-per-permission report.
1064+
def has_module_permission(self, request):
1065+
from api.admin_reports import _user_has_access
1066+
1067+
return _user_has_access(request.user)
1068+
1069+
def has_view_permission(self, request, obj=None):
1070+
from api.admin_reports import _user_has_access
1071+
1072+
return _user_has_access(request.user)
1073+
1074+
def has_add_permission(self, request):
1075+
return False
1076+
1077+
def has_change_permission(self, request, obj=None):
1078+
return False
1079+
1080+
def has_delete_permission(self, request, obj=None):
1081+
return False
1082+
1083+
def changelist_view(self, request, extra_context=None):
1084+
from api.admin_reports import users_per_permission_view
1085+
1086+
return users_per_permission_view(request)
1087+
1088+
10551089
admin.site.register(models.DisasterType, DisasterTypeAdmin)
10561090
admin.site.register(models.Event, EventAdmin)
10571091
admin.site.register(models.GDACSEvent, GdacsAdmin)

api/templates/admin/users_per_permission.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<th>{% trans "Username" %}</th>
4646
<th>{% trans "Email address" %}</th>
4747
<th>{% trans "Name" %}</th>
48+
<th>{% trans "Ctry" %}</th>
4849
<th>{% trans "Organization" %}</th>
4950
<th>{% trans "Active" %}</th>
5051
<th>{% trans "Staff" %}</th>
@@ -58,6 +59,7 @@
5859
<td>{{ u.username }}</td>
5960
<td>{{ u.email }}</td>
6061
<td>{{ u.get_full_name }}</td>
62+
<td>{{ u.profile.country.iso3|default_if_none:"" }}</td>
6163
<td>{{ u.profile.org|default_if_none:"" }}</td>
6264
<!-- yesno:"+,," -> '+' for True, '' for False/None -->
6365
<td class="bool-col">{{ u.is_active|yesno:"+,," }}</td>

0 commit comments

Comments
 (0)