Merge pull request #10668 from rainzm/automated-cherry-pick-of-#10667-upstream-release-3.7

Automated cherry pick of #10667: feat(notify): exempt the administrator to update the receiver verification
This commit is contained in:
Zexi Li
2021-04-09 17:03:20 +08:00
committed by GitHub

View File

@@ -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) {