# 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 http://mozilla.org/MPL/2.0/.
# -*- coding: utf-8 -*-
# Generated by Django 1.9.11 on 2017-01-13 15:38
from django.db import migrations

from atmo.models import PermissionMigrator


def assign_sshkey_view_permission(apps, schema_editor):
    SSHKey = apps.get_model("keys", "SSHKey")
    PermissionMigrator(apps, SSHKey, "view", user_field="created_by").assign()
    PermissionMigrator(apps, SSHKey, "change", user_field="created_by").assign()
    PermissionMigrator(apps, SSHKey, "delete", user_field="created_by").assign()


def remove_sshkey_view_permission(apps, schema_editor):
    SSHKey = apps.get_model("jobs", "SSHKey")
    PermissionMigrator(apps, SSHKey, "view", user_field="created_by").remove()
    PermissionMigrator(apps, SSHKey, "change", user_field="created_by").remove()
    PermissionMigrator(apps, SSHKey, "delete", user_field="created_by").remove()


class Migration(migrations.Migration):

    dependencies = [("guardian", "0001_initial"), ("keys", "0001_initial")]

    operations = [
        migrations.RunPython(
            assign_sshkey_view_permission, remove_sshkey_view_permission
        )
    ]
