# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2016-03-11 16:22
from __future__ import unicode_literals

import audit_log.models.fields
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='PermissionSet',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('anonymous_user', models.BooleanField(default=False)),
            ],
        ),
        migrations.CreateModel(
            name='Policy',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=200)),
                ('body', models.TextField()),
            ],
        ),
        migrations.CreateModel(
            name='PolicyAuditLogEntry',
            fields=[
                ('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
                ('name', models.CharField(max_length=200)),
                ('body', models.TextField()),
                ('action_id', models.AutoField(primary_key=True, serialize=False)),
                ('action_date', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
                ('action_type', models.CharField(choices=[('I', 'Created'), ('U', 'Changed'), ('D', 'Deleted')], editable=False, max_length=1)),
                ('action_user', audit_log.models.fields.LastUserField(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='_policy_audit_log_entry', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ('-action_date',),
                'default_permissions': (),
            },
        ),
        migrations.CreateModel(
            name='PolicyInstance',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('index', models.IntegerField()),
                ('variables', models.TextField()),
                ('policy', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='tutelary.Policy')),
                ('pset', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tutelary.PermissionSet')),
            ],
            options={
                'ordering': ['index'],
            },
        ),
        migrations.CreateModel(
            name='Role',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=200)),
                ('variables', models.TextField()),
            ],
        ),
        migrations.CreateModel(
            name='RoleAuditLogEntry',
            fields=[
                ('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
                ('name', models.CharField(max_length=200)),
                ('variables', models.TextField()),
                ('action_id', models.AutoField(primary_key=True, serialize=False)),
                ('action_date', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
                ('action_type', models.CharField(choices=[('I', 'Created'), ('U', 'Changed'), ('D', 'Deleted')], editable=False, max_length=1)),
                ('action_user', audit_log.models.fields.LastUserField(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='_role_audit_log_entry', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ('-action_date',),
                'default_permissions': (),
            },
        ),
        migrations.CreateModel(
            name='RolePolicyAssign',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('index', models.IntegerField()),
                ('policy', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='tutelary.Policy')),
                ('role', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tutelary.Role')),
            ],
            options={
                'ordering': ['index'],
            },
        ),
        migrations.AddField(
            model_name='role',
            name='policies',
            field=models.ManyToManyField(through='tutelary.RolePolicyAssign', to='tutelary.Policy'),
        ),
        migrations.AddField(
            model_name='policyinstance',
            name='role',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='tutelary.Role'),
        ),
        migrations.AddField(
            model_name='permissionset',
            name='policy_assign',
            field=models.ManyToManyField(through='tutelary.PolicyInstance', to='tutelary.Policy'),
        ),
        migrations.AddField(
            model_name='permissionset',
            name='users',
            field=models.ManyToManyField(related_name='permissionset', to=settings.AUTH_USER_MODEL),
        ),
    ]
