Feature & Fix for Notify (#7714)

* feat(notify): Add 'get-types' action for ConfigManager

The List interface is only open to administrators,
because we don't want anyone other than administrators
to see the details of the notify configuration.
To let general user to kown available notification channels,
add 'get-types' actions of ConfigManager.

* feat(notify): Check the availability of contact type before creating notification

Creating notification with unconfigured contact type will fail at
sending message. Now, prevent creation in advance.

* feat(notify): Add workwx for NotifyNormal/Important/Critical

* feat(notify): Add Notify about robot in notifyclient

* fix(notify): Init ParentContactType for SSubContact

1. ParentContactType of SSubContact with webconsole type is empty.
2. ParentContactType of others SSubContact is mobile.

* fix(notify): Unverify SSubContact when ParentContactType match

* fix(notify): When no data is initialized, exit directly
This commit is contained in:
Rain Zheng
2020-09-02 16:10:06 +08:00
committed by GitHub
parent 74c8c6bfe2
commit 1ed65ddd1a
7 changed files with 136 additions and 6 deletions
+29
View File
@@ -142,6 +142,7 @@ func NotifyNormal(recipientId []string, isGroup bool, event string, data jsonuti
notify.NotifyByDingTalk,
notify.NotifyByWebConsole,
notify.NotifyByFeishu,
notify.NotifyByWorkwx,
} {
RawNotify(recipientId, isGroup,
c,
@@ -157,6 +158,7 @@ func NotifyImportant(recipientId []string, isGroup bool, event string, data json
notify.NotifyByMobile,
notify.NotifyByWebConsole,
notify.NotifyByFeishu,
notify.NotifyByWorkwx,
} {
RawNotify(recipientId, isGroup,
c,
@@ -172,6 +174,7 @@ func NotifyCritical(recipientId []string, isGroup bool, event string, data jsonu
notify.NotifyByMobile,
notify.NotifyByWebConsole,
notify.NotifyByFeishu,
notify.NotifyByWorkwx,
} {
RawNotify(recipientId, isGroup,
c,
@@ -180,6 +183,32 @@ func NotifyCritical(recipientId []string, isGroup bool, event string, data jsonu
}
}
// NotifyAllWithoutRobot will send messages via all contacnt type from exclude robot contact type such as dingtalk-robot.
func NotifyAllWithoutRobot(recipientId []string, isGroup bool, priority notify.TNotifyPriority, event string, data jsonutils.JSONObject) error {
return notifyRobot("no", recipientId, isGroup, priority, event, data)
}
// NotifyRobot will send messages via all robot contact type such as dingtalk-robot.
func NotifyRobot(recipientId []string, isGroup bool, priority notify.TNotifyPriority, event string, data jsonutils.JSONObject) error {
return notifyRobot("only", recipientId, isGroup, priority, event, data)
}
func notifyRobot(robot string, recipientId []string, isGroup bool, priority notify.TNotifyPriority, event string, data jsonutils.JSONObject) error {
s := auth.GetAdminSession(context.Background(), consts.GetRegion(), "")
params := jsonutils.NewDict()
params.Set("robot", jsonutils.NewString(robot))
result, err := modules.NotifyConfig.PerformClassAction(s, "get-types", params)
if err != nil {
return err
}
jarray, _ := result.Get("types")
cTypes := jarray.(*jsonutils.JSONArray).GetStringArray()
for _, ct := range cTypes {
RawNotify(recipientId, isGroup, notify.TNotifyChannel(ct), priority, event, data)
}
return nil
}
func SystemNotify(priority notify.TNotifyPriority, event string, data jsonutils.JSONObject) {
// userId
Notify(notifyAdminUsers, false, priority, event, data)