# Generated by Django 2.0.8 on 2018-11-16 13:43

import datasources.models
from django.db import migrations, models


def access_control_forward(apps, schema_editor):
    DataSource = apps.get_model('datasources', 'DataSource')

    for data_source in DataSource.objects.all():
        if data_source.access_control:
            data_source.public_permission_level = datasources.models.UserPermissionLevels.NONE
            data_source.save()


def access_control_backward(apps, schema_editor):
    DataSource = apps.get_model('datasources', 'DataSource')

    for data_source in DataSource.objects.all():
        if data_source.public_permission_level == datasources.models.UserPermissionLevels.NONE:
            data_source.access_control = True
            data_source.save()


class Migration(migrations.Migration):

    dependencies = [
        ('datasources', '0013_is_encrypted'),
    ]

    operations = [
        migrations.AddField(
            model_name='datasource',
            name='public_permission_level',
            field=models.IntegerField(choices=[(0, 'NONE'), (1, 'VIEW'), (2, 'META'), (3, 'DATA'), (4, 'PROV')], default=datasources.models.UserPermissionLevels(3)),
        ),
        migrations.RunPython(access_control_forward, access_control_backward),
        migrations.RemoveField(
            model_name='datasource',
            name='access_control',
        ),
    ]
