authentik.flows.migrations.0027_auto_20231028_1424

 1# Generated by Django 4.2.6 on 2023-10-28 14:24
 2
 3from django.apps.registry import Apps
 4from django.db import migrations, models
 5from django.db.backends.base.schema import BaseDatabaseSchemaEditor
 6
 7
 8def set_oobe_flow_authentication(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
 9    from guardian.conf import settings as guardian_settings
10
11    Flow = apps.get_model("authentik_flows", "Flow")
12    User = apps.get_model("authentik_core", "User")
13
14    db_alias = schema_editor.connection.alias
15
16    users = (
17        User.objects.using(db_alias)
18        .exclude(username="akadmin")
19        .exclude(username=guardian_settings.ANONYMOUS_USER_NAME)
20    )
21    if users.exists():
22        Flow.objects.using(db_alias).filter(slug="initial-setup").update(
23            authentication="require_superuser"
24        )
25
26
27class Migration(migrations.Migration):
28    dependencies = [
29        ("authentik_flows", "0026_alter_flow_options"),
30    ]
31
32    operations = [
33        migrations.RunPython(set_oobe_flow_authentication),
34        migrations.AlterField(
35            model_name="flow",
36            name="authentication",
37            field=models.TextField(
38                choices=[
39                    ("none", "None"),
40                    ("require_authenticated", "Require Authenticated"),
41                    ("require_unauthenticated", "Require Unauthenticated"),
42                    ("require_superuser", "Require Superuser"),
43                    ("require_redirect", "Require Redirect"),
44                    ("require_outpost", "Require Outpost"),
45                ],
46                default="none",
47                help_text="Required level of authentication and authorization to access a flow.",
48            ),
49        ),
50    ]
def set_oobe_flow_authentication( apps: django.apps.registry.Apps, schema_editor: django.db.backends.base.schema.BaseDatabaseSchemaEditor):
 9def set_oobe_flow_authentication(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
10    from guardian.conf import settings as guardian_settings
11
12    Flow = apps.get_model("authentik_flows", "Flow")
13    User = apps.get_model("authentik_core", "User")
14
15    db_alias = schema_editor.connection.alias
16
17    users = (
18        User.objects.using(db_alias)
19        .exclude(username="akadmin")
20        .exclude(username=guardian_settings.ANONYMOUS_USER_NAME)
21    )
22    if users.exists():
23        Flow.objects.using(db_alias).filter(slug="initial-setup").update(
24            authentication="require_superuser"
25        )
class Migration(django.db.migrations.migration.Migration):
28class Migration(migrations.Migration):
29    dependencies = [
30        ("authentik_flows", "0026_alter_flow_options"),
31    ]
32
33    operations = [
34        migrations.RunPython(set_oobe_flow_authentication),
35        migrations.AlterField(
36            model_name="flow",
37            name="authentication",
38            field=models.TextField(
39                choices=[
40                    ("none", "None"),
41                    ("require_authenticated", "Require Authenticated"),
42                    ("require_unauthenticated", "Require Unauthenticated"),
43                    ("require_superuser", "Require Superuser"),
44                    ("require_redirect", "Require Redirect"),
45                    ("require_outpost", "Require Outpost"),
46                ],
47                default="none",
48                help_text="Required level of authentication and authorization to access a flow.",
49            ),
50        ),
51    ]

The base class for all migrations.

Migration files will import this from django.db.migrations.Migration and subclass it as a class called Migration. It will have one or more of the following attributes:

  • operations: A list of Operation instances, probably from django.db.migrations.operations
  • dependencies: A list of tuples of (app_path, migration_name)
  • run_before: A list of tuples of (app_path, migration_name)
  • replaces: A list of migration_names

Note that all migrations come out of migrations and into the Loader or Graph as instances, having been initialized with their app label and name.

dependencies = [('authentik_flows', '0026_alter_flow_options')]
operations = [<RunPython <function set_oobe_flow_authentication>>, <AlterField model_name='flow', name='authentication', field=<django.db.models.fields.TextField>>]