Browse Source

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?
pull/43/head
Pavel 'LEdoian' Turinsky 11 months ago
parent
commit
37586d7433
  1. 41
      various/migrations/0003_fix_permissions.py

41
various/migrations/0003_fix_permissions.py

@ -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…
Cancel
Save