From 66b6a2f62c56578d33bf7b1f1c704652c9b3e53b Mon Sep 17 00:00:00 2001 From: rainzm Date: Thu, 8 Apr 2021 17:19:00 +0800 Subject: [PATCH] feat(notify): exempt the administrator to update the receiver verification --- pkg/notify/models/receiver.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pkg/notify/models/receiver.go b/pkg/notify/models/receiver.go index 89ac973bc9..e023750bc1 100644 --- a/pkg/notify/models/receiver.go +++ b/pkg/notify/models/receiver.go @@ -771,6 +771,7 @@ func (r *SReceiver) ValidateUpdateData(ctx context.Context, userCred mcclient.To func (r *SReceiver) PreUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) { r.SStatusStandaloneResourceBase.PreUpdate(ctx, userCred, query, data) + originEmailEnable, originMobileEnable := r.EnabledEmail, r.EnabledMobile var input api.ReceiverUpdateInput err := data.Unmarshal(&input) if err != nil { @@ -812,6 +813,24 @@ func (r *SReceiver) PreUpdate(ctx context.Context, userCred mcclient.TokenCreden if err != nil { log.Errorf("InsertOrUpdate: %v", err) } + // 管理后台修改联系人,如果修改或者启用手机号和邮箱,无需进行校验 + allowScope := policy.PolicyManager.AllowScope(userCred, api.SERVICE_TYPE, ReceiverManager.KeywordPlural(), policy.PolicyActionCreate) + if allowScope == rbacutils.ScopeSystem { + // 修改并启用 + if len(input.Email) != 0 && input.Email != r.Email && r.EnabledEmail.Bool() { + r.VerifiedEmail = tristate.True + } + if len(mobile) != 0 && mobile != r.Mobile && r.EnabledMobile.Bool() { + r.VerifiedMobile = tristate.True + } + // 从禁用变启用 + if !originEmailEnable.Bool() && r.EnabledEmail.Bool() { + r.VerifiedEmail = tristate.True + } + if !originMobileEnable.Bool() && r.EnabledMobile.Bool() { + r.VerifiedMobile = tristate.True + } + } } func (r *SReceiver) PostUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) {