mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #8194: Enable bulk user assignment to groups under admin UI
This commit is contained in:
@ -5,6 +5,7 @@
|
|||||||
### Enhancements
|
### Enhancements
|
||||||
|
|
||||||
* [#8192](https://github.com/netbox-community/netbox/issues/8192) - Add "add prefix" button to aggregate child prefixes view
|
* [#8192](https://github.com/netbox-community/netbox/issues/8192) - Add "add prefix" button to aggregate child prefixes view
|
||||||
|
* [#8194](https://github.com/netbox-community/netbox/issues/8194) - Enable bulk user assignment to groups under admin UI
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ admin.site.unregister(User)
|
|||||||
|
|
||||||
@admin.register(Group)
|
@admin.register(Group)
|
||||||
class GroupAdmin(admin.ModelAdmin):
|
class GroupAdmin(admin.ModelAdmin):
|
||||||
fields = ('name',)
|
form = forms.GroupAdminForm
|
||||||
list_display = ('name', 'user_count')
|
list_display = ('name', 'user_count')
|
||||||
ordering = ('name',)
|
ordering = ('name',)
|
||||||
search_fields = ('name',)
|
search_fields = ('name',)
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
|
from django.contrib.auth.models import Group, User
|
||||||
|
from django.contrib.admin.widgets import FilteredSelectMultiple
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.core.exceptions import FieldError, ValidationError
|
from django.core.exceptions import FieldError, ValidationError
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
@ -8,11 +10,39 @@ from users.models import ObjectPermission, Token
|
|||||||
from utilities.forms.fields import ContentTypeMultipleChoiceField
|
from utilities.forms.fields import ContentTypeMultipleChoiceField
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
|
'GroupAdminForm',
|
||||||
'ObjectPermissionForm',
|
'ObjectPermissionForm',
|
||||||
'TokenAdminForm',
|
'TokenAdminForm',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class GroupAdminForm(forms.ModelForm):
|
||||||
|
users = forms.ModelMultipleChoiceField(
|
||||||
|
queryset=User.objects.all(),
|
||||||
|
required=False,
|
||||||
|
widget=FilteredSelectMultiple('users', False)
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Group
|
||||||
|
fields = ('name', 'users')
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(GroupAdminForm, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
if self.instance.pk:
|
||||||
|
self.fields['users'].initial = self.instance.user_set.all()
|
||||||
|
|
||||||
|
def save_m2m(self):
|
||||||
|
self.instance.user_set.set(self.cleaned_data['users'])
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
instance = super(GroupAdminForm, self).save()
|
||||||
|
self.save_m2m()
|
||||||
|
|
||||||
|
return instance
|
||||||
|
|
||||||
|
|
||||||
class TokenAdminForm(forms.ModelForm):
|
class TokenAdminForm(forms.ModelForm):
|
||||||
key = forms.CharField(
|
key = forms.CharField(
|
||||||
required=False,
|
required=False,
|
||||||
|
Reference in New Issue
Block a user