diff --git a/passbook/flows/migrations/0011_flow_title.py b/passbook/flows/migrations/0011_flow_title.py index dfb20804b..c9b4c181a 100644 --- a/passbook/flows/migrations/0011_flow_title.py +++ b/passbook/flows/migrations/0011_flow_title.py @@ -1,6 +1,27 @@ # Generated by Django 3.1 on 2020-08-28 13:14 - +from django.apps.registry import Apps from django.db import migrations, models +from django.db.backends.base.schema import BaseDatabaseSchemaEditor + + +def add_title_for_defaults(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): + slug_title_map = { + "default-authentication-flow": "Default Authentication Flow", + "default-invalidation-flow": "Default Invalidation Flow", + "default-source-enrollment": "Default Source Enrollment Flow", + "default-source-authentication": "Default Source Authentication Flow", + "default-provider-authorization-implicit-consent": "Default Provider Authorization Flow (implicit consent)", + "default-provider-authorization-explicit-consent": "Default Provider Authorization Flow (explicit consent)", + "default-password-change": "Default Password Change Flow", + } + db_alias = schema_editor.connection.alias + Flow = apps.get_model("passbook_flows", "Flow") + for flow in Flow.objects.using(db_alias).all(): + if flow.slug in slug_title_map: + flow.title = slug_title_map[flow.slug] + else: + flow.title = flow.name + flow.save() class Migration(migrations.Migration): @@ -24,4 +45,8 @@ class Migration(migrations.Migration): field=models.TextField(default="", blank=True), preserve_default=False, ), + migrations.RunPython(add_title_for_defaults), + migrations.AlterField( + model_name="flow", name="title", field=models.TextField(), + ), ]