mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
#12589: Remove obsolete admin resources
This commit is contained in:
@ -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)
|
@ -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())
|
@ -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'
|
Reference in New Issue
Block a user