# Generated by Django 2.0.8 on 2018-08-17 08:01

import django.contrib.postgres.fields.jsonb
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models

import terracommon.accounts.mixins
import terracommon.trrequests.helpers


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('terra', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Comment',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('properties', django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=dict)),
                ('is_internal', models.BooleanField(default=False)),
                ('attachment', models.FileField(blank=True, upload_to=terracommon.trrequests.helpers.rename_comment_attachment)),
                ('filename', models.CharField(blank=True, editable=False, help_text='Initial name of the attachment', max_length=255)),
                ('layer', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='terra.Layer')),
                ('owner', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='UserRequest',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('expiry', models.DateField(default=None, null=True)),
                ('state', models.IntegerField(default=100)),
                ('properties', django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=dict)),
                ('layer', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='userrequests', to='terra.Layer')),
                ('owner', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='userrequests', to=settings.AUTH_USER_MODEL)),
                ('reviewers', models.ManyToManyField(blank=True, related_name='to_review', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'permissions': (('can_create_requests', 'Is able to create a new requests'), ('can_read_self_requests', 'Is able to get own requests'), ('can_read_all_requests', 'Is able to get all requests'), ('can_comment_requests', 'Is able to comment an user request'), ('can_internal_comment_requests', 'Is able to add comments not visible by users'), ('can_read_comment_requests', 'Is allowed to read only non-internal comments'), ('can_change_state_requests', 'Is authorized to change the request state')),
            },
            bases=(models.Model, terracommon.accounts.mixins.ReadableModelMixin),
        ),
        migrations.AddField(
            model_name='comment',
            name='userrequest',
            field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='comments', to='trrequests.UserRequest'),
        ),
    ]
