# -*- coding: utf-8 -*-
# Generated by Django 1.11.21 on 2019-07-23 16:43
from __future__ import unicode_literals

from __future__ import absolute_import
from django.core.management import call_command
from django.db import migrations

from corehq.apps.hqadmin.management.commands.cchq_prbac_bootstrap import (
    cchq_prbac_bootstrap,
)
from corehq.privileges import (
    CASE_SHARING_GROUPS,
    CHILD_CASES,
)


def _grandfather_case_privs(apps, schema_editor):
    call_command(
        'cchq_prbac_grandfather_privs',
        CASE_SHARING_GROUPS,
        CHILD_CASES,
        noinput=True,
    )


class Migration(migrations.Migration):

    dependencies = [
        ('accounting', '0042_domain_user_history__unique__and__nonnullable'),
    ]

    operations = [
        migrations.RunPython(cchq_prbac_bootstrap),
        migrations.RunPython(_grandfather_case_privs),
    ]

add migration to grandfather in all existing plans to have Case Sharing via Groups and Child Cases privileges