diff --git a/sqle/api/controller/v1/dashboard.go b/sqle/api/controller/v1/dashboard.go index 947963e01d..397342d01b 100644 --- a/sqle/api/controller/v1/dashboard.go +++ b/sqle/api/controller/v1/dashboard.go @@ -89,6 +89,7 @@ func Dashboard(c echo.Context) error { "filter_current_step_type": model.WorkflowStepTypeSQLExecute, "filter_create_user_name": user.Name, "check_user_can_access": false, + "current_user_id": user.ID, }) if err != nil { return controller.JSONBaseErrorReq(c, err) @@ -111,6 +112,7 @@ func Dashboard(c echo.Context) error { "filter_current_step_type": model.WorkflowStepTypeSQLExecute, "filter_current_step_assignee_user_name": user.Name, "check_user_can_access": false, + "current_user_id": user.ID, }) if err != nil { return controller.JSONBaseErrorReq(c, err) @@ -165,6 +167,7 @@ func DashboardProjectTipsV1(c echo.Context) error { "filter_create_user_name": user.Name, "filter_status": []string{model.WorkflowStatusReject, model.WorkflowStatusWaitForAudit, model.WorkflowStatusWaitForExecution}, "check_user_can_access": false, + "current_user_id": user.ID, }) if err != nil { return controller.JSONBaseErrorReq(c, err) @@ -174,6 +177,7 @@ func DashboardProjectTipsV1(c echo.Context) error { "filter_status": []string{model.WorkflowStatusWaitForAudit, model.WorkflowStatusWaitForExecution}, "filter_current_step_assignee_user_name": user.Name, "check_user_can_access": false, + "current_user_id": user.ID, }) if err != nil { return controller.JSONBaseErrorReq(c, err) diff --git a/sqle/model/workflow_list.go b/sqle/model/workflow_list.go index a0866e9c7f..1ae940d829 100644 --- a/sqle/model/workflow_list.go +++ b/sqle/model/workflow_list.go @@ -66,6 +66,7 @@ LEFT JOIN workflow_steps AS curr_ws ON wr.current_workflow_step_id = curr_ws.id LEFT JOIN workflow_step_templates AS curr_wst ON curr_ws.workflow_step_template_id = curr_wst.id LEFT JOIN workflow_step_user AS curr_wst_re_user ON curr_ws.id = curr_wst_re_user.workflow_step_id LEFT JOIN users AS curr_ass_user ON curr_wst_re_user.user_id = curr_ass_user.id +LEFT JOIN workflow_instance_record_user wiru ON wiru.workflow_instance_record_id = wir.id {{- if .check_user_can_access }} LEFT JOIN workflow_steps AS all_ws ON w.id = all_ws.workflow_id AND all_ws.state !='initialized' @@ -122,7 +123,11 @@ AND wr.status IN (:filter_status) {{- end }} {{- if .filter_current_step_assignee_user_name }} -AND curr_ass_user.login_name = :filter_current_step_assignee_user_name +AND (curr_ass_user.login_name = :filter_current_step_assignee_user_name +{{- if .exist_wait_for_execution }} + OR wiru.user_id = :current_user_id +{{- end }} +) {{- end }} {{- if .filter_task_status }} @@ -161,6 +166,8 @@ func (s *Storage) GetWorkflowsByReq(data map[string]interface{}, user *User) ( data["viewable_instance_ids"] = utils.JoinUintSliceToString(ids, ", ") } + setWaitForExecutionStatus(data) + err = s.getListResult(workflowsQueryBodyTpl, workflowsQueryTpl, data, &result) if err != nil { return result, 0, err @@ -171,7 +178,35 @@ func (s *Storage) GetWorkflowsByReq(data map[string]interface{}, user *User) ( return result, count, err } +// exist_wait_for_execution is used to indicate whether there is a wait_for_execution status in the filter_status +// 如果工单是待上线状态且当前用户是工单内任一数据源的待操作人,则工单也会被查询出来 +// 相关issue: https://github.com/actiontech/sqle/issues/1605 +func setWaitForExecutionStatus(data map[string]interface{}) { + filterStatus := data["filter_status"] + if filterStatus == nil || filterStatus == "" { + return + } + + status, isStr := filterStatus.(string) + if isStr && status == WorkflowStatusWaitForExecution { + data["exist_wait_for_execution"] = true + return + } + + statusList, isArray := filterStatus.([]string) + if isArray { + for _, status := range statusList { + if status != WorkflowStatusWaitForExecution { + continue + } + data["exist_wait_for_execution"] = true + return + } + } +} + func (s *Storage) GetWorkflowCountByReq(data map[string]interface{}) (uint64, error) { + setWaitForExecutionStatus(data) return s.getCountResult(workflowsQueryBodyTpl, workflowsCountTpl, data) } @@ -195,6 +230,9 @@ type ProjectWorkflowCount struct { func (s *Storage) GetWorkflowCountForDashboardProjectTipsByReq(data map[string]interface{}) ( result []*ProjectWorkflowCount, err error) { + + setWaitForExecutionStatus(data) + err = s.getTemplateQueryResult(data, &result, workflowsQueryBodyTpl, projectWorkflowCountTpl) if err != nil { return result, err