From ea1564548c7270ebeab91a168039c3f6c9cc0d5d Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 26 Sep 2020 20:43:41 +0200 Subject: [PATCH] stages/consent: support pending_user from flow --- passbook/stages/consent/stage.py | 12 +++++++++--- passbook/stages/otp_static/views.py | 1 - passbook/stages/otp_time/views.py | 1 - 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/passbook/stages/consent/stage.py b/passbook/stages/consent/stage.py index 58894c15a..d12955852 100644 --- a/passbook/stages/consent/stage.py +++ b/passbook/stages/consent/stage.py @@ -5,7 +5,7 @@ from django.http import HttpRequest, HttpResponse from django.utils.timezone import now from django.views.generic import FormView -from passbook.flows.planner import PLAN_CONTEXT_APPLICATION +from passbook.flows.planner import PLAN_CONTEXT_APPLICATION, PLAN_CONTEXT_PENDING_USER from passbook.flows.stage import StageView from passbook.lib.utils.time import timedelta_from_string from passbook.stages.consent.forms import ConsentForm @@ -26,6 +26,8 @@ class ConsentStageView(FormView, StageView): return kwargs def get_template_names(self) -> List[str]: + # PLAN_CONTEXT_CONSENT_TEMPLATE has to be set by a template that calls this stage + # TODO: Add a default template in case a user directly implements this stage if PLAN_CONTEXT_CONSENT_TEMPLATE in self.executor.plan.context: template_name = self.executor.plan.context[PLAN_CONTEXT_CONSENT_TEMPLATE] return [template_name] @@ -42,9 +44,13 @@ class ConsentStageView(FormView, StageView): return super().get(request, *args, **kwargs) application = self.executor.plan.context[PLAN_CONTEXT_APPLICATION] - # TODO: Check for user in plan? + + user = self.request.user + if PLAN_CONTEXT_PENDING_USER in self.executor.plan.context: + user = self.executor.plan.context[PLAN_CONTEXT_PENDING_USER] + if UserConsent.filter_not_expired( - user=self.request.user, application=application + user=user, application=application ).exists(): return self.executor.stage_ok() diff --git a/passbook/stages/otp_static/views.py b/passbook/stages/otp_static/views.py index 9957bfa41..8b95e45de 100644 --- a/passbook/stages/otp_static/views.py +++ b/passbook/stages/otp_static/views.py @@ -16,7 +16,6 @@ class UserSettingsView(LoginRequiredMixin, TemplateView): template_name = "stages/otp_static/user_settings.html" - # TODO: Check if OTP Stage exists and applies to user def get_context_data(self, **kwargs): kwargs = super().get_context_data(**kwargs) stage = get_object_or_404(OTPStaticStage, pk=self.kwargs["stage_uuid"]) diff --git a/passbook/stages/otp_time/views.py b/passbook/stages/otp_time/views.py index dcf4b990d..2b5cbba9a 100644 --- a/passbook/stages/otp_time/views.py +++ b/passbook/stages/otp_time/views.py @@ -16,7 +16,6 @@ class UserSettingsView(LoginRequiredMixin, TemplateView): template_name = "stages/otp_time/user_settings.html" - # TODO: Check if OTP Stage exists and applies to user def get_context_data(self, **kwargs): kwargs = super().get_context_data(**kwargs) stage = get_object_or_404(OTPTimeStage, pk=self.kwargs["stage_uuid"])