mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fix up ObjectPermission content type assignment
This commit is contained in:
@@ -3,8 +3,14 @@ from django.contrib import admin
|
|||||||
from django.contrib.auth.admin import UserAdmin as UserAdmin_
|
from django.contrib.auth.admin import UserAdmin as UserAdmin_
|
||||||
from django.contrib.auth.models import Group, User
|
from django.contrib.auth.models import Group, User
|
||||||
|
|
||||||
|
from extras.admin import order_content_types
|
||||||
from .models import ObjectPermission, Token, UserConfig
|
from .models import ObjectPermission, Token, UserConfig
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Users & groups
|
||||||
|
#
|
||||||
|
|
||||||
# Unregister the built-in GroupAdmin and UserAdmin classes so that we can use our custom admin classes below
|
# Unregister the built-in GroupAdmin and UserAdmin classes so that we can use our custom admin classes below
|
||||||
admin.site.unregister(Group)
|
admin.site.unregister(Group)
|
||||||
admin.site.unregister(User)
|
admin.site.unregister(User)
|
||||||
@@ -44,6 +50,10 @@ class UserAdmin(UserAdmin_):
|
|||||||
inlines = (UserConfigInline,)
|
inlines = (UserConfigInline,)
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# REST API tokens
|
||||||
|
#
|
||||||
|
|
||||||
class TokenAdminForm(forms.ModelForm):
|
class TokenAdminForm(forms.ModelForm):
|
||||||
key = forms.CharField(
|
key = forms.CharField(
|
||||||
required=False,
|
required=False,
|
||||||
@@ -65,8 +75,27 @@ class TokenAdmin(admin.ModelAdmin):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Permissions
|
||||||
|
#
|
||||||
|
|
||||||
|
class ObjectPermissionForm(forms.ModelForm):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ObjectPermission
|
||||||
|
exclude = []
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
# Format ContentType choices
|
||||||
|
order_content_types(self.fields['model'])
|
||||||
|
self.fields['model'].choices.insert(0, ('', '---------'))
|
||||||
|
|
||||||
|
|
||||||
@admin.register(ObjectPermission)
|
@admin.register(ObjectPermission)
|
||||||
class ObjectPermissionAdmin(admin.ModelAdmin):
|
class ObjectPermissionAdmin(admin.ModelAdmin):
|
||||||
|
form = ObjectPermissionForm
|
||||||
list_display = [
|
list_display = [
|
||||||
'model', 'can_view', 'can_add', 'can_change', 'can_delete'
|
'model', 'can_view', 'can_add', 'can_change', 'can_delete'
|
||||||
]
|
]
|
||||||
|
@@ -26,7 +26,7 @@ class Migration(migrations.Migration):
|
|||||||
('can_change', models.BooleanField(default=False)),
|
('can_change', models.BooleanField(default=False)),
|
||||||
('can_delete', models.BooleanField(default=False)),
|
('can_delete', models.BooleanField(default=False)),
|
||||||
('groups', models.ManyToManyField(blank=True, related_name='object_permissions', to='auth.Group')),
|
('groups', models.ManyToManyField(blank=True, related_name='object_permissions', to='auth.Group')),
|
||||||
('model', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
|
('model', models.ForeignKey(limit_choices_to={'app_label__in': ['circuits', 'dcim', 'extras', 'ipam', 'secrets', 'tenancy', 'virtualization']}, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
|
||||||
('users', models.ManyToManyField(blank=True, related_name='object_permissions', to=settings.AUTH_USER_MODEL)),
|
('users', models.ManyToManyField(blank=True, related_name='object_permissions', to=settings.AUTH_USER_MODEL)),
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
|
@@ -214,6 +214,11 @@ class ObjectPermission(models.Model):
|
|||||||
)
|
)
|
||||||
model = models.ForeignKey(
|
model = models.ForeignKey(
|
||||||
to=ContentType,
|
to=ContentType,
|
||||||
|
limit_choices_to={
|
||||||
|
'app_label__in': [
|
||||||
|
'circuits', 'dcim', 'extras', 'ipam', 'secrets', 'tenancy', 'virtualization',
|
||||||
|
],
|
||||||
|
},
|
||||||
on_delete=models.CASCADE
|
on_delete=models.CASCADE
|
||||||
)
|
)
|
||||||
attrs = JSONField(
|
attrs = JSONField(
|
||||||
|
Reference in New Issue
Block a user