# Generated by Django 3.2.13 on 2023-01-15 20:46

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

import baserow.core.action.models


class Migration(migrations.Migration):
    dependencies = [
        ("core", "0042_add_ip_address_to_jobs"),
        ("baserow_enterprise", "0010_rename_no_role_to_no_access"),
    ]

    operations = [
        migrations.CreateModel(
            name="AuditLogEntry",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_on", models.DateTimeField(auto_now_add=True)),
                ("updated_on", models.DateTimeField(auto_now=True)),
                ("user_id", models.PositiveIntegerField(null=True)),
                ("user_email", models.CharField(blank=True, max_length=150, null=True)),
                ("group_id", models.PositiveIntegerField(null=True)),
                ("group_name", models.CharField(blank=True, max_length=160, null=True)),
                ("action_type", models.TextField()),
                ("action_timestamp", models.DateTimeField()),
                (
                    "action_params",
                    models.JSONField(
                        encoder=baserow.core.action.models.JSONEncoderSupportingDataClasses,
                        null=True,
                    ),
                ),
                (
                    "action_command_type",
                    models.CharField(
                        choices=[
                            ("DO", "DONE"),
                            ("REDO", "UNDONE"),
                            ("UNDO", "REDONE"),
                        ],
                        default="DO",
                        max_length=5,
                    ),
                ),
                (
                    "original_action_short_descr",
                    models.TextField(blank=True, null=True),
                ),
                ("original_action_long_descr", models.TextField(blank=True, null=True)),
                (
                    "original_action_context_descr",
                    models.TextField(blank=True, null=True),
                ),
                ("ip_address", models.GenericIPAddressField(null=True)),
            ],
            options={
                "ordering": ["-action_timestamp"],
            },
        ),
        migrations.CreateModel(
            name="AuditLogExportJob",
            fields=[
                (
                    "job_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="core.job",
                    ),
                ),
                (
                    "export_charset",
                    models.CharField(
                        choices=[
                            ("utf-8", "utf-8"),
                            ("iso-8859-6", "iso-8859-6"),
                            ("windows-1256", "windows-1256"),
                            ("iso-8859-4", "iso-8859-4"),
                            ("windows-1257", "windows-1257"),
                            ("iso-8859-14", "iso-8859-14"),
                            ("iso-8859-2", "iso-8859-2"),
                            ("windows-1250", "windows-1250"),
                            ("gbk", "gbk"),
                            ("gb18030", "gb18030"),
                            ("big5", "big5"),
                            ("koi8-r", "koi8-r"),
                            ("koi8-u", "koi8-u"),
                            ("iso-8859-5", "iso-8859-5"),
                            ("windows-1251", "windows-1251"),
                            ("x-mac-cyrillic", "mac-cyrillic"),
                            ("iso-8859-7", "iso-8859-7"),
                            ("windows-1253", "windows-1253"),
                            ("iso-8859-8", "iso-8859-8"),
                            ("windows-1255", "windows-1255"),
                            ("euc-jp", "euc-jp"),
                            ("iso-2022-jp", "iso-2022-jp"),
                            ("shift-jis", "shift-jis"),
                            ("euc-kr", "euc-kr"),
                            ("macintosh", "macintosh"),
                            ("iso-8859-10", "iso-8859-10"),
                            ("iso-8859-16", "iso-8859-16"),
                            ("windows-874", "cp874"),
                            ("windows-1254", "windows-1254"),
                            ("windows-1258", "windows-1258"),
                            ("iso-8859-1", "iso-8859-1"),
                            ("windows-1252", "windows-1252"),
                            ("iso-8859-3", "iso-8859-3"),
                        ],
                        default="utf-8",
                        help_text="The character set to use when creating the export file.",
                        max_length=32,
                    ),
                ),
                (
                    "csv_column_separator",
                    models.CharField(
                        choices=[
                            (",", ","),
                            (";", ";"),
                            ("|", "|"),
                            ("tab", "\t"),
                            ("record_separator", "\x1e"),
                            ("unit_separator", "\x1f"),
                        ],
                        default=",",
                        help_text="The value used to separate columns in the resulting csv file.",
                        max_length=32,
                    ),
                ),
                (
                    "csv_first_row_header",
                    models.BooleanField(
                        default=True,
                        help_text="Whether or not to generate a header row at the top of the csv file.",
                    ),
                ),
                (
                    "filter_user_id",
                    models.PositiveIntegerField(
                        help_text="Optional: The user to filter the audit log by.",
                        null=True,
                    ),
                ),
                (
                    "filter_group_id",
                    models.PositiveIntegerField(
                        help_text="Optional: The group to filter the audit log by.",
                        null=True,
                    ),
                ),
                (
                    "filter_action_type",
                    models.CharField(
                        help_text="Optional: The event type to filter the audit log by.",
                        max_length=32,
                        null=True,
                    ),
                ),
                (
                    "filter_from_timestamp",
                    models.DateTimeField(
                        help_text="Optional: The start datetime to filter the audit log by.",
                        null=True,
                    ),
                ),
                (
                    "filter_to_timestamp",
                    models.DateTimeField(
                        help_text="Optional: The end datetime to filter the audit log by.",
                        null=True,
                    ),
                ),
                (
                    "exported_file_name",
                    models.TextField(
                        help_text="The CSV file containing the filtered audit log entries.",
                        null=True,
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
            bases=("core.job",),
        ),
        migrations.AddIndex(
            model_name="auditlogentry",
            index=models.Index(
                fields=["-action_timestamp", "user_id", "group_id", "action_type"],
                name="baserow_ent_action__8db5d6_idx",
            ),
        ),
    ]
