# Generated by Django 2.2.15 on 2020-08-11 19:44

from django.db import migrations
from django.contrib.auth.management import create_permissions


# Ensures that the new permissions are added to the database so that they can
# be assigned during migrations
# based off of https://stackoverflow.com/a/40092780
def initialize_permissions(apps, schema_editor):
    for app_config in apps.get_app_configs():
        app_config.models_module = True
        create_permissions(app_config, apps=apps, verbosity=0)
        app_config.models_module = None


class Migration(migrations.Migration):

    dependencies = [
        ('galaxy', '0003_inbound_repo_per_namespace'),
    ]

    # The commented out operations were used to map the group fields that were part of the legacy permissioning
    # system when galaxy_ng was only deployed on console.redhat.com to django guardian permissions. With the
    # removal of django guardian, they can no longer be run. Since the first release of galaxy_ng (4.2)
    # included all the migrations up to 0013, theses data migrations are not required by any deployments and
    # can safely be removed.
    operations = [
        migrations.AlterModelOptions(
            name='namespace',
            options={'permissions': (('upload_to_namespace', 'Can upload collections to namespace'),)},
        ),
        migrations.RunPython(
            code=initialize_permissions,
        ),
        # migrations.RunPython(
        #     code=convert_namespace_groups_to_permissions,
        # ),
        migrations.RemoveField(
            model_name='namespace',
            name='groups',
        ),
        # migrations.RunPython(
        #     code=convert_synclist_groups_to_permissions,
        # ),
        migrations.RemoveField(
            model_name='synclist',
            name='groups',
        ),
        migrations.RemoveField(
            model_name='synclist',
            name='users',
        ),
    ]
