From d33f632203b98c09c8dcf3c2cd0ca86339878515 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 30 Jun 2020 00:11:01 +0200 Subject: [PATCH] flows: add CancelView to cancel current flow execution --- .../core/templates/login/form_with_user.html | 2 +- passbook/flows/urls.py | 2 + passbook/flows/views.py | 37 ++++++++++++------- .../templates/oidc_provider/authorize.html | 2 +- .../templates/stages/password/backend.html | 2 +- 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/passbook/core/templates/login/form_with_user.html b/passbook/core/templates/login/form_with_user.html index a7c2461fe..bed72f78c 100644 --- a/passbook/core/templates/login/form_with_user.html +++ b/passbook/core/templates/login/form_with_user.html @@ -14,7 +14,7 @@ {{ user.username }}
- {% trans 'Not you?' %} + {% trans 'Not you?' %}
diff --git a/passbook/flows/urls.py b/passbook/flows/urls.py index ca83335f7..26b0ebb59 100644 --- a/passbook/flows/urls.py +++ b/passbook/flows/urls.py @@ -3,6 +3,7 @@ from django.urls import path from passbook.flows.models import FlowDesignation from passbook.flows.views import ( + CancelView, FlowExecutorShellView, FlowExecutorView, FlowPermissionDeniedView, @@ -36,6 +37,7 @@ urlpatterns = [ ToDefaultFlow.as_view(designation=FlowDesignation.UNRENOLLMENT), name="default-unenrollment", ), + path("-/cancel/", CancelView.as_view(), name="cancel"), 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 c78f1aa38..bbe010392 100644 --- a/passbook/flows/views.py +++ b/passbook/flows/views.py @@ -183,6 +183,30 @@ class FlowPermissionDeniedView(PermissionDeniedView): """User could not be authenticated""" +class FlowExecutorShellView(TemplateView): + """Executor Shell view, loads a dummy card with a spinner + that loads the next stage in the background.""" + + template_name = "flows/shell.html" + + def get_context_data(self, **kwargs) -> Dict[str, Any]: + kwargs["exec_url"] = reverse("passbook_flows:flow-executor", kwargs=self.kwargs) + kwargs["msg_url"] = reverse("passbook_api:messages-list") + self.request.session[SESSION_KEY_GET] = self.request.GET + return kwargs + + +class CancelView(View): + """View which canels the currently active plan""" + + def get(self, request: HttpRequest) -> HttpResponse: + """View which canels the currently active plan""" + if SESSION_KEY_PLAN in request.session: + del request.session[SESSION_KEY_PLAN] + LOGGER.debug("Canceled current plan") + return redirect("passbook_core:overview") + + class ToDefaultFlow(View): """Redirect to default flow matching by designation""" @@ -206,19 +230,6 @@ class ToDefaultFlow(View): ) -class FlowExecutorShellView(TemplateView): - """Executor Shell view, loads a dummy card with a spinner - that loads the next stage in the background.""" - - template_name = "flows/shell.html" - - def get_context_data(self, **kwargs) -> Dict[str, Any]: - kwargs["exec_url"] = reverse("passbook_flows:flow-executor", kwargs=self.kwargs) - kwargs["msg_url"] = reverse("passbook_api:messages-list") - self.request.session[SESSION_KEY_GET] = self.request.GET - return kwargs - - def to_stage_response(request: HttpRequest, source: HttpResponse) -> HttpResponse: """Convert normal HttpResponse into JSON Response""" if isinstance(source, HttpResponseRedirect) or source.status_code == 302: diff --git a/passbook/providers/oidc/templates/oidc_provider/authorize.html b/passbook/providers/oidc/templates/oidc_provider/authorize.html index 9326ee625..aabbb262e 100644 --- a/passbook/providers/oidc/templates/oidc_provider/authorize.html +++ b/passbook/providers/oidc/templates/oidc_provider/authorize.html @@ -38,7 +38,7 @@ {% blocktrans with user=user %} You are logged in as {{ user }}. Not you? {% endblocktrans %} - {% trans 'Logout' %} + {% trans 'Logout' %}

diff --git a/passbook/stages/password/templates/stages/password/backend.html b/passbook/stages/password/templates/stages/password/backend.html index a2b3db483..74547608d 100644 --- a/passbook/stages/password/templates/stages/password/backend.html +++ b/passbook/stages/password/templates/stages/password/backend.html @@ -21,7 +21,7 @@ {{ user.username }}