some basic stuff for showing only relating items to user w/ burnettk

This commit is contained in:
jasquat 2022-12-16 16:07:40 -05:00
parent 01472d9848
commit f9c1036cce
5 changed files with 37 additions and 7 deletions

View File

@ -577,6 +577,12 @@ paths:
description: For filtering - show instances with tasks completed by my group description: For filtering - show instances with tasks completed by my group
schema: schema:
type: boolean 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 - name: user_filter
in: query in: query
required: false required: false

View File

@ -1,5 +1,6 @@
"""APIs for dealing with process groups, process models, and process instances.""" """APIs for dealing with process groups, process models, and process instances."""
import json import json
from sqlalchemy import or_
import os import os
import random import random
import re import re
@ -846,6 +847,7 @@ def process_instance_list(
initiated_by_me: Optional[bool] = None, initiated_by_me: Optional[bool] = None,
with_tasks_completed_by_me: Optional[bool] = None, with_tasks_completed_by_me: Optional[bool] = None,
with_tasks_completed_by_my_group: Optional[bool] = None, with_tasks_completed_by_my_group: Optional[bool] = None,
with_relation_to_me: Optional[bool] = None,
user_filter: Optional[bool] = False, user_filter: Optional[bool] = False,
report_identifier: Optional[str] = None, report_identifier: Optional[str] = None,
report_id: Optional[int] = None, report_id: Optional[int] = None,
@ -855,6 +857,7 @@ def process_instance_list(
process_instance_report = ProcessInstanceReportService.report_with_identifier( process_instance_report = ProcessInstanceReportService.report_with_identifier(
g.user, report_id, report_identifier g.user, report_id, report_identifier
) )
print(f"with_relation_to_me: {with_relation_to_me}")
if user_filter: if user_filter:
report_filter = ProcessInstanceReportFilter( report_filter = ProcessInstanceReportFilter(
@ -867,6 +870,7 @@ def process_instance_list(
initiated_by_me, initiated_by_me,
with_tasks_completed_by_me, with_tasks_completed_by_me,
with_tasks_completed_by_my_group, with_tasks_completed_by_my_group,
with_relation_to_me
) )
else: else:
report_filter = ( report_filter = (
@ -881,6 +885,7 @@ def process_instance_list(
initiated_by_me, initiated_by_me,
with_tasks_completed_by_me, with_tasks_completed_by_me,
with_tasks_completed_by_my_group, 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 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: if report_filter.initiated_by_me is True:
process_instance_query = process_instance_query.filter( process_instance_query = process_instance_query.filter(
ProcessInstanceModel.status.in_(["complete", "error", "terminated"]) # type: ignore ProcessInstanceModel.status.in_(["complete", "error", "terminated"]) # type: ignore

View File

@ -699,10 +699,10 @@ class ProcessInstanceProcessor:
db.session.add(active_task_user) db.session.add(active_task_user)
db.session.commit() db.session.commit()
if len(active_tasks) > 0: # if len(active_tasks) > 0:
for at in active_tasks: # for at in active_tasks:
db.session.delete(at) # db.session.delete(at)
db.session.commit() # db.session.commit()
@staticmethod @staticmethod
def get_parser() -> MyCustomParser: def get_parser() -> MyCustomParser:

View File

@ -24,6 +24,7 @@ class ProcessInstanceReportFilter:
initiated_by_me: Optional[bool] = None initiated_by_me: Optional[bool] = None
with_tasks_completed_by_me: Optional[bool] = None with_tasks_completed_by_me: Optional[bool] = None
with_tasks_completed_by_my_group: 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]: def to_dict(self) -> dict[str, str]:
"""To_dict.""" """To_dict."""
@ -51,6 +52,10 @@ class ProcessInstanceReportFilter:
d["with_tasks_completed_by_my_group"] = str( d["with_tasks_completed_by_my_group"] = str(
self.with_tasks_completed_by_my_group self.with_tasks_completed_by_my_group
).lower() ).lower()
if self.with_relation_to_me is not None:
d["with_relation_to_me"] = str(
self.with_relation_to_me
).lower()
return d return d
@ -174,6 +179,9 @@ class ProcessInstanceReportService:
with_tasks_completed_by_my_group = bool_value( with_tasks_completed_by_my_group = bool_value(
"with_tasks_completed_by_my_group" "with_tasks_completed_by_my_group"
) )
with_relation_to_me = bool_value(
"with_relation_to_me"
)
report_filter = ProcessInstanceReportFilter( report_filter = ProcessInstanceReportFilter(
process_model_identifier, process_model_identifier,
@ -185,6 +193,7 @@ class ProcessInstanceReportService:
initiated_by_me, initiated_by_me,
with_tasks_completed_by_me, with_tasks_completed_by_me,
with_tasks_completed_by_my_group, with_tasks_completed_by_my_group,
with_relation_to_me,
) )
return report_filter return report_filter
@ -202,6 +211,7 @@ class ProcessInstanceReportService:
initiated_by_me: Optional[bool] = None, initiated_by_me: Optional[bool] = None,
with_tasks_completed_by_me: Optional[bool] = None, with_tasks_completed_by_me: Optional[bool] = None,
with_tasks_completed_by_my_group: Optional[bool] = None, with_tasks_completed_by_my_group: Optional[bool] = None,
with_relation_to_me: Optional[bool] = None,
) -> ProcessInstanceReportFilter: ) -> ProcessInstanceReportFilter:
"""Filter_from_metadata_with_overrides.""" """Filter_from_metadata_with_overrides."""
report_filter = cls.filter_from_metadata(process_instance_report) report_filter = cls.filter_from_metadata(process_instance_report)
@ -226,6 +236,10 @@ class ProcessInstanceReportService:
report_filter.with_tasks_completed_by_my_group = ( report_filter.with_tasks_completed_by_my_group = (
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 return report_filter

View File

@ -74,9 +74,9 @@ export default function ProcessInstanceShow() {
[targetUris.processInstanceActionPath]: ['DELETE'], [targetUris.processInstanceActionPath]: ['DELETE'],
[targetUris.processInstanceLogListPath]: ['GET'], [targetUris.processInstanceLogListPath]: ['GET'],
[targetUris.processModelShowPath]: ['PUT'], [targetUris.processModelShowPath]: ['PUT'],
[`${targetUris.processInstanceActionPath}/suspend`]: ['PUT'], [`${targetUris.processInstanceActionPath}/suspend`]: ['POST'],
[`${targetUris.processInstanceActionPath}/terminate`]: ['PUT'], [`${targetUris.processInstanceActionPath}/terminate`]: ['POST'],
[`${targetUris.processInstanceActionPath}/resume`]: ['PUT'], [`${targetUris.processInstanceActionPath}/resume`]: ['POST'],
}; };
const { ability, permissionsLoaded } = usePermissionFetcher( const { ability, permissionsLoaded } = usePermissionFetcher(
permissionRequestData permissionRequestData