# Generated by Django 4.2.7 on 2024-04-17 10:12

from django.db import migrations
from django.contrib.auth.models import Group, Permission

def update_groups_permissions(apps, schema_editor):
    # first add a missing role
    user_roles = ["Static content editor"]

    for name in user_roles:
        Group.objects.create(name=name)

    all_perms = Permission.objects.all()

    # set permissions for moderators
    editor_perms = [i for i in all_perms if i.content_type.app_label == 'agenda_culturel' and i.content_type.model == 'staticcontent']
    Group.objects.get(name="Static content editor").permissions.add(*editor_perms)

def update_groups_delete(apps, schema_editor):
    user_roles = ["Static content editor"]

    for name in user_roles:
        Group.objects.filter(name=name).delete()

class Migration(migrations.Migration):

    dependencies = [
        ('agenda_culturel', '0047_categorisationrule_loc_exact_and_more'),
    ]

    operations = [
        migrations.RunPython(update_groups_permissions, reverse_code=update_groups_delete),
    ]
