# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-04-29 16:41
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import mailauth.models
import oauth2_provider.generators
import oauth2_provider.validators
import uuid


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('auth', '0008_alter_user_username_max_length'),
    ]

    run_before = [
        ('oauth2_provider', '0001_initial'),
    ]

    operations = [
        migrations.CreateModel(
            name='MNUser',
            fields=[
                ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
                ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, verbose_name='Shareable ID')),
                ('identifier', models.CharField(db_index=True, max_length=255, unique=True, verbose_name='User ID')),
                ('fullname', models.CharField(max_length=255, verbose_name='Full name')),
                ('password', mailauth.models.PretendHasherPasswordField(max_length=128, verbose_name='Password')),
                ('pgp_key_id', models.CharField(blank=True, default='', max_length=64, verbose_name='PGP Key ID')),
                ('yubikey_serial', models.CharField(blank=True, default='', max_length=64, verbose_name='Yubikey Serial')),
                ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='Staff status')),
                ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='Active')),
            ],
            options={
                'verbose_name_plural': 'User accounts',
            },
            managers=[
                ('objects', mailauth.models.MNUserManager()),
            ],
        ),
        migrations.CreateModel(
            name='Domain',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=255, unique=True)),
                ('dkimselector', models.CharField(blank=True, default='default', max_length=255, verbose_name='DKIM DNS selector')),
                ('dkimkey', models.TextField(blank=True, verbose_name='DKIM private key (PEM)')),
            ],
        ),
        migrations.CreateModel(
            name='EmailAlias',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('mailprefix', models.CharField(max_length=255, verbose_name='Mail prefix')),
                ('domain', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='mailauth.Domain', verbose_name='On domain')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='aliases', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name_plural': 'Email aliases',
            },
        ),
        migrations.CreateModel(
            name='MNApplication',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('client_id', models.CharField(db_index=True, default=oauth2_provider.generators.generate_client_id, max_length=100, unique=True)),
                ('redirect_uris', models.TextField(blank=True, help_text='Allowed URIs list, space separated')),
                ('client_type', models.CharField(choices=[('confidential', 'Confidential'), ('public', 'Public')], max_length=32)),
                ('authorization_grant_type', models.CharField(choices=[('authorization-code', 'Authorization code'), ('implicit', 'Implicit'), ('password', 'Resource owner password-based'), ('client-credentials', 'Client credentials')], max_length=32)),
                ('client_secret', models.CharField(blank=True, db_index=True, default=oauth2_provider.generators.generate_client_secret, max_length=255)),
                ('name', models.CharField(blank=True, max_length=255)),
                ('skip_authorization', models.BooleanField(default=False)),
            ],
            options={
                'verbose_name_plural': 'OAuth2 Applications',
            },
        ),
        migrations.CreateModel(
            name='MNApplicationPermission',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(blank=True, max_length=255, verbose_name='Human readable name')),
                ('scope_name', models.CharField(max_length=255, null=True, unique=True, verbose_name='OAuth2 scope string')),
            ],
            options={
                'verbose_name': 'application permissions',
                'verbose_name_plural': 'Application permissions',
            },
        ),
        migrations.CreateModel(
            name='MNGroups',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=255, verbose_name='Group name')),
                ('group_permissions', models.ManyToManyField(blank=True, help_text='Permissions for OAuth2/CAS applications', related_name='group_set', related_query_name='group', to='mailauth.MNApplicationPermission', verbose_name='Application permissions')),
            ],
            options={
                'verbose_name': 'OAuth2/CAS Groups',
                'verbose_name_plural': 'OAuth2/CAS Groups',
            },
        ),
        migrations.AddField(
            model_name='mnapplication',
            name='required_permissions',
            field=models.ManyToManyField(blank=True, help_text='Permissions required for this application', related_name='application_set', related_query_name='application', to='mailauth.MNApplicationPermission', verbose_name='required permissions'),
        ),
        migrations.AddField(
            model_name='mnapplication',
            name='user',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='mailauth_mnapplication', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='mnuser',
            name='app_groups',
            field=models.ManyToManyField(blank=True, related_name='user_set', related_query_name='user', to='mailauth.MNGroups', verbose_name='OAuth2/CAS Groups'),
        ),
        migrations.AddField(
            model_name='mnuser',
            name='app_permissions',
            field=models.ManyToManyField(blank=True, help_text='Permissions for networkapplications', related_name='user_set', related_query_name='user', to='mailauth.MNApplicationPermission', verbose_name='OAuth2/CAS Application permissions'),
        ),
        migrations.AddField(
            model_name='mnuser',
            name='delivery_mailbox',
            field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.PROTECT, to='mailauth.EmailAlias'),
        ),
        migrations.AddField(
            model_name='mnuser',
            name='groups',
            field=models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups'),
        ),
        migrations.AddField(
            model_name='mnuser',
            name='user_permissions',
            field=models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions'),
        ),
        migrations.AlterUniqueTogether(
            name='emailalias',
            unique_together=set([('mailprefix', 'domain')]),
        ),
    ]
