From 8791cc513cd804ceeb62b10938c4e35c8ae9b6e7 Mon Sep 17 00:00:00 2001 From: jasquat Date: Wed, 31 May 2023 08:54:33 -0400 Subject: [PATCH 1/3] allow not redirecting to home page at all in interstitial component and do not error out if next task does not exist --- .../routes/tasks_controller.py | 29 ++++++++++--------- .../services/process_instance_service.py | 1 - .../src/components/ProcessInterstitial.tsx | 5 ++-- .../src/routes/ProcessInstanceShow.tsx | 1 + 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py index df9f5818..4c5bf15c 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py @@ -430,20 +430,21 @@ def _interstitial_stream(process_instance: ProcessInstanceModel) -> Generator[st break # No more tasks to report spiff_task = processor.next_task() - task = ProcessInstanceService.spiff_task_to_api_task(processor, processor.next_task()) - if task.id not in reported_ids: - try: - instructions = render_instructions(spiff_task) - except Exception as e: - api_error = ApiError( - error_code="engine_steps_error", - message=f"Failed to complete an automated task. Error was: {str(e)}", - status_code=400, - ) - yield render_data("error", api_error) - raise e - task.properties = {"instructionsForEndUser": instructions} - yield render_data("task", task) + if spiff_task is not None: + task = ProcessInstanceService.spiff_task_to_api_task(processor, spiff_task) + if task.id not in reported_ids: + try: + instructions = render_instructions(spiff_task) + except Exception as e: + api_error = ApiError( + error_code="engine_steps_error", + message=f"Failed to complete an automated task. Error was: {str(e)}", + status_code=400, + ) + yield render_data("error", api_error) + raise e + task.properties = {"instructionsForEndUser": instructions} + yield render_data("task", task) def get_ready_engine_step_count(bpmn_process_instance: BpmnWorkflow) -> int: diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py index f342f5f0..109832d7 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py @@ -514,7 +514,6 @@ class ProcessInstanceService: add_docs_and_forms: bool = False, calling_subprocess_task_id: str | None = None, ) -> Task: - """Spiff_task_to_api_task.""" task_type = spiff_task.task_spec.description props = {} diff --git a/spiffworkflow-frontend/src/components/ProcessInterstitial.tsx b/spiffworkflow-frontend/src/components/ProcessInterstitial.tsx index 639b5bb9..3c06d05e 100644 --- a/spiffworkflow-frontend/src/components/ProcessInterstitial.tsx +++ b/spiffworkflow-frontend/src/components/ProcessInterstitial.tsx @@ -15,12 +15,14 @@ type OwnProps = { processInstanceId: number; processInstanceShowPageUrl: string; allowRedirect: boolean; + redirectToHomeWhenNoTasks?: boolean; }; export default function ProcessInterstitial({ processInstanceId, allowRedirect, processInstanceShowPageUrl, + redirectToHomeWhenNoTasks = true, }: OwnProps) { const [data, setData] = useState([]); const [lastTask, setLastTask] = useState(null); @@ -49,7 +51,6 @@ export default function ProcessInterstitial({ } }, onclose() { - console.log('The state is closed.'); setState('CLOSED'); }, }); @@ -161,7 +162,7 @@ export default function ProcessInterstitial({ /** In the event there is no task information and the connection closed, * redirect to the home page. */ - if (state === 'CLOSED' && lastTask === null) { + if (state === 'CLOSED' && lastTask === null && redirectToHomeWhenNoTasks) { navigate(`/tasks`); } diff --git a/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx b/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx index ca7968a2..74b8bb05 100644 --- a/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx +++ b/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx @@ -1113,6 +1113,7 @@ export default function ProcessInstanceShow({ variant }: OwnProps) {
From bb6a0bf44351f2694441760bfd56cb22f7a89b6f Mon Sep 17 00:00:00 2001 From: jasquat Date: Wed, 31 May 2023 09:42:20 -0400 Subject: [PATCH 2/3] stop refreshing homepage if unauthorized to metadata --- .../src/components/ProcessInstanceListTable.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx b/spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx index 268debab..e069f18a 100644 --- a/spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx +++ b/spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx @@ -490,6 +490,7 @@ export default function ProcessInstanceListTable({ HttpService.makeCallToBackend({ path: `/process-instances/report-metadata${queryParamString}`, successCallback: getProcessInstances, + onUnauthorized: stopRefreshing, }); } else { getProcessInstances(); @@ -542,6 +543,7 @@ export default function ProcessInstanceListTable({ permissionsLoaded, reportIdentifier, searchParams, + stopRefreshing, ]); const processInstanceReportSaveTag = () => { From e72ccebed0c2cf7cf0761c951cd14848c95fa13c Mon Sep 17 00:00:00 2001 From: danfunk Date: Wed, 31 May 2023 10:28:16 -0400 Subject: [PATCH 3/3] just reuse allowRedirect. --- spiffworkflow-frontend/src/components/ProcessInterstitial.tsx | 4 +--- spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/spiffworkflow-frontend/src/components/ProcessInterstitial.tsx b/spiffworkflow-frontend/src/components/ProcessInterstitial.tsx index 3c06d05e..2face331 100644 --- a/spiffworkflow-frontend/src/components/ProcessInterstitial.tsx +++ b/spiffworkflow-frontend/src/components/ProcessInterstitial.tsx @@ -15,14 +15,12 @@ type OwnProps = { processInstanceId: number; processInstanceShowPageUrl: string; allowRedirect: boolean; - redirectToHomeWhenNoTasks?: boolean; }; export default function ProcessInterstitial({ processInstanceId, allowRedirect, processInstanceShowPageUrl, - redirectToHomeWhenNoTasks = true, }: OwnProps) { const [data, setData] = useState([]); const [lastTask, setLastTask] = useState(null); @@ -162,7 +160,7 @@ export default function ProcessInterstitial({ /** In the event there is no task information and the connection closed, * redirect to the home page. */ - if (state === 'CLOSED' && lastTask === null && redirectToHomeWhenNoTasks) { + if (state === 'CLOSED' && lastTask === null && allowRedirect) { navigate(`/tasks`); } diff --git a/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx b/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx index 74b8bb05..ca7968a2 100644 --- a/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx +++ b/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx @@ -1113,7 +1113,6 @@ export default function ProcessInstanceShow({ variant }: OwnProps) {