diff --git a/passbook/admin/templates/administration/flow/list.html b/passbook/admin/templates/administration/flow/list.html index c013e9348..0956ead3f 100644 --- a/passbook/admin/templates/administration/flow/list.html +++ b/passbook/admin/templates/administration/flow/list.html @@ -61,6 +61,7 @@ {% trans 'Edit' %} {% trans 'Delete' %} + {% trans 'Execute' %} {% endfor %} diff --git a/passbook/admin/urls.py b/passbook/admin/urls.py index 56a7603a6..af7e41ec9 100644 --- a/passbook/admin/urls.py +++ b/passbook/admin/urls.py @@ -187,6 +187,11 @@ urlpatterns = [ path( "flows//update/", flows.FlowUpdateView.as_view(), name="flow-update", ), + path( + "flows//execute/", + flows.FlowDebugExecuteView.as_view(), + name="flow-execute", + ), path( "flows//delete/", flows.FlowDeleteView.as_view(), name="flow-delete", ), diff --git a/passbook/admin/views/flows.py b/passbook/admin/views/flows.py index 377cf93f4..2ec591c15 100644 --- a/passbook/admin/views/flows.py +++ b/passbook/admin/views/flows.py @@ -5,13 +5,17 @@ from django.contrib.auth.mixins import ( PermissionRequiredMixin as DjangoPermissionRequiredMixin, ) from django.contrib.messages.views import SuccessMessageMixin +from django.http import HttpRequest, HttpResponse from django.urls import reverse_lazy from django.utils.translation import ugettext as _ -from django.views.generic import DeleteView, ListView, UpdateView +from django.views.generic import DeleteView, DetailView, ListView, UpdateView from guardian.mixins import PermissionListMixin, PermissionRequiredMixin from passbook.flows.forms import FlowForm from passbook.flows.models import Flow +from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER +from passbook.flows.views import SESSION_KEY_PLAN, FlowPlanner +from passbook.lib.utils.urls import redirect_with_qs from passbook.lib.views import CreateAssignPermView @@ -46,6 +50,25 @@ class FlowCreateView( return super().get_context_data(**kwargs) +class FlowDebugExecuteView(LoginRequiredMixin, PermissionRequiredMixin, DetailView): + """Debug exectue flow, setting the current user as pending user""" + + model = Flow + permission_required = "passbook_flows.view_flow" + + # pylint: disable=unused-argument + def get(self, request: HttpRequest, pk: str) -> HttpResponse: + """Debug exectue flow, setting the current user as pending user""" + flow: Flow = self.get_object() + planner = FlowPlanner(flow) + planner.use_cache = False + plan = planner.plan(self.request, {PLAN_CONTEXT_PENDING_USER: request.user,},) + self.request.session[SESSION_KEY_PLAN] = plan + return redirect_with_qs( + "passbook_flows:flow-executor-shell", self.request.GET, flow_slug=flow.slug, + ) + + class FlowUpdateView( SuccessMessageMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView ):