# Generated by Django 3.2.16 on 2023-03-09 17:14

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

"""
    CMS-Editors: 
        Wagtail: Alle Rechte
        Django: Bereich «Lernziele»

    Support:
        Django: Bereich «User»

    News:
        Django: Bereich «News»

"""

news = ["news"]
support = ["users", "auth"]
cms_editors = [
    "objectives",
    "books",
    "assignments",
    "basicknowledge",
    "surveys",
    "wagtailadmin",
    "wagtailcore",
    "wagtailimages",
    "wagtailembeds",
    "wagtailredirects",
    "wagtailsearch",
    "wagtailusers",
    "wagtaildocs",
]

groups = [("News", news), ("CMS-Editors", cms_editors), ("Support", support)]


def add_permissions(apps, schema_editor):
    for name, app_labels in groups:
        group, _ = Group.objects.get_or_create(name=name)
        for app_label in app_labels:
            for permission in Permission.objects.filter(
                content_type__app_label=app_label
            ):
                group.permissions.add(permission)


class Migration(migrations.Migration):
    dependencies = [
        ("core", "0002_delete_admindata"),
    ]

    operations = [
        migrations.RunPython(add_permissions, migrations.RunPython.noop),
    ]
