# -*- coding: utf-8 -*-
# Generated by Django 1.9.12 on 2017-03-20 23:26
from __future__ import unicode_literals

from django.db import migrations

from atmo.models import PermissionMigrator


def assign_spark_job_view_permission_to_group(apps, schema_editor):
    SparkJob = apps.get_model("jobs", "SparkJob")
    Group = apps.get_model("auth", "Group")

    group, created = Group.objects.get_or_create(name="Spark job maintainers")
    PermissionMigrator(apps, SparkJob, "view", group=group).assign()


def remove_spark_job_view_permission_to_group(apps, schema_editor):
    SparkJob = apps.get_model("jobs", "SparkJob")
    Group = apps.get_model("auth", "Group")

    group = Group.objects.get(name="Spark job maintainers")
    PermissionMigrator(apps, SparkJob, "view", group=group).remove()


class Migration(migrations.Migration):

    dependencies = [("jobs", "0016_auto_20170320_0943")]

    operations = [
        migrations.RunPython(
            assign_spark_job_view_permission_to_group,
            remove_spark_job_view_permission_to_group,
        )
    ]
