From dec34bc948f3e63f27a49d292f61cbf4e2ff70b5 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 24 Aug 2021 14:56:26 +0200 Subject: [PATCH] stages/password: fix replace_inbuilt not being called Signed-off-by: Jens Langhammer --- .../password/migrations/0007_app_password.py | 13 -------- .../migrations/0008_replace_inbuilt.py | 31 +++++++++++++++++++ 2 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 authentik/stages/password/migrations/0008_replace_inbuilt.py diff --git a/authentik/stages/password/migrations/0007_app_password.py b/authentik/stages/password/migrations/0007_app_password.py index 50c42488e..fbff951b3 100644 --- a/authentik/stages/password/migrations/0007_app_password.py +++ b/authentik/stages/password/migrations/0007_app_password.py @@ -19,19 +19,6 @@ def update_default_backends(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) stage.save() -def replace_inbuilt(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): - PasswordStage = apps.get_model("authentik_stages_password", "passwordstage") - db_alias = schema_editor.connection.alias - - for stage in PasswordStage.objects.using(db_alias).all(): - if "django.contrib.auth.backends.ModelBackend" not in stage.backends: - continue - stage.backends.remove("django.contrib.auth.backends.ModelBackend") - stage.backends.append(BACKEND_INBUILT) - stage.backends.sort() - stage.save() - - class Migration(migrations.Migration): dependencies = [ diff --git a/authentik/stages/password/migrations/0008_replace_inbuilt.py b/authentik/stages/password/migrations/0008_replace_inbuilt.py new file mode 100644 index 000000000..4c8327e7c --- /dev/null +++ b/authentik/stages/password/migrations/0008_replace_inbuilt.py @@ -0,0 +1,31 @@ +# Generated by Django 3.2.6 on 2021-08-23 14:34 +import django.contrib.postgres.fields +from django.apps.registry import Apps +from django.db import migrations, models +from django.db.backends.base.schema import BaseDatabaseSchemaEditor + +from authentik.stages.password import BACKEND_INBUILT + + +def replace_inbuilt(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): + PasswordStage = apps.get_model("authentik_stages_password", "passwordstage") + db_alias = schema_editor.connection.alias + + for stage in PasswordStage.objects.using(db_alias).all(): + if "django.contrib.auth.backends.ModelBackend" not in stage.backends: + continue + stage.backends.remove("django.contrib.auth.backends.ModelBackend") + stage.backends.append(BACKEND_INBUILT) + stage.backends.sort() + stage.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ("authentik_stages_password", "0007_app_password"), + ] + + operations = [ + migrations.RunPython(replace_inbuilt), + ]