# Generated by Django 3.2.7 on 2021-12-17 09:18

from django.db import migrations


def create_action_plans_group(apps, schema_editor):
    Group = apps.get_model("auth", "Group")
    Group.objects.create(name="Action plan user")

    Permission = apps.get_model("auth", "Permission")
    ContentType = apps.get_model("contenttypes", "ContentType")
    ActionPlan = apps.get_model("action_plans", "ActionPlan")
    action_plan_content_type = ContentType.objects.get_for_model(ActionPlan)
    view_action_plans_permission, created = Permission.objects.get_or_create(
        codename="view_action_plans",
        defaults={
            "name": "Can view action plans",
            "content_type": action_plan_content_type,
        },
    )
    group = Group.objects.get(name="Action plan user")
    group.permissions.add(view_action_plans_permission)

def reverse_create_action_plans_group(apps, schema_editor):
    Group = apps.get_model("auth", "Group")
    Group.objects.filter(name="Action plan user").delete()

    Permission = apps.get_model("auth", "Permission")
    ContentType = apps.get_model("contenttypes", "ContentType")
    ActionPlan = apps.get_model("action_plans", "ActionPlan")
    action_plan_content_type = ContentType.objects.get_for_model(ActionPlan)
    view_action_plans_permission = Permission.objects.get(
        codename="view_action_plans",
        content_type=action_plan_content_type,
    )
    view_action_plans_permission.delete()

class Migration(migrations.Migration):

    dependencies = [
        ("user", "0023_create_barrier_search_download_approved_group"),
    ]

    operations = [migrations.RunPython(create_action_plans_group, reverse_code=reverse_create_action_plans_group)]

# Generated by Django 3.2.7 on 2021-12-17 09:18

from django.db import migrations


def create_action_plans_group(apps, schema_editor):
    Group = apps.get_model("auth", "Group")
    Group.objects.create(name="Action plan user")

    Permission = apps.get_model("auth", "Permission")
    ContentType = apps.get_model("contenttypes", "ContentType")
    ActionPlan = apps.get_model("action_plans", "ActionPlan")
    action_plan_content_type = ContentType.objects.get_for_model(ActionPlan)
    view_action_plans_permission, created = Permission.objects.get_or_create(
        codename="view_action_plans",
        defaults={
            "name": "Can view action plans",
            "content_type": action_plan_content_type,
        },
    )
    group = Group.objects.get(name="Action plan user")
    group.permissions.add(view_action_plans_permission)

def reverse_create_action_plans_group(apps, schema_editor):
    Group = apps.get_model("auth", "Group")
    Group.objects.filter(name="Action plan user").delete()

    Permission = apps.get_model("auth", "Permission")
    ContentType = apps.get_model("contenttypes", "ContentType")
    ActionPlan = apps.get_model("action_plans", "ActionPlan")
    action_plan_content_type = ContentType.objects.get_for_model(ActionPlan)
    view_action_plans_permission = Permission.objects.get(
        codename="view_action_plans",
        content_type=action_plan_content_type,
    )
    view_action_plans_permission.delete()

class Migration(migrations.Migration):

    dependencies = [
        ("user", "0023_create_barrier_search_download_approved_group"),
    ]

    operations = [migrations.RunPython(create_action_plans_group, reverse_code=reverse_create_action_plans_group)]

# Generated by Django 3.2.7 on 2021-12-17 09:18