From e64289e791329bb2157e607b0e646b95cd483cbc Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 1 Aug 2023 14:35:28 -0400 Subject: [PATCH] #12589: Remove obsolete admin resources --- netbox/users/{admin/__init__.py => admin.py} | 6 +-- netbox/users/admin/filters.py | 42 ----------------- netbox/users/admin/inlines.py | 49 -------------------- 3 files changed, 1 insertion(+), 96 deletions(-) rename netbox/users/{admin/__init__.py => admin.py} (52%) delete mode 100644 netbox/users/admin/filters.py delete mode 100644 netbox/users/admin/inlines.py diff --git a/netbox/users/admin/__init__.py b/netbox/users/admin.py similarity index 52% rename from netbox/users/admin/__init__.py rename to netbox/users/admin.py index bc7bf7ab21a..a82ec49979c 100644 --- a/netbox/users/admin/__init__.py +++ b/netbox/users/admin.py @@ -1,10 +1,6 @@ from django.contrib import admin from django.contrib.auth.models import Group, User -# -# Users & groups -# - -# Unregister the built-in GroupAdmin and UserAdmin classes so that we can use our custom admin classes below +# Unregister Django's built-in Group and User admin views admin.site.unregister(Group) admin.site.unregister(User) diff --git a/netbox/users/admin/filters.py b/netbox/users/admin/filters.py deleted file mode 100644 index b71761fa276..00000000000 --- a/netbox/users/admin/filters.py +++ /dev/null @@ -1,42 +0,0 @@ -from django.contrib import admin -from django.contrib.contenttypes.models import ContentType - -from users.models import ObjectPermission - -__all__ = ( - 'ActionListFilter', - 'ObjectTypeListFilter', -) - - -class ActionListFilter(admin.SimpleListFilter): - title = 'action' - parameter_name = 'action' - - def lookups(self, request, model_admin): - options = set() - for action_list in ObjectPermission.objects.values_list('actions', flat=True).distinct(): - options.update(action_list) - return [ - (action, action) for action in sorted(options) - ] - - def queryset(self, request, queryset): - if self.value(): - return queryset.filter(actions=[self.value()]) - - -class ObjectTypeListFilter(admin.SimpleListFilter): - title = 'object type' - parameter_name = 'object_type' - - def lookups(self, request, model_admin): - object_types = ObjectPermission.objects.values_list('object_types__pk', flat=True).distinct() - content_types = ContentType.objects.filter(pk__in=object_types).order_by('app_label', 'model') - return [ - (ct.pk, ct) for ct in content_types - ] - - def queryset(self, request, queryset): - if self.value(): - return queryset.filter(object_types=self.value()) diff --git a/netbox/users/admin/inlines.py b/netbox/users/admin/inlines.py deleted file mode 100644 index cd192ecf85c..00000000000 --- a/netbox/users/admin/inlines.py +++ /dev/null @@ -1,49 +0,0 @@ -from django.contrib import admin -from django.contrib.auth.models import Group, User - -from users.models import UserConfig - -__all__ = ( - 'GroupObjectPermissionInline', - 'UserConfigInline', - 'UserObjectPermissionInline', -) - - -class ObjectPermissionInline(admin.TabularInline): - exclude = None - extra = 3 - readonly_fields = ['object_types', 'actions', 'constraints'] - verbose_name = 'Permission' - verbose_name_plural = 'Permissions' - - def get_queryset(self, request): - return super().get_queryset(request).prefetch_related('objectpermission__object_types') - - @staticmethod - def object_types(instance): - # Don't call .values_list() here because we want to reference the pre-fetched object_types - return ', '.join([ot.name for ot in instance.objectpermission.object_types.all()]) - - @staticmethod - def actions(instance): - return ', '.join(instance.objectpermission.actions) - - @staticmethod - def constraints(instance): - return instance.objectpermission.constraints - - -class GroupObjectPermissionInline(ObjectPermissionInline): - model = Group.object_permissions.through - - -class UserObjectPermissionInline(ObjectPermissionInline): - model = User.object_permissions.through - - -class UserConfigInline(admin.TabularInline): - model = UserConfig - readonly_fields = ('data',) - can_delete = False - verbose_name = 'Preferences'