From 3805119c4ac5902019802d213cb5b5d6de361577 Mon Sep 17 00:00:00 2001 From: rainzm Date: Wed, 7 Apr 2021 19:16:55 +0800 Subject: [PATCH] fix(notify): exempt the administrator to create the receiver verification --- pkg/notify/models/receiver.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pkg/notify/models/receiver.go b/pkg/notify/models/receiver.go index 57493bbffa..89ac973bc9 100644 --- a/pkg/notify/models/receiver.go +++ b/pkg/notify/models/receiver.go @@ -703,13 +703,6 @@ func (rm *SReceiverManager) OrderByExtraFields(ctx context.Context, q *sqlchemy. func (r *SReceiver) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) { r.SStatusStandaloneResourceBase.PostCreate(ctx, userCred, ownerId, query, data) - // 需求:管理后台新建的联系人,手机号和邮箱无需进行校验 - // 方案:检查请求者对于创建联系人 是否具有system scope - allowScope := policy.PolicyManager.AllowScope(userCred, api.SERVICE_TYPE, ReceiverManager.KeywordPlural(), policy.PolicyActionCreate) - if allowScope == rbacutils.ScopeSystem { - r.VerifiedEmail = tristate.True - r.VerifiedMobile = tristate.True - } // set status r.SetStatus(userCred, api.RECEIVER_STATUS_PULLING, "") logclient.AddActionLogWithContext(ctx, r, logclient.ACT_CREATE, nil, userCred, true) @@ -745,6 +738,17 @@ func (r *SReceiver) CustomizeCreate(ctx context.Context, userCred mcclient.Token if err != nil { return errors.Wrap(err, "PushCache") } + // 需求:管理后台新建的联系人,手机号和邮箱无需进行校验 + // 方案:检查请求者对于创建联系人 是否具有system scope + allowScope := policy.PolicyManager.AllowScope(userCred, api.SERVICE_TYPE, ReceiverManager.KeywordPlural(), policy.PolicyActionCreate) + if allowScope == rbacutils.ScopeSystem { + if r.EnabledEmail.Bool() { + r.VerifiedEmail = tristate.True + } + if r.EnabledMobile.Bool() { + r.VerifiedMobile = tristate.True + } + } return nil }