# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2016-12-02 13:32
from __future__ import unicode_literals

import django.core.validators
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models

import jasmin_services.models


class Migration(migrations.Migration):
    initial = True

    dependencies = [
        ("jasmin_metadata", "0001_initial"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("contenttypes", "0002_remove_content_type_name"),
        ("jasmin_notifications", "0001_initial"),
    ]

    operations = [
        migrations.CreateModel(
            name="Behaviour",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="Category",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "name",
                    models.SlugField(
                        help_text="Short name for the category, used in URLs",
                        unique=True,
                    ),
                ),
                (
                    "long_name",
                    models.CharField(
                        help_text="Long name for the category, used for display",
                        max_length=250,
                    ),
                ),
                (
                    "position",
                    models.PositiveIntegerField(
                        default=9999,
                        help_text="Number defining where the category appears in listings. Categories are ordered in ascending order by this field, then alphabetically by name within that.",
                    ),
                ),
            ],
            options={
                "verbose_name_plural": "Categories",
                "ordering": ("position", "long_name"),
            },
        ),
        migrations.CreateModel(
            name="Grant",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "role",
                    models.CharField(
                        choices=[
                            ("USER", "USER"),
                            ("VIEW_USERS", "VIEW_USERS"),
                            ("APPROVER", "APPROVER"),
                        ],
                        default="USER",
                        max_length=10,
                    ),
                ),
                ("granted_by", models.CharField(max_length=200)),
                ("granted_at", models.DateTimeField(auto_now_add=True)),
                (
                    "expires",
                    models.DateField(
                        default=jasmin_services.models.grant._default_expiry,
                        verbose_name="expiry date",
                    ),
                ),
                ("revoked", models.BooleanField(default=False)),
                (
                    "user_reason",
                    models.TextField(
                        blank=True,
                        help_text='<a href="http://daringfireball.net/projects/markdown/syntax" target="_blank">Markdown syntax</a> allowed, but no raw HTML. Examples: **bold**, *italic*, indent 4 spaces for a code block.',
                        verbose_name="Reason for revocation (user)",
                    ),
                ),
                (
                    "internal_reason",
                    models.TextField(
                        blank=True,
                        help_text='<a href="http://daringfireball.net/projects/markdown/syntax" target="_blank">Markdown syntax</a> allowed, but no raw HTML. Examples: **bold**, *italic*, indent 4 spaces for a code block.',
                        verbose_name="Reason for revocation (internal)",
                    ),
                ),
            ],
            options={
                "ordering": ("service__category__name", "service__name", "-granted_at"),
                "get_latest_by": "granted_at",
            },
        ),
        migrations.CreateModel(
            name="Request",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "role",
                    models.CharField(
                        choices=[
                            ("USER", "USER"),
                            ("VIEW_USERS", "VIEW_USERS"),
                            ("APPROVER", "APPROVER"),
                        ],
                        default="USER",
                        max_length=10,
                    ),
                ),
                ("requested_by", models.CharField(max_length=200)),
                ("requested_at", models.DateTimeField(auto_now_add=True)),
                (
                    "state",
                    models.CharField(
                        choices=[
                            ("APPROVED", "APPROVED"),
                            ("PENDING", "PENDING"),
                            ("REJECTED", "REJECTED"),
                        ],
                        default="PENDING",
                        max_length=8,
                    ),
                ),
                (
                    "user_reason",
                    models.TextField(
                        blank=True,
                        help_text='<a href="http://daringfireball.net/projects/markdown/syntax" target="_blank">Markdown syntax</a> allowed, but no raw HTML. Examples: **bold**, *italic*, indent 4 spaces for a code block.',
                        verbose_name="Reason for rejection (user)",
                    ),
                ),
                (
                    "internal_reason",
                    models.TextField(
                        blank=True,
                        help_text='<a href="http://daringfireball.net/projects/markdown/syntax" target="_blank">Markdown syntax</a> allowed, but no raw HTML. Examples: **bold**, *italic*, indent 4 spaces for a code block.',
                        verbose_name="Reason for rejection (internal)",
                    ),
                ),
                (
                    "grant",
                    models.OneToOneField(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="request",
                        to="jasmin_services.Grant",
                    ),
                ),
            ],
            options={
                "ordering": (
                    "service__category__name",
                    "service__name",
                    "-requested_at",
                ),
            },
        ),
        migrations.CreateModel(
            name="Service",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "name",
                    models.SlugField(
                        help_text="The name of the service. This is also used in URLs."
                    ),
                ),
                (
                    "summary",
                    models.TextField(
                        help_text="One-line description of the service, shown in listings. No special formatting allowed."
                    ),
                ),
                (
                    "description",
                    models.TextField(
                        blank=True,
                        default="",
                        help_text="Full description of the service, shown on the details page. Markdown formatting is allowed.",
                        null=True,
                    ),
                ),
                (
                    "hidden",
                    models.BooleanField(
                        default=True,
                        help_text="Prevents the service appearing in listings unless the user has an active grant or request for it. The service details page will still be accessible to anybody who knows the URL.",
                    ),
                ),
                (
                    "manual_intervention_required",
                    models.BooleanField(
                        default=False,
                        help_text="Check this box if manual intervention is required to enable or disable this service.<br>Registered approvers will receive an email when grants are revoked or expire.",
                    ),
                ),
                (
                    "position",
                    models.PositiveIntegerField(
                        default=9999,
                        help_text="Number defining where the service appears in listings. Services are ordered in ascending order by category, then by this field, then alphabetically by name.",
                    ),
                ),
                (
                    "category",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="services",
                        related_query_name="service",
                        to="jasmin_services.Category",
                    ),
                ),
            ],
            options={
                "ordering": (
                    "category__position",
                    "category__long_name",
                    "position",
                    "name",
                ),
            },
        ),
        migrations.CreateModel(
            name="ServiceRoleBehaviour",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "role",
                    models.CharField(
                        choices=[
                            ("USER", "USER"),
                            ("VIEW_USERS", "VIEW_USERS"),
                            ("APPROVER", "APPROVER"),
                        ],
                        max_length=10,
                    ),
                ),
            ],
            options={
                "verbose_name_plural": "Service Behaviours",
            },
        ),
        migrations.CreateModel(
            name="ServiceRoleMetadataForm",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "role",
                    models.CharField(
                        choices=[
                            ("USER", "USER"),
                            ("VIEW_USERS", "VIEW_USERS"),
                            ("APPROVER", "APPROVER"),
                        ],
                        max_length=10,
                    ),
                ),
                (
                    "form",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="+",
                        to="jasmin_metadata.Form",
                    ),
                ),
                (
                    "service",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="form_join_set",
                        related_query_name="form_join",
                        to="jasmin_services.Service",
                    ),
                ),
            ],
            options={
                "verbose_name_plural": "Metadata Forms",
            },
        ),
        migrations.CreateModel(
            name="LdapGroupBehaviour",
            fields=[
                (
                    "behaviour_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="jasmin_services.Behaviour",
                    ),
                ),
                (
                    "group_dn",
                    models.CharField(
                        help_text="The LDAP group to use",
                        max_length=250,
                        unique=True,
                        verbose_name="LDAP Group",
                    ),
                ),
            ],
            options={
                "verbose_name": "LDAP Group Behaviour",
            },
            bases=("jasmin_services.behaviour",),
        ),
        migrations.CreateModel(
            name="LdapTagBehaviour",
            fields=[
                (
                    "behaviour_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="jasmin_services.Behaviour",
                    ),
                ),
                (
                    "tag",
                    models.CharField(
                        max_length=100,
                        unique=True,
                        validators=[
                            django.core.validators.RegexValidator(regex="^[a-zA-Z0-9_:-]+$")
                        ],
                        verbose_name="LDAP Tag",
                    ),
                ),
            ],
            options={
                "verbose_name": "LDAP Tag Behaviour",
            },
            bases=("jasmin_services.behaviour",),
        ),
        migrations.CreateModel(
            name="NotifyOnceBehaviour",
            fields=[
                (
                    "behaviour_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="jasmin_services.Behaviour",
                    ),
                ),
                ("name", models.CharField(max_length=100)),
                ("email", models.EmailField(max_length=254)),
                ("link", models.CharField(blank=True, max_length=250)),
                (
                    "notification_type",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="jasmin_notifications.NotificationType",
                    ),
                ),
            ],
            options={
                "verbose_name": "Notify Once Behaviour",
            },
            bases=("jasmin_services.behaviour",),
        ),
        migrations.AddField(
            model_name="servicerolebehaviour",
            name="behaviour",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="service_join_set",
                related_query_name="service_join",
                to="jasmin_services.Behaviour",
            ),
        ),
        migrations.AddField(
            model_name="servicerolebehaviour",
            name="service",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="behaviour_join_set",
                related_query_name="behaviour_join",
                to="jasmin_services.Service",
            ),
        ),
        migrations.AddField(
            model_name="request",
            name="service",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="requests",
                related_query_name="request",
                to="jasmin_services.Service",
            ),
        ),
        migrations.AddField(
            model_name="request",
            name="user",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL
            ),
        ),
        migrations.AddField(
            model_name="grant",
            name="service",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="grants",
                related_query_name="grant",
                to="jasmin_services.Service",
            ),
        ),
        migrations.AddField(
            model_name="grant",
            name="user",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL
            ),
        ),
        migrations.AddField(
            model_name="behaviour",
            name="polymorphic_ctype",
            field=models.ForeignKey(
                editable=False,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="polymorphic_jasmin_services.behaviour_set+",
                to="contenttypes.ContentType",
            ),
        ),
        migrations.AlterUniqueTogether(
            name="servicerolemetadataform",
            unique_together=set([("service", "role")]),
        ),
        migrations.AlterUniqueTogether(
            name="servicerolebehaviour",
            unique_together=set([("service", "role", "behaviour")]),
        ),
        migrations.AlterUniqueTogether(
            name="service",
            unique_together=set([("category", "name")]),
        ),
    ]
