stages/consent: cleanup

This commit is contained in:
Jens Langhammer 2020-09-24 20:06:37 +02:00
parent 7be50c2574
commit 397892b282
6 changed files with 38 additions and 11 deletions

View file

@ -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."
)
),
)

View file

@ -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/<uuid:stage_uuid>/", ConfigureFlowInitView.as_view(), name="configure"),
path(
"-/configure/<uuid:stage_uuid>/",
ConfigureFlowInitView.as_view(),
name="configure",
),
path("b/<slug:flow_slug>/", FlowExecutorView.as_view(), name="flow-executor"),
path(
"<slug:flow_slug>/", FlowExecutorShellView.as_view(), name="flow-executor-shell"

View file

@ -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:

View file

@ -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
),
),
]

View file

@ -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):

View file

@ -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}