# Generated by Django 3.2.7 on 2022-01-17 09:14

from django.db import migrations

# Create permission "set_topprioritybarrier" and add to "Administrator" group
def add_top_barrier_permissions(app, schema_editor):
    Permission = app.get_model("auth", "Permission")
    Group = app.get_model("auth", "Group")
    ContentType = app.get_model("contenttypes", "ContentType")
    User = app.get_model("auth", "User")

    user_content_type = ContentType.objects.get_for_model(User)

    set_topprioritybarrier, created = Permission.objects.get_or_create(
        codename="set_topprioritybarrier",
        defaults={
            "name": "Can add or remove Top-Priority Barrier tags",
            "content_type": user_content_type,
        },
    )

    administrator_group = Group.objects.get(name="Administrator")
    administrator_group.permissions.add(
        set_topprioritybarrier,
    )


# Remove permission "set_topprioritybarrier" from "Administrator" group and delete it
def remove_top_barrier_permissions(apps, schema_editor):
    Permission = apps.get_model("auth", "Permission")
    set_topprioritybarrier_permission = Permission.objects.get(
        codename="set_topprioritybarrier",
    )
    set_topprioritybarrier_permission.delete()


class Migration(migrations.Migration):

    dependencies = [
        ("user", "0025_add_permissions_to_admin"),
    ]

    operations = [
        migrations.RunPython(
            code=add_top_barrier_permissions,
            reverse_code=remove_top_barrier_permissions,
        ),
    ]
