mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-12 10:38:16 -06:00
16138 add migration of group perms
This commit is contained in:
parent
bdc5a1c472
commit
5b6ae28422
32
netbox/users/migrations/0009_update_group_perms.py
Normal file
32
netbox/users/migrations/0009_update_group_perms.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# Generated by Django 5.0.5 on 2024-05-15 18:05
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def update_content_types(apps, schema_editor):
|
||||||
|
ObjectType = apps.get_model('core', 'ObjectType')
|
||||||
|
ObjectPermission = apps.get_model('users', 'ObjectPermission')
|
||||||
|
|
||||||
|
auth_group_ct = ObjectType.objects.filter(app_label='auth', model='group').first()
|
||||||
|
users_group_ct = ObjectType.objects.filter(app_label='users', model='group').first()
|
||||||
|
if auth_group_ct and users_group_ct:
|
||||||
|
perms = ObjectPermission.objects.filter(object_types__in=[auth_group_ct])
|
||||||
|
for perm in perms:
|
||||||
|
perm.object_types.remove(auth_group_ct)
|
||||||
|
perm.object_types.add(users_group_ct)
|
||||||
|
perm.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('users', '0008_flip_objectpermission_assignments'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
# Update ContentTypes
|
||||||
|
migrations.RunPython(
|
||||||
|
code=update_content_types,
|
||||||
|
reverse_code=migrations.RunPython.noop
|
||||||
|
),
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user