# Generated by Django 4.2.9 on 2024-10-30 19:02

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 = ["Tag 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 == 'tag']
    Group.objects.get(name="Tag editor").permissions.add(*editor_perms)

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

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

class Migration(migrations.Migration):

    dependencies = [
        ('agenda_culturel', '0093_tag'),
    ]

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