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 1fd3cfd537
commit 52f32112c8
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
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

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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