# Generated by Django 5.0.7 on 2024-07-12 23:02

from django.db import migrations


def apply_migration(apps, schema_editor):
    db_alias = schema_editor.connection.alias
    Group = apps.get_model("auth", "Group")
    Permission = apps.get_model("auth", "Permission")
    g = Group.objects.using(db_alias).get(name="API Users")
    upload_permission = Permission.objects.using(db_alias).get(
        content_type__app_label="sphinxhostingcore",
        codename="add_version"
    )
    change_project_permission = Permission.objects.using(db_alias).get(
        content_type__app_label="sphinxhostingcore",
        codename="change_project"
    )
    g.permissions.add(
        upload_permission,
        change_project_permission
    )


def revert_migration(apps, schema_editor):
    db_alias = schema_editor.connection.alias
    Group = apps.get_model("auth", "Group")
    Permission = apps.get_model("auth", "Permission")
    g = Group.objects.using(db_alias).get(name="API Users")
    upload_permission = Permission.objects.using(db_alias).get(
        content_type__app_label="sphinxhostingcore",
        codename="add_version"
    )
    change_project_permission = Permission.objects.using(db_alias).get(
        content_type__app_label="sphinxhostingcore",
        codename="change_project"
    )
    g.permissions.remove(
        upload_permission,
        change_project_permission
    )


class Migration(migrations.Migration):

    dependencies = [
        ('users', '0004_apiuser'),
    ]

    operations = [migrations.RunPython(apply_migration, revert_migration)]
