From 397892b2826c55e7491bb35dea61822019fbc2b1 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 24 Sep 2020 20:06:37 +0200 Subject: [PATCH] stages/consent: cleanup --- passbook/flows/models.py | 6 ++--- passbook/flows/urls.py | 9 ++++++-- passbook/flows/views.py | 6 ++--- .../migrations/0003_auto_20200924_1403.py | 23 +++++++++++++++++++ passbook/stages/consent/models.py | 3 +-- passbook/stages/password/models.py | 2 +- 6 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 passbook/stages/consent/migrations/0003_auto_20200924_1403.py diff --git a/passbook/flows/models.py b/passbook/flows/models.py index c508201d2..26675d8c5 100644 --- a/passbook/flows/models.py +++ b/passbook/flows/models.py @@ -79,14 +79,14 @@ class ConfigurableStage(models.Model): migration.""" configure_flow = models.ForeignKey( - 'passbook_flows.Flow', + "passbook_flows.Flow", on_delete=models.SET_NULL, null=True, blank=True, help_text=_( ( - "Flow used by an authenticated user to change their password. " - "If empty, user will be unable to change their password." + "Flow used by an authenticated user to configure this Stage. " + "If empty, user will not be able to configure this stage." ) ), ) diff --git a/passbook/flows/urls.py b/passbook/flows/urls.py index 4473e201c..5db88dd74 100644 --- a/passbook/flows/urls.py +++ b/passbook/flows/urls.py @@ -3,7 +3,8 @@ from django.urls import path from passbook.flows.models import FlowDesignation from passbook.flows.views import ( - CancelView, ConfigureFlowInitView, + CancelView, + ConfigureFlowInitView, FlowExecutorShellView, FlowExecutorView, ToDefaultFlow, @@ -36,7 +37,11 @@ urlpatterns = [ name="default-unenrollment", ), path("-/cancel/", CancelView.as_view(), name="cancel"), - path("-/configure//", ConfigureFlowInitView.as_view(), name="configure"), + path( + "-/configure//", + ConfigureFlowInitView.as_view(), + name="configure", + ), path("b//", FlowExecutorView.as_view(), name="flow-executor"), path( "/", FlowExecutorShellView.as_view(), name="flow-executor-shell" diff --git a/passbook/flows/views.py b/passbook/flows/views.py index 2573c4f4f..c666b3383 100644 --- a/passbook/flows/views.py +++ b/passbook/flows/views.py @@ -1,8 +1,8 @@ """passbook multi-stage authentication engine""" from traceback import format_tb from typing import Any, Dict, Optional -from django.contrib.auth.mixins import LoginRequiredMixin +from django.contrib.auth.mixins import LoginRequiredMixin from django.http import ( Http404, HttpRequest, @@ -21,7 +21,7 @@ from passbook.audit.models import cleanse_dict from passbook.core.models import PASSBOOK_USER_DEBUG from passbook.flows.exceptions import EmptyFlowException, FlowNonApplicableException from passbook.flows.models import ConfigurableStage, Flow, FlowDesignation, Stage -from passbook.flows.planner import FlowPlan, FlowPlanner, PLAN_CONTEXT_PENDING_USER +from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER, FlowPlan, FlowPlanner from passbook.lib.utils.reflection import class_to_path from passbook.lib.utils.urls import is_url_absolute, redirect_with_qs from passbook.policies.http import AccessDeniedResponse @@ -309,7 +309,7 @@ class ConfigureFlowInitView(LoginRequiredMixin, View): stage: Stage = Stage.objects.get_subclass(pk=stage_uuid) except Stage.DoesNotExist as exc: raise Http404 from exc - if not issubclass(stage, ConfigurableStage): + if not isinstance(stage, ConfigurableStage): LOGGER.debug("Stage does not inherit ConfigurableStage", stage=stage) raise Http404 if not stage.configure_flow: diff --git a/passbook/stages/consent/migrations/0003_auto_20200924_1403.py b/passbook/stages/consent/migrations/0003_auto_20200924_1403.py new file mode 100644 index 000000000..6ce477a7e --- /dev/null +++ b/passbook/stages/consent/migrations/0003_auto_20200924_1403.py @@ -0,0 +1,23 @@ +# Generated by Django 3.1.1 on 2020-09-24 14:03 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ("passbook_stages_consent", "0002_auto_20200720_0941"), + ] + + operations = [ + migrations.AlterField( + model_name="userconsent", + name="user", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL + ), + ), + ] diff --git a/passbook/stages/consent/models.py b/passbook/stages/consent/models.py index 21a3e6780..c8ef52f78 100644 --- a/passbook/stages/consent/models.py +++ b/passbook/stages/consent/models.py @@ -66,8 +66,7 @@ class ConsentStage(Stage): class UserConsent(ExpiringModel): """Consent given by a user for an application""" - # TODO: Remove related_name when oidc provider is v2 - user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="pb_consent") + user = models.ForeignKey(User, on_delete=models.CASCADE) application = models.ForeignKey(Application, on_delete=models.CASCADE) def __str__(self): diff --git a/passbook/stages/password/models.py b/passbook/stages/password/models.py index d7621608c..0d4b2a1fe 100644 --- a/passbook/stages/password/models.py +++ b/passbook/stages/password/models.py @@ -50,7 +50,7 @@ class PasswordStage(ConfigurableStage, Stage): @property def ui_user_settings(self) -> Optional[UIUserSettings]: - if not self.change_flow: + if not self.configure_flow: return None base_url = reverse( "passbook_flows:configure", kwargs={"stage_uuid": self.pk}