# Generated by Django 4.2.x

from django.db import migrations


def update_captrack_basic_access_permission(apps, schema_editor):
    Permission = apps.get_model("auth", "Permission")
    ContentType = apps.get_model("contenttypes", "ContentType")

    try:
        ct = ContentType.objects.get(
            app_label="captrack",
            model="captracksettings",
        )
    except ContentType.DoesNotExist:
        # ContentType not created yet on fresh installs.
        # Safe to skip; permission name is cosmetic only.
        return

    Permission.objects.filter(
        content_type=ct,
        codename="basic_access",
    ).update(
        name="Can View Dashboard"
    )


class Migration(migrations.Migration):

    dependencies = [
        ("captrack", "0003_alter_captracksettings_options"),
        ("auth", "0012_alter_user_first_name_max_length"),
        ("contenttypes", "0002_remove_content_type_name"),
    ]

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