Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: only mention end users (#13366)
p0nyef9f2166f0c4
diff --git a/backend/component/webhook/manager.go b/backend/component/webhook/manager.goindex 266241e0ce..1ba19fa922 100644--- a/backend/component/webhook/manager.go+++ b/backend/component/webhook/manager.go@@ -305,6 +305,13 @@ func (m *Manager) getWebhookContextFromEvent(ctx context.Context, e *Event, acti}}+ var mentionEndUsers []*store.UserMessage+ for _, u := range mentionUsers {+ if u.Type == api.EndUser {+ mentionEndUsers = append(mentionEndUsers, u)+ }+ }+webhookCtx = webhook.Context{Level: level,ActivityType: string(activityType),@@ -328,7 +335,7 @@ func (m *Manager) getWebhookContextFromEvent(ctx context.Context, e *Event, actiCreatorID: e.Actor.ID,CreatorName: e.Actor.Name,CreatorEmail: e.Actor.Email,- MentionUsers: mentionUsers,+ MentionEndUsers: mentionEndUsers,MentionUsersByPhone: mentions,}if u := e.TaskRunStatusUpdate; u != nil {diff --git a/backend/plugin/webhook/feishu/feishu.go b/backend/plugin/webhook/feishu/feishu.goindex d864f089ee..60b9044073 100644--- a/backend/plugin/webhook/feishu/feishu.go+++ b/backend/plugin/webhook/feishu/feishu.go@@ -103,7 +103,7 @@ type feishuReceiver struct {}func (*feishuReceiver) Post(context webhook.Context) error {- if context.DirectMessage && len(context.MentionUsers) > 0 {+ if context.DirectMessage && len(context.MentionEndUsers) > 0 {postDirectMessage(context)return nil}@@ -125,7 +125,7 @@ func postDirectMessage(webhookCtx webhook.Context) {var errs errorvar emails []string- for _, u := range webhookCtx.MentionUsers {+ for _, u := range webhookCtx.MentionEndUsers {if sent[u.Email] {continue}@@ -137,7 +137,7 @@ func postDirectMessage(webhookCtx webhook.Context) {return errors.Wrapf(err, "failed to get id by email")}- for _, u := range webhookCtx.MentionUsers {+ for _, u := range webhookCtx.MentionEndUsers {if sent[u.Email] {continue}diff --git a/backend/plugin/webhook/slack/slack.go b/backend/plugin/webhook/slack/slack.goindex 45cf8f370d..e26e27ceb3 100644--- a/backend/plugin/webhook/slack/slack.go+++ b/backend/plugin/webhook/slack/slack.go@@ -124,7 +124,7 @@ func GetBlocks(context webhook.Context) []Block {}func (*Receiver) Post(context webhook.Context) error {- if context.DirectMessage && len(context.MentionUsers) > 0 {+ if context.DirectMessage && len(context.MentionEndUsers) > 0 {postDirectMessage(context)return nil}@@ -184,7 +184,7 @@ func postDirectMessage(webhookCtx webhook.Context) {sent := map[string]bool{}if err := common.Retry(ctx, func() error {var errs error- for _, u := range webhookCtx.MentionUsers {+ for _, u := range webhookCtx.MentionEndUsers {if sent[u.Email] {continue}diff --git a/backend/plugin/webhook/webhook.go b/backend/plugin/webhook/webhook.goindex 7f7e5213f4..72f0f2a9a6 100644--- a/backend/plugin/webhook/webhook.go+++ b/backend/plugin/webhook/webhook.go@@ -71,22 +71,23 @@ type Project struct {// Context is the context of webhook.type Context struct {- URL string- Level Level- ActivityType string- Title string- TitleZh string- Description string- Link string- CreatorID int- CreatorName string- CreatorEmail string- CreatedTs int64- Issue *Issue- Stage *Stage- Project *Project- TaskResult *TaskResult- MentionUsers []*store.UserMessage+ URL string+ Level Level+ ActivityType string+ Title string+ TitleZh string+ Description string+ Link string+ CreatorID int+ CreatorName string+ CreatorEmail string+ CreatedTs int64+ Issue *Issue+ Stage *Stage+ Project *Project+ TaskResult *TaskResult+ // End users that should be mentioned.+ MentionEndUsers []*store.UserMessageMentionUsersByPhone []stringDirectMessage booldiff --git a/backend/plugin/webhook/wecom/app.go b/backend/plugin/webhook/wecom/app.goindex d931b2f76a..e2bb8ac8b5 100644--- a/backend/plugin/webhook/wecom/app.go+++ b/backend/plugin/webhook/wecom/app.go@@ -13,6 +13,7 @@ import ("time"lru "github.com/hashicorp/golang-lru/v2"+ "github.com/hashicorp/golang-lru/v2/expirable""github.com/pkg/errors")@@ -120,10 +121,22 @@ func (p *provider) refreshToken(ctx context.Context) error {return nil}-func (p *provider) getUserIDByEmail(ctx context.Context, email string) (string, error) {+func (p *provider) getUserIDByEmail(ctx context.Context, email string) (id string, rerr error) {if id, ok := userIDCache.Get(email); ok {return id, nil}+ if t, ok := notFoundUserCache.Peek(email); ok {+ return "", errors.Errorf("user wasn't found at %v with errcode 46004", t)+ }++ defer func() {+ // errcode 46004 means user not found.+ // we consider the error to be permanent and won't retry+ // for the email for the next 12 hours.+ if rerr != nil && strings.Contains(rerr.Error(), "errcode 46004") {+ notFoundUserCache.Add(email, time.Now())+ }+ }()url, err := url.Parse("https://qyapi.weixin.qq.com/cgi-bin/user/get_userid_by_email")if err != nil {@@ -278,6 +291,8 @@ var userIDCache = func() *lru.Cache[string, string] {return cache}()+var notFoundUserCache = expirable.NewLRU[string, time.Time](100, nil, time.Hour*12)+func getTokenCached(ctx context.Context, c *http.Client, corpID, secret string) (string, error) {tokenCacheLock.Lock()defer tokenCacheLock.Unlock()diff --git a/backend/plugin/webhook/wecom/wecom.go b/backend/plugin/webhook/wecom/wecom.goindex 2e20500c0f..a6a68c5ab5 100644--- a/backend/plugin/webhook/wecom/wecom.go+++ b/backend/plugin/webhook/wecom/wecom.go@@ -70,12 +70,16 @@ func getMessageCard(context webhook.Context) *WebhookMarkdown {}func (r *Receiver) Post(context webhook.Context) error {- if context.DirectMessage && len(context.MentionUsers) > 0 {+ if context.DirectMessage && len(context.MentionEndUsers) > 0 {if r.sendDirectMessage(context) {return nil}}- return r.sendMessage(context)+ err := r.sendMessage(context)+ if err != nil {+ return backoff.Permanent(err)+ }+ return nil}func (*Receiver) sendMessage(context webhook.Context) error {@@ -145,7 +149,7 @@ func (*Receiver) sendDirectMessage(webhookCtx webhook.Context) bool {var errs errorvar users, userEmails []string- for _, u := range webhookCtx.MentionUsers {+ for _, u := range webhookCtx.MentionEndUsers {if sent[u.Email] || notFound[u.Email] {continue}@@ -186,5 +190,5 @@ func (*Receiver) sendDirectMessage(webhookCtx webhook.Context) bool {slog.Warn("failed to send direct message to wecom users", log.BBError(err))}- return len(sent) == len(webhookCtx.MentionUsers)+ return len(sent) == len(webhookCtx.MentionEndUsers)}