38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
|
# Generated by Django 3.0.3 on 2020-05-08 14:30
|
||
|
|
||
|
from django.apps.registry import Apps
|
||
|
from django.db import migrations
|
||
|
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
||
|
|
||
|
from passbook.flows.models import FlowDesignation
|
||
|
|
||
|
|
||
|
def create_default_flow(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
||
|
Flow = apps.get_model("passbook_flows", "Flow")
|
||
|
FlowFactorBinding = apps.get_model("passbook_flows", "FlowFactorBinding")
|
||
|
PasswordFactor = apps.get_model("passbook_factors_password", "PasswordFactor")
|
||
|
db_alias = schema_editor.connection.alias
|
||
|
|
||
|
if Flow.objects.using(db_alias).all().exists():
|
||
|
# Only create default flow when none exist
|
||
|
return
|
||
|
|
||
|
pw_factor = PasswordFactor.objects.using(db_alias).first()
|
||
|
flow = Flow.objects.using(db_alias).create(
|
||
|
name="default-authentication-flow",
|
||
|
slug="default-authentication-flow",
|
||
|
designation=FlowDesignation.AUTHENTICATION,
|
||
|
)
|
||
|
FlowFactorBinding.objects.using(db_alias).create(
|
||
|
flow=flow, factor=pw_factor, order=0,
|
||
|
)
|
||
|
|
||
|
|
||
|
class Migration(migrations.Migration):
|
||
|
|
||
|
dependencies = [
|
||
|
("passbook_flows", "0003_auto_20200508_1230"),
|
||
|
]
|
||
|
|
||
|
operations = [migrations.RunPython(create_default_flow)]
|