From 5fa6be665183b1b52af08f2b5be1d30feaea8d4d Mon Sep 17 00:00:00 2001 From: jasquat Date: Mon, 19 Dec 2022 17:11:39 -0500 Subject: [PATCH] fix getting task info for a process instance w/ burnettk --- .../src/spiffworkflow_backend/api.yml | 47 ++++++++++ .../routes/process_api_blueprint.py | 90 ++++++++++++------- .../src/hooks/UriListForPermissions.tsx | 1 + .../src/routes/ProcessInstanceShow.tsx | 11 ++- 4 files changed, 112 insertions(+), 37 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml index 49419ef9..0d3a4afe 100755 --- a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml +++ b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml @@ -798,6 +798,53 @@ paths: schema: $ref: "#/components/schemas/Workflow" + /process-instances/for-me/{modified_process_model_identifier}/{process_instance_id}/task-info: + parameters: + - name: modified_process_model_identifier + in: path + required: true + description: The unique id of an existing process model + schema: + type: string + - name: process_instance_id + in: path + required: true + description: The unique id of an existing process instance. + schema: + type: integer + - name: process_identifier + in: query + required: false + description: The identifier of the process to use for the diagram. Useful for displaying the diagram for a call activity. + schema: + type: string + - name: all_tasks + in: query + required: false + description: If true, this wil return all tasks associated with the process instance and not just user tasks. + schema: + type: boolean + - name: spiff_step + in: query + required: false + description: If set will return the tasks as they were during a specific step of execution. + schema: + type: integer + get: + tags: + - Process Instances + operationId: spiffworkflow_backend.routes.process_api_blueprint.process_instance_task_list_without_task_data_for_me + summary: returns the list of all user tasks associated with process instance without the task data + responses: + "200": + description: list of tasks + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/Task" + /process-instances/{modified_process_model_identifier}/{process_instance_id}/task-info: parameters: - name: modified_process_model_identifier diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py index 12140458..8b8d7168 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -1180,34 +1180,7 @@ def process_instance_show_for_me( process_identifier: Optional[str] = None, ) -> flask.wrappers.Response: """Process_instance_show_for_me.""" - process_instance = ( - ProcessInstanceModel.query.filter_by(id=process_instance_id) - .outerjoin(HumanTaskModel) - .outerjoin( - HumanTaskUserModel, - and_( - HumanTaskModel.id == HumanTaskUserModel.human_task_id, - HumanTaskUserModel.user_id == g.user.id, - ), - ) - .filter( - or_( - HumanTaskUserModel.id.is_not(None), - ProcessInstanceModel.process_initiator_id == g.user.id, - ) - ) - .first() - ) - - if process_instance is None: - raise ( - ApiError( - error_code="process_instance_cannot_be_found", - message=f"Process instance with id {process_instance_id} cannot be found that is associated with you.", - status_code=400, - ) - ) - + process_instance = _find_process_instance_for_me_or_raise(process_instance_id) return _get_process_instance( process_instance=process_instance, modified_process_model_identifier=modified_process_model_identifier, @@ -1599,6 +1572,23 @@ def get_tasks( return make_response(jsonify(response_json), 200) +def process_instance_task_list_without_task_data_for_me( + modified_process_model_identifier: str, + process_instance_id: int, + all_tasks: bool = False, + spiff_step: int = 0, +) -> flask.wrappers.Response: + process_instance = _find_process_instance_for_me_or_raise(process_instance_id) + print(f"process_instance: {process_instance}") + return process_instance_task_list( + modified_process_model_identifier, + process_instance, + all_tasks, + spiff_step, + get_task_data=False, + ) + + def process_instance_task_list_without_task_data( modified_process_model_identifier: str, process_instance_id: int, @@ -1606,9 +1596,10 @@ def process_instance_task_list_without_task_data( spiff_step: int = 0, ) -> flask.wrappers.Response: """Process_instance_task_list_without_task_data.""" + process_instance = find_process_instance_by_id_or_raise(process_instance_id) return process_instance_task_list( modified_process_model_identifier, - process_instance_id, + process_instance, all_tasks, spiff_step, get_task_data=False, @@ -1622,9 +1613,10 @@ def process_instance_task_list_with_task_data( spiff_step: int = 0, ) -> flask.wrappers.Response: """Process_instance_task_list_with_task_data.""" + process_instance = find_process_instance_by_id_or_raise(process_instance_id) return process_instance_task_list( modified_process_model_identifier, - process_instance_id, + process_instance, all_tasks, spiff_step, get_task_data=True, @@ -1633,19 +1625,17 @@ def process_instance_task_list_with_task_data( def process_instance_task_list( _modified_process_model_identifier: str, - process_instance_id: int, + process_instance: ProcessInstanceModel, all_tasks: bool = False, spiff_step: int = 0, get_task_data: bool = False, ) -> flask.wrappers.Response: """Process_instance_task_list.""" - process_instance = find_process_instance_by_id_or_raise(process_instance_id) - if spiff_step > 0: step_detail = ( db.session.query(SpiffStepDetailsModel) .filter( - SpiffStepDetailsModel.process_instance_id == process_instance.id, + SpiffStepDetailsModel.process_instance.id == process_instance.id, SpiffStepDetailsModel.spiff_step == spiff_step, ) .first() @@ -2299,3 +2289,35 @@ def commit_and_push_to_git(message: str) -> None: current_app.logger.info(f"git output: {git_output}") else: current_app.logger.info("Git commit on save is disabled") + + +def _find_process_instance_for_me_or_raise(process_instance_id: int) -> ProcessInstanceModel: + process_instance = ( + ProcessInstanceModel.query.filter_by(id=process_instance_id) + .outerjoin(HumanTaskModel) + .outerjoin( + HumanTaskUserModel, + and_( + HumanTaskModel.id == HumanTaskUserModel.human_task_id, + HumanTaskUserModel.user_id == g.user.id, + ), + ) + .filter( + or_( + HumanTaskUserModel.id.is_not(None), + ProcessInstanceModel.process_initiator_id == g.user.id, + ) + ) + .first() + ) + + if process_instance is None: + raise ( + ApiError( + error_code="process_instance_cannot_be_found", + message=f"Process instance with id {process_instance_id} cannot be found that is associated with you.", + status_code=400, + ) + ) + + return process_instance diff --git a/spiffworkflow-frontend/src/hooks/UriListForPermissions.tsx b/spiffworkflow-frontend/src/hooks/UriListForPermissions.tsx index 46be60d5..574eb4e9 100644 --- a/spiffworkflow-frontend/src/hooks/UriListForPermissions.tsx +++ b/spiffworkflow-frontend/src/hooks/UriListForPermissions.tsx @@ -18,6 +18,7 @@ export const useUriListForPermissions = () => { processInstanceSuspendPath: `/v1.0/process-instance-suspend/${params.process_model_id}/${params.process_instance_id}`, processInstanceTaskListDataPath: `/v1.0/task-data/${params.process_model_id}/${params.process_instance_id}`, processInstanceTaskListPath: `/v1.0/process-instances/${params.process_model_id}/${params.process_instance_id}/task-info`, + processInstanceTaskListForMePath: `/v1.0/process-instances/for-me/${params.process_model_id}/${params.process_instance_id}/task-info`, processInstanceTerminatePath: `/v1.0/process-instance-terminate/${params.process_model_id}/${params.process_instance_id}`, processModelCreatePath: `/v1.0/process-models/${params.process_group_id}`, processModelFileCreatePath: `/v1.0/process-models/${params.process_model_id}/files`, diff --git a/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx b/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx index 37b51548..fe5a2a32 100644 --- a/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx +++ b/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx @@ -72,9 +72,14 @@ export default function ProcessInstanceShow({ variant }: OwnProps) { const modifiedProcessModelId = params.process_model_id; const { targetUris } = useUriListForPermissions(); + const taskListPath = + variant === 'all' + ? targetUris.processInstanceTaskListPath + : targetUris.processInstanceTaskListForMePath; + const permissionRequestData: PermissionsToCheck = { [targetUris.messageInstanceListPath]: ['GET'], - [targetUris.processInstanceTaskListPath]: ['GET'], + [taskListPath]: ['GET'], [targetUris.processInstanceTaskListDataPath]: ['GET', 'PUT'], [targetUris.processInstanceActionPath]: ['DELETE'], [targetUris.processInstanceLogListPath]: ['GET'], @@ -118,8 +123,8 @@ export default function ProcessInstanceShow({ variant }: OwnProps) { let taskPath = ''; if (ability.can('GET', targetUris.processInstanceTaskListDataPath)) { taskPath = `${targetUris.processInstanceTaskListDataPath}${taskParams}`; - } else if (ability.can('GET', targetUris.processInstanceTaskListPath)) { - taskPath = `${targetUris.processInstanceTaskListPath}${taskParams}`; + } else if (ability.can('GET', taskListPath)) { + taskPath = `${taskListPath}${taskParams}`; } if (taskPath) { HttpService.makeCallToBackend({