Skip to content

Commit

Permalink
chore:fix issue 1605
Browse files Browse the repository at this point in the history
  • Loading branch information
taolx0 committed Aug 23, 2023
1 parent 824d43c commit a4c8c4c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
4 changes: 4 additions & 0 deletions sqle/api/controller/v1/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
40 changes: 39 additions & 1 deletion sqle/model/workflow_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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
Expand All @@ -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)
}

Expand All @@ -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
Expand Down

0 comments on commit a4c8c4c

Please sign in to comment.