Opravení práv
TODO: je na těch ContentTypech navěšené ještě něco dalšího? Pro nastavení asi ne, ale co ostatní aplikace?
This commit is contained in:
parent
ca0bbb1247
commit
37586d7433
1 changed files with 41 additions and 0 deletions
41
various/migrations/0003_fix_permissions.py
Normal file
41
various/migrations/0003_fix_permissions.py
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
# Generated by Django 3.2.23 on 2023-12-11 19:40
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
def oprav_prava_k_nastaveni(apps, schema_editor):
|
||||||
|
# Tohle je trošku hnus, nešlo by to snáz?
|
||||||
|
ContentType = apps.get_model('contenttypes', 'ContentType')
|
||||||
|
Permission = apps.get_model('auth', 'Permission')
|
||||||
|
Group = apps.get_model('auth', 'Group')
|
||||||
|
old_ct = ContentType.objects.get_by_natural_key('seminar', 'nastaveni')
|
||||||
|
new_ct = ContentType.objects.get_by_natural_key('various', 'nastaveni')
|
||||||
|
old_perms = Permission.objects.filter(content_type=old_ct)
|
||||||
|
new_perms = Permission.objects.filter(content_type=new_ct)
|
||||||
|
for g in Group.objects.filter(permissions__in=old_perms):
|
||||||
|
old_codenames = Permission.objects.filter(group__in=[g], content_type=old_ct).values('codename')
|
||||||
|
g.permissions.add(*new_perms.filter(codename__in=old_codenames))
|
||||||
|
g.permissions.remove(*old_perms)
|
||||||
|
|
||||||
|
def obnov_prava_k_nastaveni(apps, schema_editor):
|
||||||
|
ContentType = apps.get_model('contenttypes', 'ContentType')
|
||||||
|
Permission = apps.get_model('auth', 'Permission')
|
||||||
|
Group = apps.get_model('auth', 'Group')
|
||||||
|
old_ct = ContentType.objects.get_by_natural_key('seminar', 'nastaveni')
|
||||||
|
new_ct = ContentType.objects.get_by_natural_key('various', 'nastaveni')
|
||||||
|
old_perms = Permission.objects.filter(content_type=old_ct)
|
||||||
|
new_perms = Permission.objects.filter(content_type=new_ct)
|
||||||
|
for g in Group.objects.filter(permissions__in=old_perms):
|
||||||
|
new_codenames = Permission.objects.filter(group__in=[g], content_type=new_ct).values('codename')
|
||||||
|
g.permissions.add(*old_perms.filter(codename__in=new_codenames))
|
||||||
|
g.permissions.remove(*new_perms)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('various', '0002_alter_nastaveni_options'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(oprav_prava_k_nastaveni, obnov_prava_k_nastaveni),
|
||||||
|
]
|
Loading…
Reference in a new issue