# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2019-09-13 13:35
from django.db import migrations


def give_permissions(apps, schema_editor):
    User = apps.get_model('users', 'User')
    Permission = apps.get_model('auth', 'Permission')
    robot_usernames = (
        'robot-forms',
        'tech-robot',
    )

    perm = Permission.objects.get(codename='can_use_api_for_forms_constructor')
    robots = User.objects.filter(username__in=robot_usernames)
    for robot in robots:
        robot.user_permissions.add(perm)


class Migration(migrations.Migration):

    dependencies = [
        ('permissions', '0005_add_screening_reviewer'),
    ]

    operations = [
        migrations.AlterModelOptions(
            name='globalpermission',
            options={
                'managed': False,
                'permissions': (
                    ('recruiter_perm', 'Recruiter'),
                    ('recruiting_manager_perm', 'Recruiting manager'),
                    ('recruiter_assessor_perm', 'Recruiter-assessor'),
                    ('publication_manager_perm', 'Publication manager'),
                    ('reference_coordinator_perm', 'Reference coordinator'),
                    ('analyst_perm', 'Analyst'),
                    ('aa_perm', 'AA'),
                    ('aa_frontend_perm', 'AA-frontend'),
                    ('aa_management_perm', 'AA-management'),
                    ('aa_ml_perm', 'AA-ml'),
                    ('aa_dev_ops_perm', 'AA-DevOps'),
                    ('aa_lite_perm', 'AA-Lite'),
                    ('aa_easy_perm', 'AA-Easy'),
                    ('aa_to_perm', 'AA-TO'),
                    ('aa_sd_perm', 'AA-SD'),
                    ('aa_analytic_perm', 'AA-Analytic'),
                    ('screening_reviewer_perm', 'Screening reviewer'),
                    ('can_see_publications', 'Can see publications'),
                    ('can_export_from_admin', 'Can export from admin'),
                    ('can_use_yt_candidate_uploader', 'Can use YT candidate uploader'),
                    ('can_use_yt_candidate_scoring_uploader', 'Can use YT candidate scorings uploader'),
                    ('can_use_api_for_isearch', 'Can use API for ISearch'),
                    ('can_use_api_for_separator', 'Can use API for Separator'),
                    ('can_use_api_for_newhire', 'Can use API for Newhire'),
                    ('can_use_api_for_staff', 'Can use API for Staff'),
                    ('can_use_api_for_forms_constructor', 'Can use API for Forms'),
                    ('can_use_api_for_yang', 'Can use API for Yang'),
                    ('can_use_frontend_version_view', 'Can use frontend version view'),
                    ('can_view_startrek_changelog', 'Can view Startrek changelog'),
                    # Права, доступные сервисам (но могут быть доступны и пользователям)
                    ('can_access_femida', 'Доступ к Фемиде (TVM)'),
                    ('can_access_magiclinks_data', 'Доступ к данным для магических ссылок'),
                    ('can_view_external_publications', 'Просмотр внешних объявлений'),
                    ('can_use_hire_orders', 'Использование автонайма'),
                    ('can_see_all_attachments', 'Просмотр всех файлов'),
                    ('can_access_certification_data', 'Доступ к сертификатам о прохождении испытания'),
                ),
            },
        ),
        migrations.RunPython(give_permissions, lambda *x, **y: None),
    ]
