Merge pull request #104 from BeryJu/flows-cancel
flows: add CancelView to cancel current flow execution
This commit is contained in:
commit
50a57fb3dd
|
@ -14,7 +14,7 @@
|
||||||
{{ user.username }}
|
{{ user.username }}
|
||||||
</div>
|
</div>
|
||||||
<div class="right">
|
<div class="right">
|
||||||
<a href="{% url 'passbook_flows:default-authentication' %}">{% trans 'Not you?' %}</a>
|
<a href="{% url 'passbook_flows:cancel' %}">{% trans 'Not you?' %}</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -3,6 +3,7 @@ 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,
|
||||||
FlowExecutorShellView,
|
FlowExecutorShellView,
|
||||||
FlowExecutorView,
|
FlowExecutorView,
|
||||||
FlowPermissionDeniedView,
|
FlowPermissionDeniedView,
|
||||||
|
@ -36,6 +37,7 @@ urlpatterns = [
|
||||||
ToDefaultFlow.as_view(designation=FlowDesignation.UNRENOLLMENT),
|
ToDefaultFlow.as_view(designation=FlowDesignation.UNRENOLLMENT),
|
||||||
name="default-unenrollment",
|
name="default-unenrollment",
|
||||||
),
|
),
|
||||||
|
path("-/cancel/", CancelView.as_view(), name="cancel"),
|
||||||
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"
|
||||||
|
|
|
@ -183,6 +183,30 @@ class FlowPermissionDeniedView(PermissionDeniedView):
|
||||||
"""User could not be authenticated"""
|
"""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):
|
class ToDefaultFlow(View):
|
||||||
"""Redirect to default flow matching by designation"""
|
"""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:
|
def to_stage_response(request: HttpRequest, source: HttpResponse) -> HttpResponse:
|
||||||
"""Convert normal HttpResponse into JSON Response"""
|
"""Convert normal HttpResponse into JSON Response"""
|
||||||
if isinstance(source, HttpResponseRedirect) or source.status_code == 302:
|
if isinstance(source, HttpResponseRedirect) or source.status_code == 302:
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
{% blocktrans with user=user %}
|
{% blocktrans with user=user %}
|
||||||
You are logged in as {{ user }}. Not you?
|
You are logged in as {{ user }}. Not you?
|
||||||
{% endblocktrans %}
|
{% endblocktrans %}
|
||||||
<a href="{% url 'passbook_flows:default-invalidation' %}">{% trans 'Logout' %}</a>
|
<a href="{% url 'passbook_flows:cancel' %}">{% trans 'Logout' %}</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="pf-c-form__group pf-m-action">
|
<div class="pf-c-form__group pf-m-action">
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
{{ user.username }}
|
{{ user.username }}
|
||||||
</div>
|
</div>
|
||||||
<div class="right">
|
<div class="right">
|
||||||
<a href="{% url 'passbook_flows:default-authentication' %}">{% trans 'Not you?' %}</a>
|
<a href="{% url 'passbook_flows:cancel' %}">{% trans 'Not you?' %}</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Reference in New Issue