stages/consent: cleanup
This commit is contained in:
parent
7be50c2574
commit
397892b282
|
@ -79,14 +79,14 @@ class ConfigurableStage(models.Model):
|
||||||
migration."""
|
migration."""
|
||||||
|
|
||||||
configure_flow = models.ForeignKey(
|
configure_flow = models.ForeignKey(
|
||||||
'passbook_flows.Flow',
|
"passbook_flows.Flow",
|
||||||
on_delete=models.SET_NULL,
|
on_delete=models.SET_NULL,
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
help_text=_(
|
help_text=_(
|
||||||
(
|
(
|
||||||
"Flow used by an authenticated user to change their password. "
|
"Flow used by an authenticated user to configure this Stage. "
|
||||||
"If empty, user will be unable to change their password."
|
"If empty, user will not be able to configure this stage."
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,7 +3,8 @@ from django.urls import path
|
||||||
|
|
||||||
from passbook.flows.models import FlowDesignation
|
from passbook.flows.models import FlowDesignation
|
||||||
from passbook.flows.views import (
|
from passbook.flows.views import (
|
||||||
CancelView, ConfigureFlowInitView,
|
CancelView,
|
||||||
|
ConfigureFlowInitView,
|
||||||
FlowExecutorShellView,
|
FlowExecutorShellView,
|
||||||
FlowExecutorView,
|
FlowExecutorView,
|
||||||
ToDefaultFlow,
|
ToDefaultFlow,
|
||||||
|
@ -36,7 +37,11 @@ urlpatterns = [
|
||||||
name="default-unenrollment",
|
name="default-unenrollment",
|
||||||
),
|
),
|
||||||
path("-/cancel/", CancelView.as_view(), name="cancel"),
|
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("b/<slug:flow_slug>/", FlowExecutorView.as_view(), name="flow-executor"),
|
||||||
path(
|
path(
|
||||||
"<slug:flow_slug>/", FlowExecutorShellView.as_view(), name="flow-executor-shell"
|
"<slug:flow_slug>/", FlowExecutorShellView.as_view(), name="flow-executor-shell"
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
"""passbook multi-stage authentication engine"""
|
"""passbook multi-stage authentication engine"""
|
||||||
from traceback import format_tb
|
from traceback import format_tb
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
||||||
|
|
||||||
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.http import (
|
from django.http import (
|
||||||
Http404,
|
Http404,
|
||||||
HttpRequest,
|
HttpRequest,
|
||||||
|
@ -21,7 +21,7 @@ from passbook.audit.models import cleanse_dict
|
||||||
from passbook.core.models import PASSBOOK_USER_DEBUG
|
from passbook.core.models import PASSBOOK_USER_DEBUG
|
||||||
from passbook.flows.exceptions import EmptyFlowException, FlowNonApplicableException
|
from passbook.flows.exceptions import EmptyFlowException, FlowNonApplicableException
|
||||||
from passbook.flows.models import ConfigurableStage, Flow, FlowDesignation, Stage
|
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.reflection import class_to_path
|
||||||
from passbook.lib.utils.urls import is_url_absolute, redirect_with_qs
|
from passbook.lib.utils.urls import is_url_absolute, redirect_with_qs
|
||||||
from passbook.policies.http import AccessDeniedResponse
|
from passbook.policies.http import AccessDeniedResponse
|
||||||
|
@ -309,7 +309,7 @@ class ConfigureFlowInitView(LoginRequiredMixin, View):
|
||||||
stage: Stage = Stage.objects.get_subclass(pk=stage_uuid)
|
stage: Stage = Stage.objects.get_subclass(pk=stage_uuid)
|
||||||
except Stage.DoesNotExist as exc:
|
except Stage.DoesNotExist as exc:
|
||||||
raise Http404 from exc
|
raise Http404 from exc
|
||||||
if not issubclass(stage, ConfigurableStage):
|
if not isinstance(stage, ConfigurableStage):
|
||||||
LOGGER.debug("Stage does not inherit ConfigurableStage", stage=stage)
|
LOGGER.debug("Stage does not inherit ConfigurableStage", stage=stage)
|
||||||
raise Http404
|
raise Http404
|
||||||
if not stage.configure_flow:
|
if not stage.configure_flow:
|
||||||
|
|
|
@ -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
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -66,8 +66,7 @@ class ConsentStage(Stage):
|
||||||
class UserConsent(ExpiringModel):
|
class UserConsent(ExpiringModel):
|
||||||
"""Consent given by a user for an application"""
|
"""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)
|
||||||
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="pb_consent")
|
|
||||||
application = models.ForeignKey(Application, on_delete=models.CASCADE)
|
application = models.ForeignKey(Application, on_delete=models.CASCADE)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -50,7 +50,7 @@ class PasswordStage(ConfigurableStage, Stage):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ui_user_settings(self) -> Optional[UIUserSettings]:
|
def ui_user_settings(self) -> Optional[UIUserSettings]:
|
||||||
if not self.change_flow:
|
if not self.configure_flow:
|
||||||
return None
|
return None
|
||||||
base_url = reverse(
|
base_url = reverse(
|
||||||
"passbook_flows:configure", kwargs={"stage_uuid": self.pk}
|
"passbook_flows:configure", kwargs={"stage_uuid": self.pk}
|
||||||
|
|
Reference in New Issue