# Generated by Django 3.2.18 on 2023-04-21 14:44

from django.contrib.auth.management import create_permissions
from django.db import migrations


# https://stackoverflow.com/a/40092780/1336275
def migrate_permissions(apps, schema_editor):
    for app_config in apps.get_app_configs():
        app_config.models_module = True
        create_permissions(app_config, apps=apps, verbosity=0)
        app_config.models_module = None


def add_group_permissions(apps, schema_editor):
    Group = apps.get_model("auth", "Group")
    Permission = apps.get_model("auth", "Permission")
    can_delete_oois = Permission.objects.get(codename="can_delete_oois")
    try:
        redteam = Group.objects.get(name="redteam")
        admin = Group.objects.get(name="admin")
        redteam.permissions.add(can_delete_oois)
        admin.permissions.add(can_delete_oois)
    except Group.DoesNotExist:
        pass


class Migration(migrations.Migration):
    dependencies = [("tools", "0034_alter_organization_options"), ("contenttypes", "0002_remove_content_type_name")]

    operations = [migrations.RunPython(migrate_permissions), migrations.RunPython(add_group_permissions)]
