# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

# Generated by Django 1.11.4 on 2017-08-31 15:23

from django.db import migrations


def correct_uploaders_group(apps, schema_editor):
    Group = apps.get_model("auth", "Group")
    Permission = apps.get_model("auth", "Permission")
    for group in Group.objects.filter(name="Uploaders"):
        right_permission = Permission.objects.get(codename="upload_symbols")
        wrong_permission = Permission.objects.get(codename="add_upload")
        if (
            right_permission not in group.permissions.all()
            and wrong_permission in group.permissions.all()
        ):
            group.permissions.add(right_permission)
            group.permissions.remove(wrong_permission)


class Migration(migrations.Migration):
    dependencies = [
        ("upload", "0009_upload_cancelled_at"),
    ]

    operations = [
        migrations.RunPython(correct_uploaders_group),
    ]
