mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-25 08:46:10 -06:00
Clean up permissions bulk edit
This commit is contained in:
parent
f49b43d5b5
commit
4702cc049f
@ -13,7 +13,6 @@ __all__ = (
|
||||
|
||||
class UserBulkEditForm(BootstrapMixin, forms.Form):
|
||||
pk = forms.ModelMultipleChoiceField(
|
||||
label=_('Pk'),
|
||||
queryset=NetBoxUser.objects.all(),
|
||||
widget=forms.MultipleHiddenInput
|
||||
)
|
||||
@ -52,8 +51,7 @@ class UserBulkEditForm(BootstrapMixin, forms.Form):
|
||||
|
||||
class ObjectPermissionBulkEditForm(BootstrapMixin, forms.Form):
|
||||
pk = forms.ModelMultipleChoiceField(
|
||||
label=_('Pk'),
|
||||
queryset=None, # Set from self.model on init
|
||||
queryset=ObjectPermission.objects.all(),
|
||||
widget=forms.MultipleHiddenInput
|
||||
)
|
||||
description = forms.CharField(
|
||||
@ -61,17 +59,14 @@ class ObjectPermissionBulkEditForm(BootstrapMixin, forms.Form):
|
||||
max_length=200,
|
||||
required=False
|
||||
)
|
||||
enabled = forms.BooleanField(
|
||||
label=_('Enabled'),
|
||||
enabled = forms.NullBooleanField(
|
||||
required=False,
|
||||
widget=BulkEditNullBooleanSelect,
|
||||
label=_('Enabled')
|
||||
)
|
||||
|
||||
model = ObjectPermission
|
||||
fieldsets = (
|
||||
(None, ('description', 'enabled')),
|
||||
(None, ('enabled', 'description')),
|
||||
)
|
||||
nullable_fields = ()
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['pk'].queryset = self.model.objects.all()
|
||||
nullable_fields = ('description',)
|
||||
|
@ -368,6 +368,22 @@ class ObjectPermission(models.Model):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
@property
|
||||
def can_view(self):
|
||||
return 'view' in self.actions
|
||||
|
||||
@property
|
||||
def can_add(self):
|
||||
return 'add' in self.actions
|
||||
|
||||
@property
|
||||
def can_change(self):
|
||||
return 'change' in self.actions
|
||||
|
||||
@property
|
||||
def can_delete(self):
|
||||
return 'delete' in self.actions
|
||||
|
||||
def list_constraints(self):
|
||||
"""
|
||||
Return all constraint sets as a list (even if only a single set is defined).
|
||||
|
@ -1,8 +1,8 @@
|
||||
import django_tables2 as tables
|
||||
from django_tables2.utils import A
|
||||
from .models import Token
|
||||
|
||||
from netbox.tables import NetBoxTable, columns
|
||||
from users.models import NetBoxGroup, NetBoxUser, ObjectPermission
|
||||
from .models import Token
|
||||
|
||||
__all__ = (
|
||||
'GroupTable',
|
||||
@ -89,6 +89,17 @@ class GroupTable(NetBoxTable):
|
||||
|
||||
class ObjectPermissionTable(NetBoxTable):
|
||||
name = tables.Column(linkify=True)
|
||||
object_types = columns.ContentTypesColumn()
|
||||
enabled = columns.BooleanColumn()
|
||||
can_view = columns.BooleanColumn()
|
||||
can_add = columns.BooleanColumn()
|
||||
can_change = columns.BooleanColumn()
|
||||
can_delete = columns.BooleanColumn()
|
||||
custom_actions = columns.ArrayColumn(
|
||||
accessor=tables.A('actions')
|
||||
)
|
||||
users = tables.ManyToManyColumn()
|
||||
groups = tables.ManyToManyColumn()
|
||||
actions = columns.ActionsColumn(
|
||||
actions=('edit', 'delete'),
|
||||
)
|
||||
@ -96,6 +107,9 @@ class ObjectPermissionTable(NetBoxTable):
|
||||
class Meta(NetBoxTable.Meta):
|
||||
model = ObjectPermission
|
||||
fields = (
|
||||
'pk', 'id', 'name', 'enabled', 'actions', 'constraints',
|
||||
'pk', 'id', 'name', 'enabled', 'object_types', 'can_view', 'can_add', 'can_change', 'can_delete',
|
||||
'custom_actions', 'users', 'groups', 'constraints', 'description',
|
||||
)
|
||||
default_columns = (
|
||||
'pk', 'name', 'enabled', 'object_types', 'can_view', 'can_add', 'can_change', 'can_delete', 'description',
|
||||
)
|
||||
default_columns = ('pk', 'name', 'enabled', 'actions', 'constraints',)
|
||||
|
Loading…
Reference in New Issue
Block a user