flows: fix default flows not having titles
This commit is contained in:
		| @ -1,6 +1,27 @@ | |||||||
| # Generated by Django 3.1 on 2020-08-28 13:14 | # 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 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): | class Migration(migrations.Migration): | ||||||
| @ -24,4 +45,8 @@ class Migration(migrations.Migration): | |||||||
|             field=models.TextField(default="", blank=True), |             field=models.TextField(default="", blank=True), | ||||||
|             preserve_default=False, |             preserve_default=False, | ||||||
|         ), |         ), | ||||||
|  |         migrations.RunPython(add_title_for_defaults), | ||||||
|  |         migrations.AlterField( | ||||||
|  |             model_name="flow", name="title", field=models.TextField(), | ||||||
|  |         ), | ||||||
|     ] |     ] | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Jens Langhammer
					Jens Langhammer