# Generated by Django 2.2.13 on 2020-06-24 14:20

from django.db import migrations


def assign_permissions(apps, schema_editor):
    Permission = apps.get_model("auth", "Permission")
    Group = apps.get_model("auth", "Group")
    ContentType = apps.get_model("contenttypes", "ContentType")
    User = apps.get_model("auth", "User")

    user_content_type = ContentType.objects.get_for_model(User)

    change_user_permission, created = Permission.objects.get_or_create(
        codename="change_user",
        defaults={"name": "Can change user", "content_type": user_content_type},
    )
    list_users_permission, created = Permission.objects.get_or_create(
        codename="list_users",
        defaults={"name": "Can list users", "content_type": user_content_type},
    )

    administrator_group = Group.objects.get(name="Administrator")
    administrator_group.permissions.add(change_user_permission)
    administrator_group.permissions.add(list_users_permission)


class Migration(migrations.Migration):

    dependencies = [
        ("contenttypes", "0001_initial"),
        ("user", "0013_add_permission_groups"),
    ]

    operations = [
        migrations.RunPython(
            assign_permissions, reverse_code=migrations.RunPython.noop
        ),
    ]
