mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 04:22:01 -06:00
Closes #4942: Make ObjectPermission's 'name' field required
This commit is contained in:
parent
ccb2bf4344
commit
ce2dada9fd
@ -1,6 +1,6 @@
|
||||
# NetBox v2.9
|
||||
|
||||
## v2.9.0 (FUTURE)
|
||||
## v2.9-beta2 (FUTURE)
|
||||
|
||||
### Enhancements
|
||||
|
||||
@ -18,6 +18,11 @@
|
||||
* [#4938](https://github.com/netbox-community/netbox/issues/4938) - Show add, import buttons on virtual chassis list view
|
||||
* [#4939](https://github.com/netbox-community/netbox/issues/4939) - Fix linking to LAG interfaces on other VC members
|
||||
|
||||
### Other Changes
|
||||
|
||||
* [#4940](https://github.com/netbox-community/netbox/issues/4940) - Add an `occupied` field to rack unit representations for rack elevation views
|
||||
* [#4942](https://github.com/netbox-community/netbox/issues/4942) - Make ObjectPermission's `name` field required
|
||||
|
||||
---
|
||||
|
||||
## v2.9-beta1 (2020-07-23)
|
||||
|
@ -251,7 +251,7 @@ class ObjectPermissionAdmin(admin.ModelAdmin):
|
||||
filter_horizontal = ('object_types', 'groups', 'users')
|
||||
form = ObjectPermissionForm
|
||||
list_display = [
|
||||
'get_name', 'enabled', 'list_models', 'list_users', 'list_groups', 'actions', 'constraints',
|
||||
'name', 'enabled', 'list_models', 'list_users', 'list_groups', 'actions', 'constraints',
|
||||
]
|
||||
list_filter = [
|
||||
'enabled', ActionListFilter, ObjectTypeListFilter, 'groups', 'users'
|
||||
@ -260,13 +260,6 @@ class ObjectPermissionAdmin(admin.ModelAdmin):
|
||||
def get_queryset(self, request):
|
||||
return super().get_queryset(request).prefetch_related('object_types', 'users', 'groups')
|
||||
|
||||
def get_name(self, obj):
|
||||
return '{}: {}'.format(
|
||||
', '.join([ot.name for ot in obj.object_types.all()]),
|
||||
', '.join(obj.actions)
|
||||
)
|
||||
get_name.short_description = 'Name'
|
||||
|
||||
def list_models(self, obj):
|
||||
return ', '.join([f"{ct}" for ct in obj.object_types.all()])
|
||||
list_models.short_description = 'Models'
|
||||
|
@ -18,7 +18,7 @@ class Migration(migrations.Migration):
|
||||
name='ObjectPermission',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False)),
|
||||
('name', models.CharField(blank=True, max_length=100)),
|
||||
('name', models.CharField(max_length=100)),
|
||||
('enabled', models.BooleanField(default=True)),
|
||||
('constraints', django.contrib.postgres.fields.jsonb.JSONField(blank=True, null=True)),
|
||||
('actions', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=30), size=None)),
|
||||
@ -27,6 +27,7 @@ class Migration(migrations.Migration):
|
||||
('users', models.ManyToManyField(blank=True, related_name='object_permissions', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'ordering': ['name'],
|
||||
'verbose_name': 'permission',
|
||||
},
|
||||
),
|
||||
|
@ -13,7 +13,7 @@ def replicate_permissions(apps, schema_editor):
|
||||
|
||||
# TODO: Optimize this iteration so that ObjectPermissions with identical sets of users and groups
|
||||
# are combined into a single ObjectPermission instance.
|
||||
for perm in Permission.objects.all():
|
||||
for perm in Permission.objects.select_related('content_type'):
|
||||
if perm.codename.split('_')[0] in ACTIONS:
|
||||
action = perm.codename.split('_')[0]
|
||||
elif perm.codename == 'activate_userkey':
|
||||
@ -24,7 +24,11 @@ def replicate_permissions(apps, schema_editor):
|
||||
action = perm.codename
|
||||
|
||||
if perm.group_set.exists() or perm.user_set.exists():
|
||||
obj_perm = ObjectPermission(actions=[action])
|
||||
obj_perm = ObjectPermission(
|
||||
# Copy name from original Permission object
|
||||
name=f'{perm.content_type.app_label}.{perm.codename}'[:100],
|
||||
actions=[action]
|
||||
)
|
||||
obj_perm.save()
|
||||
obj_perm.object_types.add(perm.content_type)
|
||||
if perm.group_set.exists():
|
||||
|
@ -239,8 +239,7 @@ class ObjectPermission(models.Model):
|
||||
identified by ORM query parameters.
|
||||
"""
|
||||
name = models.CharField(
|
||||
max_length=100,
|
||||
blank=True
|
||||
max_length=100
|
||||
)
|
||||
enabled = models.BooleanField(
|
||||
default=True
|
||||
@ -277,7 +276,8 @@ class ObjectPermission(models.Model):
|
||||
objects = RestrictedQuerySet.as_manager()
|
||||
|
||||
class Meta:
|
||||
ordering = ['name']
|
||||
verbose_name = "permission"
|
||||
|
||||
def __str__(self):
|
||||
return self.name or f'Permission #{self.pk}'
|
||||
return self.name
|
||||
|
Loading…
Reference in New Issue
Block a user