diff --git a/Makefile b/Makefile index d143b9339..ef962bec0 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ lint-fix: lint: pyright bandit -r . - pylint passbook + pylint passbook e2e lifecycle prospector gen: coverage diff --git a/passbook/stages/otp_static/migrations/0002_otpstaticstage_configure_flow.py b/passbook/stages/otp_static/migrations/0002_otpstaticstage_configure_flow.py index bcd664b5e..60d9b0e71 100644 --- a/passbook/stages/otp_static/migrations/0002_otpstaticstage_configure_flow.py +++ b/passbook/stages/otp_static/migrations/0002_otpstaticstage_configure_flow.py @@ -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), ] diff --git a/passbook/stages/otp_static/migrations/0003_auto_20200925_1432.py b/passbook/stages/otp_static/migrations/0003_auto_20200925_1432.py new file mode 100644 index 000000000..fa2e1f129 --- /dev/null +++ b/passbook/stages/otp_static/migrations/0003_auto_20200925_1432.py @@ -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), + ] diff --git a/passbook/stages/otp_time/migrations/0003_otptimestage_configure_flow.py b/passbook/stages/otp_time/migrations/0003_otptimestage_configure_flow.py index 7182ea157..e26e37a5b 100644 --- a/passbook/stages/otp_time/migrations/0003_otptimestage_configure_flow.py +++ b/passbook/stages/otp_time/migrations/0003_otptimestage_configure_flow.py @@ -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} ) diff --git a/passbook/stages/password/migrations/0002_passwordstage_change_flow.py b/passbook/stages/password/migrations/0002_passwordstage_change_flow.py index 670d8910f..d946e8e51 100644 --- a/passbook/stages/password/migrations/0002_passwordstage_change_flow.py +++ b/passbook/stages/password/migrations/0002_passwordstage_change_flow.py @@ -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") diff --git a/passbook/stages/password/migrations/0004_auto_20200924_1605.py b/passbook/stages/password/migrations/0004_auto_20200924_1605.py deleted file mode 100644 index 885d062a8..000000000 --- a/passbook/stages/password/migrations/0004_auto_20200924_1605.py +++ /dev/null @@ -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', - ), - ] diff --git a/passbook/stages/password/migrations/0004_auto_20200925_1057.py b/passbook/stages/password/migrations/0004_auto_20200925_1057.py new file mode 100644 index 000000000..3928bd169 --- /dev/null +++ b/passbook/stages/password/migrations/0004_auto_20200925_1057.py @@ -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", + ), + ), + ] diff --git a/passbook/stages/password/models.py b/passbook/stages/password/models.py index 0d4b2a1fe..51bf20215 100644 --- a/passbook/stages/password/models.py +++ b/passbook/stages/password/models.py @@ -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}") diff --git a/passbook/stages/password/views.py b/passbook/stages/password/views.py deleted file mode 100644 index 1a54de1ae..000000000 --- a/passbook/stages/password/views.py +++ /dev/null @@ -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 -