mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
Merge pull request #9980 from rainzm/automated-cherry-pick-of-#9979-upstream-release-3.7
Automated cherry pick of #9979: Send SMS notification for abnormal login
This commit is contained in:
@@ -222,6 +222,7 @@ func NotifyWithTag(ctx context.Context, params SNotifyParams) {
|
||||
}
|
||||
notifyWithChannel(ctx, p,
|
||||
npk.NotifyByEmail,
|
||||
npk.NotifyByMobile,
|
||||
npk.NotifyByDingTalk,
|
||||
npk.NotifyByFeishu,
|
||||
npk.NotifyByWorkwx,
|
||||
|
||||
@@ -256,7 +256,7 @@ func (tm *STemplateManager) NotifyFilter(contactType, topic, msg, lang string) (
|
||||
err = errors.Wrap(err, "db.FetchModelObjects")
|
||||
return
|
||||
}
|
||||
for _, template := range templates {
|
||||
for _, template := range tm.chooseTemplate(contactType, templates) {
|
||||
var title, content string
|
||||
switch template.TemplateType {
|
||||
case api.TEMPLATE_TYPE_TITLE:
|
||||
@@ -282,6 +282,39 @@ func (tm *STemplateManager) NotifyFilter(contactType, topic, msg, lang string) (
|
||||
return
|
||||
}
|
||||
|
||||
func (tm *STemplateManager) chooseTemplate(contactType string, tempaltes []STemplate) []*STemplate {
|
||||
var titleTemplate, contentTemplate *STemplate
|
||||
// contactType first
|
||||
for i := range tempaltes {
|
||||
switch tempaltes[i].TemplateType {
|
||||
case api.TEMPLATE_TYPE_REMOTE:
|
||||
if tempaltes[i].ContactType == contactType {
|
||||
return []*STemplate{&tempaltes[i]}
|
||||
}
|
||||
case api.TEMPLATE_TYPE_TITLE:
|
||||
if tempaltes[i].ContactType == contactType {
|
||||
titleTemplate = &tempaltes[i]
|
||||
} else if titleTemplate == nil {
|
||||
titleTemplate = &tempaltes[i]
|
||||
}
|
||||
case api.TEMPLATE_TYPE_CONTENT:
|
||||
if tempaltes[i].ContactType == contactType {
|
||||
contentTemplate = &tempaltes[i]
|
||||
} else if contentTemplate == nil {
|
||||
contentTemplate = &tempaltes[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
ret := make([]*STemplate, 0, 2)
|
||||
if titleTemplate != nil {
|
||||
ret = append(ret, titleTemplate)
|
||||
}
|
||||
if contentTemplate != nil {
|
||||
ret = append(ret, contentTemplate)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (tm *STemplate) Execute(str string) (string, error) {
|
||||
tem, err := ptem.New("tmp").Parse(tm.Content)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user