stages/password: update to use ConfigurableStage
This commit is contained in:
parent
3d4c5b8f4e
commit
dc57f433fd
2
Makefile
2
Makefile
|
@ -13,7 +13,7 @@ lint-fix:
|
|||
lint:
|
||||
pyright
|
||||
bandit -r .
|
||||
pylint passbook
|
||||
pylint passbook e2e lifecycle
|
||||
prospector
|
||||
|
||||
gen: coverage
|
||||
|
|
|
@ -1,32 +1,7 @@
|
|||
# Generated by Django 3.1.1 on 2020-09-24 20:51
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.apps.registry import Apps
|
||||
from django.db import migrations, models
|
||||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
||||
|
||||
|
||||
def create_default_setup_flow(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
||||
Flow = apps.get_model("passbook_flows", "Flow")
|
||||
FlowStageBinding = apps.get_model("passbook_flows", "FlowStageBinding")
|
||||
|
||||
OTPStaticStage = apps.get_model("passbook_stages_otp_static", "OTPStaticStage")
|
||||
|
||||
db_alias = schema_editor.connection.alias
|
||||
|
||||
flow, _ = Flow.objects.using(db_alias).update_or_create(
|
||||
slug="default-otp-static-configure",
|
||||
designation=FlowDesignation.STAGE_SETUP,
|
||||
defaults={"name": "Setup Static OTP Tokens"},
|
||||
)
|
||||
|
||||
stage = OTPStaticStage.objects.using(db_alias).update_or_create(
|
||||
name="default-otp-static-configure"
|
||||
)
|
||||
|
||||
FlowStageBinding.objects.using(db_alias).update_or_create(
|
||||
target=flow, stage=stage, defaults={"order": 0}
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
@ -48,5 +23,4 @@ class Migration(migrations.Migration):
|
|||
to="passbook_flows.flow",
|
||||
),
|
||||
),
|
||||
migrations.RunPython(create_default_setup_flow),
|
||||
]
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
# Generated by Django 3.1.1 on 2020-09-25 14:32
|
||||
|
||||
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_setup_flow(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
||||
Flow = apps.get_model("passbook_flows", "Flow")
|
||||
FlowStageBinding = apps.get_model("passbook_flows", "FlowStageBinding")
|
||||
|
||||
OTPStaticStage = apps.get_model("passbook_stages_otp_static", "OTPStaticStage")
|
||||
|
||||
db_alias = schema_editor.connection.alias
|
||||
|
||||
flow, _ = Flow.objects.using(db_alias).update_or_create(
|
||||
slug="default-otp-static-configure",
|
||||
designation=FlowDesignation.STAGE_CONFIGURATION,
|
||||
defaults={"name": "Setup Static OTP Tokens"},
|
||||
)
|
||||
|
||||
stage, _ = OTPStaticStage.objects.using(db_alias).update_or_create(
|
||||
name="default-otp-static-configure", defaults={"token_count": 6}
|
||||
)
|
||||
|
||||
FlowStageBinding.objects.using(db_alias).update_or_create(
|
||||
target=flow, stage=stage, defaults={"order": 0}
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("passbook_stages_otp_static", "0002_otpstaticstage_configure_flow"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(create_default_setup_flow),
|
||||
]
|
|
@ -5,6 +5,7 @@ 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
|
||||
from passbook.stages.otp_time.models import TOTPDigits
|
||||
|
||||
|
||||
|
@ -18,11 +19,11 @@ def create_default_setup_flow(apps: Apps, schema_editor: BaseDatabaseSchemaEdito
|
|||
|
||||
flow, _ = Flow.objects.using(db_alias).update_or_create(
|
||||
slug="default-otp-time-configure",
|
||||
designation=FlowDesignation.STAGE_SETUP,
|
||||
designation=FlowDesignation.STAGE_CONFIGURATION,
|
||||
defaults={"name": "Setup Two-Factor authentication"},
|
||||
)
|
||||
|
||||
stage = OTPTimeStage.objects.using(db_alias).update_or_create(
|
||||
stage, _ = OTPTimeStage.objects.using(db_alias).update_or_create(
|
||||
name="default-otp-time-configure", defaults={"digits": TOTPDigits.SIX}
|
||||
)
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ def create_default_password_change(apps: Apps, schema_editor: BaseDatabaseSchema
|
|||
|
||||
flow, _ = Flow.objects.using(db_alias).update_or_create(
|
||||
slug="default-password-change",
|
||||
designation=FlowDesignation.STAGE_SETUP,
|
||||
designation=FlowDesignation.STAGE_CONFIGURATION,
|
||||
defaults={"name": "Change Password"},
|
||||
)
|
||||
|
||||
|
@ -71,7 +71,7 @@ def update_default_stage_change(apps: Apps, schema_editor: BaseDatabaseSchemaEdi
|
|||
Flow = apps.get_model("passbook_flows", "Flow")
|
||||
|
||||
flow = Flow.objects.get(
|
||||
slug="default-password-change", designation=FlowDesignation.STAGE_SETUP,
|
||||
slug="default-password-change", designation=FlowDesignation.STAGE_CONFIGURATION,
|
||||
)
|
||||
|
||||
stages = PasswordStage.objects.filter(name="default-authentication-password")
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
# Generated by Django 3.1.1 on 2020-09-24 16:05
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('passbook_stages_password', '0003_passwordstage_failed_attempts_before_cancel'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='passwordstage',
|
||||
old_name='change_flow',
|
||||
new_name='configure_flow',
|
||||
),
|
||||
]
|
|
@ -0,0 +1,30 @@
|
|||
# Generated by Django 3.1.1 on 2020-09-25 10:57
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("passbook_flows", "0013_auto_20200924_1605"),
|
||||
(
|
||||
"passbook_stages_password",
|
||||
"0003_passwordstage_failed_attempts_before_cancel",
|
||||
),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(model_name="passwordstage", name="change_flow",),
|
||||
migrations.AddField(
|
||||
model_name="passwordstage",
|
||||
name="configure_flow",
|
||||
field=models.ForeignKey(
|
||||
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.",
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
to="passbook_flows.flow",
|
||||
),
|
||||
),
|
||||
]
|
|
@ -52,9 +52,7 @@ class PasswordStage(ConfigurableStage, Stage):
|
|||
def ui_user_settings(self) -> Optional[UIUserSettings]:
|
||||
if not self.configure_flow:
|
||||
return None
|
||||
base_url = reverse(
|
||||
"passbook_flows:configure", kwargs={"stage_uuid": self.pk}
|
||||
)
|
||||
base_url = reverse("passbook_flows:configure", kwargs={"stage_uuid": self.pk})
|
||||
args = urlencode({NEXT_ARG_NAME: reverse("passbook_core:user-settings")})
|
||||
return UIUserSettings(name=_("Change password"), url=f"{base_url}?{args}")
|
||||
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
"""password stage views"""
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.http import Http404, HttpRequest, HttpResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.views import View
|
||||
|
||||
from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER, FlowPlanner
|
||||
from passbook.flows.views import SESSION_KEY_PLAN
|
||||
from passbook.lib.utils.urls import redirect_with_qs
|
||||
from passbook.stages.password.models import PasswordStage
|
||||
|
Reference in New Issue