From 8fa83a8d08c9607cdba0caa7eff86558343a457a Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 25 Sep 2020 12:43:11 +0200 Subject: [PATCH] flows: change setup_stage to configure_stage in migration --- .../migrations/0013_auto_20200924_1605.py | 34 ++++++++++++-- passbook/flows/models.py | 46 +++++++++---------- 2 files changed, 53 insertions(+), 27 deletions(-) diff --git a/passbook/flows/migrations/0013_auto_20200924_1605.py b/passbook/flows/migrations/0013_auto_20200924_1605.py index 6e2ac1c55..eb3683c60 100644 --- a/passbook/flows/migrations/0013_auto_20200924_1605.py +++ b/passbook/flows/migrations/0013_auto_20200924_1605.py @@ -1,18 +1,44 @@ # Generated by Django 3.1.1 on 2020-09-24 16:05 +from django.apps.registry import Apps from django.db import migrations, models +from django.db.backends.base.schema import BaseDatabaseSchemaEditor + +from passbook.flows.models import FlowDesignation + + +def update_flow_designation(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): + Flow = apps.get_model("passbook_flows", "Flow") + db_alias = schema_editor.connection.alias + + for flow in Flow.objects.using(db_alias).all(): + if flow.designation == "stage_setup": + flow.designation = FlowDesignation.STAGE_CONFIGURATION + flow.save() class Migration(migrations.Migration): dependencies = [ - ('passbook_flows', '0012_auto_20200908_1542'), + ("passbook_flows", "0012_auto_20200908_1542"), ] operations = [ migrations.AlterField( - model_name='flow', - name='designation', - field=models.CharField(choices=[('authentication', 'Authentication'), ('authorization', 'Authorization'), ('invalidation', 'Invalidation'), ('enrollment', 'Enrollment'), ('unenrollment', 'Unrenollment'), ('recovery', 'Recovery'), ('stage_configuration', 'Stage Configuration')], max_length=100), + model_name="flow", + name="designation", + field=models.CharField( + choices=[ + ("authentication", "Authentication"), + ("authorization", "Authorization"), + ("invalidation", "Invalidation"), + ("enrollment", "Enrollment"), + ("unenrollment", "Unrenollment"), + ("recovery", "Recovery"), + ("stage_configuration", "Stage Configuration"), + ], + max_length=100, + ), ), + migrations.RunPython(update_flow_designation), ] diff --git a/passbook/flows/models.py b/passbook/flows/models.py index 26675d8c5..5bc0858d1 100644 --- a/passbook/flows/models.py +++ b/passbook/flows/models.py @@ -73,29 +73,6 @@ class Stage(SerializerModel): return f"Stage {self.name}" -class ConfigurableStage(models.Model): - """Abstract base class for a Stage that can be configured by the enduser. - The stage should create a default flow with the configure_stage designation during - migration.""" - - configure_flow = models.ForeignKey( - "passbook_flows.Flow", - on_delete=models.SET_NULL, - null=True, - blank=True, - help_text=_( - ( - "Flow used by an authenticated user to configure this Stage. " - "If empty, user will not be able to configure this stage." - ) - ), - ) - - class Meta: - - abstract = True - - def in_memory_stage(view: Type["StageView"]) -> Stage: """Creates an in-memory stage instance, based on a `_type` as view.""" stage = Stage() @@ -202,3 +179,26 @@ class FlowStageBinding(SerializerModel, PolicyBindingModel): verbose_name = _("Flow Stage Binding") verbose_name_plural = _("Flow Stage Bindings") unique_together = (("target", "stage", "order"),) + + +class ConfigurableStage(models.Model): + """Abstract base class for a Stage that can be configured by the enduser. + The stage should create a default flow with the configure_stage designation during + migration.""" + + configure_flow = models.ForeignKey( + Flow, + on_delete=models.SET_NULL, + null=True, + blank=True, + help_text=_( + ( + "Flow used by an authenticated user to configure this Stage. " + "If empty, user will not be able to configure this stage." + ) + ), + ) + + class Meta: + + abstract = True