Query fix with the gang

This commit is contained in:
Jon Herron 2022-11-28 11:15:40 -05:00
parent 400747a797
commit 40abba13d1
1 changed files with 8 additions and 13 deletions

View File

@ -899,7 +899,6 @@ def process_instance_list(
SpiffStepDetailsModel.completed_by_user_id == g.user.id SpiffStepDetailsModel.completed_by_user_id == g.user.id
) )
# TODO: not sure if this is exactly what is wanted
if report_filter.with_tasks_completed_by_my_group is True: if report_filter.with_tasks_completed_by_my_group 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
@ -918,22 +917,18 @@ def process_instance_list(
process_instance_query = process_instance_query.filter( process_instance_query = process_instance_query.filter(
SpiffLoggingModel.spiff_step == SpiffStepDetailsModel.spiff_step SpiffLoggingModel.spiff_step == SpiffStepDetailsModel.spiff_step
) )
process_instance_query = process_instance_query.join(
my_groups = ( GroupModel,
select(UserGroupAssignmentModel) # type: ignore GroupModel.id == SpiffStepDetailsModel.lane_assignment_id,
.where(UserGroupAssignmentModel.user_id == g.user.id)
.with_only_columns(UserGroupAssignmentModel.group_id)
) )
users_in_my_groups = ( process_instance_query = process_instance_query.join(
select(UserGroupAssignmentModel) # type: ignore UserGroupAssignmentModel,
.where(UserGroupAssignmentModel.group_id.in_(my_groups)) UserGroupAssignmentModel.group_id == GroupModel.id,
.with_only_columns(UserGroupAssignmentModel.user_id)
) )
process_instance_query = process_instance_query.filter( process_instance_query = process_instance_query.filter(
SpiffStepDetailsModel.completed_by_user_id.in_(users_in_my_groups) # type: ignore UserGroupAssignmentModel.user_id == g.user.id
) )
process_instances = ( process_instances = (
process_instance_query.group_by(ProcessInstanceModel.id) process_instance_query.group_by(ProcessInstanceModel.id)
.order_by( .order_by(