From 4f4538834a6a6a07bf5d2f2cb0667803d6726e79 Mon Sep 17 00:00:00 2001 From: rainzm Date: Thu, 21 Jan 2021 19:42:39 +0800 Subject: [PATCH] fix(notify): send websocket messages according to language preference --- pkg/cloudcommon/notifyclient/notify.go | 7 +------ pkg/notify/models/notification.go | 8 +++----- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/pkg/cloudcommon/notifyclient/notify.go b/pkg/cloudcommon/notifyclient/notify.go index 77fbb291ea..2982be731b 100644 --- a/pkg/cloudcommon/notifyclient/notify.go +++ b/pkg/cloudcommon/notifyclient/notify.go @@ -536,14 +536,9 @@ func notifyWithChannel(ctx context.Context, p sNotifyParams, channels ...npk.TNo p.recipientId = []string{} p.contacts = []string{} p.channel = c - if c == npk.NotifyByWebConsole { - p.contacts = reps - } else { - p.recipientId = reps - } + p.recipientId = reps rawNotify(ctx, p) } - } func NotifyImportant(recipientId []string, isGroup bool, event string, data jsonutils.JSONObject) { diff --git a/pkg/notify/models/notification.go b/pkg/notify/models/notification.go index 69a0472dd6..6efd667566 100644 --- a/pkg/notify/models/notification.go +++ b/pkg/notify/models/notification.go @@ -81,11 +81,6 @@ func (nm *SNotificationManager) ValidateCreateData(ctx context.Context, userCred if len(input.Tag) == 0 && utils.IsInStringArray(input.Tag, []string{api.NOTIFICATION_TAG_ALERT}) { return input, httperrors.NewInputParameterError("invalid tag") } - // compatible - if len(input.Receivers) != 0 && input.ContactType == api.WEBCONSOLE { - input.Contacts = input.Receivers - input.Receivers = []string{} - } if len(input.Receivers) == 0 { if !userCred.IsAllow(rbacutils.ScopeSystem, api.SERVICE_TYPE, nm.KeywordPlural(), policy.PolicyActionPerform, SendByContact) { return input, httperrors.NewForbiddenError("can't send notification by contact, need receiver") @@ -119,6 +114,9 @@ func (nm *SNotificationManager) ValidateCreateData(ctx context.Context, userCred if idSet.Has(re) || nameSet.Has(re) { continue } + if input.ContactType == api.WEBCONSOLE { + input.Contacts = append(input.Contacts, re) + } if !input.IgnoreNonexistentReceiver { return input, httperrors.NewInputParameterError("no such receiver whose uid is %q", re) }