From 3b1d76fdd735ba85acccb4c90cd0c78328bc7939 Mon Sep 17 00:00:00 2001 From: BugsGuru Date: Fri, 19 Dec 2025 17:16:53 +0800 Subject: [PATCH] feat(notification): add workflow cancellation notification and localization support - Implemented notification for workflow cancellation in the CancelWorkflowV2 function. - Added new localization strings for cancellation notifications in English and Chinese. - Updated notification handling to include cancellation type in the workflow notification process. --- sqle/api/controller/v2/workflow.go | 2 ++ sqle/locale/active.en.toml | 1 + sqle/locale/active.zh.toml | 1 + sqle/locale/message_zh.go | 1 + sqle/notification/notification.go | 10 ++++++++++ 5 files changed, 15 insertions(+) diff --git a/sqle/api/controller/v2/workflow.go b/sqle/api/controller/v2/workflow.go index 8f601a132..254ba3253 100644 --- a/sqle/api/controller/v2/workflow.go +++ b/sqle/api/controller/v2/workflow.go @@ -240,6 +240,8 @@ func CancelWorkflowV2(c echo.Context) error { } go im.BatchCancelApprove([]string{workflow.WorkflowId}, user) + go notification.NotifyWorkflow(string(workflow.ProjectId), workflow.WorkflowId, notification.WorkflowNotifyTypeCancel) + return controller.JSONBaseErrorReq(c, nil) } diff --git a/sqle/locale/active.en.toml b/sqle/locale/active.en.toml index a5ee6f272..0d45a9218 100644 --- a/sqle/locale/active.en.toml +++ b/sqle/locale/active.en.toml @@ -357,6 +357,7 @@ TaskStatusExecuteSucceeded = "Execution succeeded" TaskStatusExecuting = "Executing" TaskStatusManuallyExecuted = "Manually executed" WordIs = "is" +WorkflowNotifyTypeCancel = "SQL Workflow Cancelled" WorkflowNotifyTypeDefault = "SQL Workflow Unknown Requests" WorkflowNotifyTypeExecuteFail = "SQL Workflow Execute Failed" WorkflowNotifyTypeExecuteSuccess = "SQL Workflow Execute Succeeded" diff --git a/sqle/locale/active.zh.toml b/sqle/locale/active.zh.toml index e5b4b6180..f77ab89f9 100644 --- a/sqle/locale/active.zh.toml +++ b/sqle/locale/active.zh.toml @@ -357,6 +357,7 @@ TaskStatusExecuteSucceeded = "上线成功" TaskStatusExecuting = "正在上线" TaskStatusManuallyExecuted = "手动上线" WordIs = "为" +WorkflowNotifyTypeCancel = "SQL工单已被关闭" WorkflowNotifyTypeDefault = "SQL工单未知请求" WorkflowNotifyTypeExecuteFail = "SQL工单上线失败" WorkflowNotifyTypeExecuteSuccess = "SQL工单上线成功" diff --git a/sqle/locale/message_zh.go b/sqle/locale/message_zh.go index 230010eac..30e03b1ed 100644 --- a/sqle/locale/message_zh.go +++ b/sqle/locale/message_zh.go @@ -452,6 +452,7 @@ var ( NotifyWorkflowNotifyTypeReject = &i18n.Message{ID: "WorkflowNotifyTypeReject", Other: "SQL工单已被驳回"} NotifyWorkflowNotifyTypeExecuteSuccess = &i18n.Message{ID: "WorkflowNotifyTypeExecuteSuccess", Other: "SQL工单上线成功"} NotifyWorkflowNotifyTypeExecuteFail = &i18n.Message{ID: "WorkflowNotifyTypeExecuteFail", Other: "SQL工单上线失败"} + NotifyWorkflowNotifyTypeCancel = &i18n.Message{ID: "WorkflowNotifyTypeCancel", Other: "SQL工单已被关闭"} NotifyWorkflowNotifyTypeDefault = &i18n.Message{ID: "WorkflowNotifyTypeDefault", Other: "SQL工单未知请求"} NotifyAuditPlanSubject = &i18n.Message{ID: "NotifyAuditPlanSubject", Other: "SQLE扫描任务[%v]扫描结果[%v]"} diff --git a/sqle/notification/notification.go b/sqle/notification/notification.go index ef9c52a18..3aebdaa6f 100644 --- a/sqle/notification/notification.go +++ b/sqle/notification/notification.go @@ -51,6 +51,7 @@ const ( WorkflowNotifyTypeReject WorkflowNotifyTypeExecuteSuccess WorkflowNotifyTypeExecuteFail + WorkflowNotifyTypeCancel ) func getWorkflowNotifyTypeAction(wt WorkflowNotifyType) string { @@ -65,6 +66,8 @@ func getWorkflowNotifyTypeAction(wt WorkflowNotifyType) string { return "exec_success" case WorkflowNotifyTypeExecuteFail: return "exec_failed" + case WorkflowNotifyTypeCancel: + return "cancel" } return "unknown" } @@ -102,6 +105,8 @@ func (w *WorkflowNotification) NotificationSubject() i18nPkg.I18nStr { return locale.Bundle.LocalizeAll(locale.NotifyWorkflowNotifyTypeExecuteSuccess) case WorkflowNotifyTypeExecuteFail: return locale.Bundle.LocalizeAll(locale.NotifyWorkflowNotifyTypeExecuteFail) + case WorkflowNotifyTypeCancel: + return locale.Bundle.LocalizeAll(locale.NotifyWorkflowNotifyTypeCancel) default: return locale.Bundle.LocalizeAll(locale.NotifyWorkflowNotifyTypeDefault) } @@ -207,6 +212,11 @@ func (w *WorkflowNotification) notifyUser() []string { return []string{ w.workflow.CreateUserId, } + // if workflow is cancelled, the creator needs to be notified. + case WorkflowNotifyTypeCancel: + return []string{ + w.workflow.CreateUserId, + } // if workflow is executed, the creator and executor needs to be notified. case WorkflowNotifyTypeExecuteSuccess, WorkflowNotifyTypeExecuteFail: // 获取该工单对应数据源上有工单审核权限的所有用户