flows: change setup_stage to configure_stage in migration
This commit is contained in:
parent
397892b282
commit
8fa83a8d08
|
@ -1,18 +1,44 @@
|
||||||
# Generated by Django 3.1.1 on 2020-09-24 16:05
|
# 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 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):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('passbook_flows', '0012_auto_20200908_1542'),
|
("passbook_flows", "0012_auto_20200908_1542"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='flow',
|
model_name="flow",
|
||||||
name='designation',
|
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),
|
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),
|
||||||
]
|
]
|
||||||
|
|
|
@ -73,29 +73,6 @@ class Stage(SerializerModel):
|
||||||
return f"Stage {self.name}"
|
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:
|
def in_memory_stage(view: Type["StageView"]) -> Stage:
|
||||||
"""Creates an in-memory stage instance, based on a `_type` as view."""
|
"""Creates an in-memory stage instance, based on a `_type` as view."""
|
||||||
stage = Stage()
|
stage = Stage()
|
||||||
|
@ -202,3 +179,26 @@ class FlowStageBinding(SerializerModel, PolicyBindingModel):
|
||||||
verbose_name = _("Flow Stage Binding")
|
verbose_name = _("Flow Stage Binding")
|
||||||
verbose_name_plural = _("Flow Stage Bindings")
|
verbose_name_plural = _("Flow Stage Bindings")
|
||||||
unique_together = (("target", "stage", "order"),)
|
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
|
||||||
|
|
Reference in New Issue