From 52f32112c873a2d2ad1eb622c0ef89d04b93e9c1 Mon Sep 17 00:00:00 2001 From: jasquat Date: Fri, 16 Dec 2022 16:07:40 -0500 Subject: [PATCH] some basic stuff for showing only relating items to user w/ burnettk --- .../src/spiffworkflow_backend/api.yml | 6 ++++++ .../routes/process_api_blueprint.py | 10 ++++++++++ .../services/process_instance_processor.py | 8 ++++---- .../services/process_instance_report_service.py | 14 ++++++++++++++ .../src/routes/ProcessInstanceShow.tsx | 6 +++--- 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml index be9796aa..07ba8d63 100755 --- a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml +++ b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml @@ -577,6 +577,12 @@ paths: description: For filtering - show instances with tasks completed by my group schema: type: boolean + - name: with_relation_to_me + in: query + required: false + description: For filtering - show instances that have something to do with me + schema: + type: boolean - name: user_filter in: query required: false 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 294a6524..aff7a9c0 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -1,5 +1,6 @@ """APIs for dealing with process groups, process models, and process instances.""" import json +from sqlalchemy import or_ import os import random import re @@ -846,6 +847,7 @@ def process_instance_list( initiated_by_me: Optional[bool] = None, with_tasks_completed_by_me: Optional[bool] = None, with_tasks_completed_by_my_group: Optional[bool] = None, + with_relation_to_me: Optional[bool] = None, user_filter: Optional[bool] = False, report_identifier: Optional[str] = None, report_id: Optional[int] = None, @@ -855,6 +857,7 @@ def process_instance_list( process_instance_report = ProcessInstanceReportService.report_with_identifier( g.user, report_id, report_identifier ) + print(f"with_relation_to_me: {with_relation_to_me}") if user_filter: report_filter = ProcessInstanceReportFilter( @@ -867,6 +870,7 @@ def process_instance_list( initiated_by_me, with_tasks_completed_by_me, with_tasks_completed_by_my_group, + with_relation_to_me ) else: report_filter = ( @@ -881,6 +885,7 @@ def process_instance_list( initiated_by_me, with_tasks_completed_by_me, with_tasks_completed_by_my_group, + with_relation_to_me ) ) @@ -933,6 +938,11 @@ def process_instance_list( ProcessInstanceModel.status.in_(report_filter.process_status) # type: ignore ) + print(f"report_filter.with_relation_to_me: {report_filter.with_relation_to_me}") + if report_filter.with_relation_to_me is True: + process_instance_query = process_instance_query.outerjoin(ActiveTaskModel).outerjoin(ActiveTaskUserModel, ActiveTaskUserModel.user_id == g.user.id) + process_instance_query = process_instance_query.filter(or_(ActiveTaskUserModel.id.is_not(None), ProcessInstanceModel.process_initiator_id == g.user.id)) + if report_filter.initiated_by_me is True: process_instance_query = process_instance_query.filter( ProcessInstanceModel.status.in_(["complete", "error", "terminated"]) # type: ignore diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py index 5edc526c..3ad3fbe7 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py @@ -699,10 +699,10 @@ class ProcessInstanceProcessor: db.session.add(active_task_user) db.session.commit() - if len(active_tasks) > 0: - for at in active_tasks: - db.session.delete(at) - db.session.commit() + # if len(active_tasks) > 0: + # for at in active_tasks: + # db.session.delete(at) + # db.session.commit() @staticmethod def get_parser() -> MyCustomParser: diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_report_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_report_service.py index 84d5d675..66561fad 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_report_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_report_service.py @@ -24,6 +24,7 @@ class ProcessInstanceReportFilter: initiated_by_me: Optional[bool] = None with_tasks_completed_by_me: Optional[bool] = None with_tasks_completed_by_my_group: Optional[bool] = None + with_relation_to_me: Optional[bool] = None def to_dict(self) -> dict[str, str]: """To_dict.""" @@ -51,6 +52,10 @@ class ProcessInstanceReportFilter: d["with_tasks_completed_by_my_group"] = str( self.with_tasks_completed_by_my_group ).lower() + if self.with_relation_to_me is not None: + d["with_relation_to_me"] = str( + self.with_relation_to_me + ).lower() return d @@ -174,6 +179,9 @@ class ProcessInstanceReportService: with_tasks_completed_by_my_group = bool_value( "with_tasks_completed_by_my_group" ) + with_relation_to_me = bool_value( + "with_relation_to_me" + ) report_filter = ProcessInstanceReportFilter( process_model_identifier, @@ -185,6 +193,7 @@ class ProcessInstanceReportService: initiated_by_me, with_tasks_completed_by_me, with_tasks_completed_by_my_group, + with_relation_to_me, ) return report_filter @@ -202,6 +211,7 @@ class ProcessInstanceReportService: initiated_by_me: Optional[bool] = None, with_tasks_completed_by_me: Optional[bool] = None, with_tasks_completed_by_my_group: Optional[bool] = None, + with_relation_to_me: Optional[bool] = None, ) -> ProcessInstanceReportFilter: """Filter_from_metadata_with_overrides.""" report_filter = cls.filter_from_metadata(process_instance_report) @@ -226,6 +236,10 @@ class ProcessInstanceReportService: report_filter.with_tasks_completed_by_my_group = ( with_tasks_completed_by_my_group ) + if with_relation_to_me is not None: + report_filter.with_relation_to_me = ( + with_relation_to_me + ) return report_filter diff --git a/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx b/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx index 1adb585b..88e5e3bb 100644 --- a/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx +++ b/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx @@ -74,9 +74,9 @@ export default function ProcessInstanceShow() { [targetUris.processInstanceActionPath]: ['DELETE'], [targetUris.processInstanceLogListPath]: ['GET'], [targetUris.processModelShowPath]: ['PUT'], - [`${targetUris.processInstanceActionPath}/suspend`]: ['PUT'], - [`${targetUris.processInstanceActionPath}/terminate`]: ['PUT'], - [`${targetUris.processInstanceActionPath}/resume`]: ['PUT'], + [`${targetUris.processInstanceActionPath}/suspend`]: ['POST'], + [`${targetUris.processInstanceActionPath}/terminate`]: ['POST'], + [`${targetUris.processInstanceActionPath}/resume`]: ['POST'], }; const { ability, permissionsLoaded } = usePermissionFetcher( permissionRequestData