From 5184c4b7ef2419d7e874a783aef1382ffa2a5760 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 14 Sep 2020 18:40:26 +0200 Subject: [PATCH] flows: fix FlowNonApplicableException and EmptyFlowException leading to infinite spinners --- passbook/core/templates/error/embedded.html | 25 +++++++++++++++++++++ passbook/flows/exceptions.py | 4 ++-- passbook/flows/views.py | 5 ++++- passbook/lib/views.py | 10 ++++----- 4 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 passbook/core/templates/error/embedded.html diff --git a/passbook/core/templates/error/embedded.html b/passbook/core/templates/error/embedded.html new file mode 100644 index 000000000..ddd0986e8 --- /dev/null +++ b/passbook/core/templates/error/embedded.html @@ -0,0 +1,25 @@ +{# Template used by bad_request_message within flows #} +{% extends 'login/base.html' %} + +{% load static %} +{% load i18n %} +{% load passbook_utils %} + +{% block title %} +{% trans card_title %} +{% endblock %} + +{% block card_title %} +{% trans card_title %} +{% endblock %} + +{% block card %} +
+ {% if message %} +

{% trans message %}

+ {% endif %} + {% if 'back' in request.GET %} + {% trans 'Back' %} + {% endif %} +
+{% endblock %} diff --git a/passbook/flows/exceptions.py b/passbook/flows/exceptions.py index 4bcf6f854..47072264c 100644 --- a/passbook/flows/exceptions.py +++ b/passbook/flows/exceptions.py @@ -2,8 +2,8 @@ class FlowNonApplicableException(BaseException): - """Exception raised when a Flow does not apply to a user.""" + """Flow does not apply to current user (denied by policy).""" class EmptyFlowException(BaseException): - """Exception raised when a Flow Plan is empty""" + """Flow has no stages.""" diff --git a/passbook/flows/views.py b/passbook/flows/views.py index 5553291c3..75769a267 100644 --- a/passbook/flows/views.py +++ b/passbook/flows/views.py @@ -54,7 +54,10 @@ class FlowExecutorView(View): LOGGER.debug("f(exec): Redirecting to next on fail") return redirect(self.request.GET.get(NEXT_ARG_NAME)) message = exc.__doc__ if exc.__doc__ else str(exc) - return bad_request_message(self.request, message) + return to_stage_response( + self.request, + bad_request_message(self.request, message, template="error/embedded.html"), + ) def dispatch(self, request: HttpRequest, flow_slug: str) -> HttpResponse: # Early check if theres an active Plan for the current session diff --git a/passbook/lib/views.py b/passbook/lib/views.py index a82ec9e84..2fe5281e2 100644 --- a/passbook/lib/views.py +++ b/passbook/lib/views.py @@ -27,12 +27,12 @@ class CreateAssignPermView(CreateView): def bad_request_message( - request: HttpRequest, message: str, title="Bad Request" + request: HttpRequest, + message: str, + title="Bad Request", + template="error/generic.html", ) -> TemplateResponse: """Return generic error page with message, with status code set to 400""" return TemplateResponse( - request, - "error/generic.html", - {"message": message, "card_title": _(title)}, - status=400, + request, template, {"message": message, "card_title": _(title)}, status=400, )