Merge pull request #12559 from rainzm/notify/fix7

fixes for notify
This commit is contained in:
Zexi Li
2021-11-01 10:07:26 +08:00
committed by GitHub
3 changed files with 29 additions and 12 deletions
+19 -7
View File
@@ -308,13 +308,16 @@ func (nm *SNotificationManager) PerformEventNotify(ctx context.Context, userCred
return output, errors.Wrap(err, "unable to create Event")
}
// webconsole
err = nm.create(ctx, userCred, api.WEBCONSOLE, receiverIds, webconsoleContacts.UnsortedList(), input.Priority, event.Id)
if err != nil {
output.FailedList = append(output.FailedList, api.FailedElem{
ContactType: api.WEBCONSOLE,
Reason: err.Error(),
})
if nm.needWebconsole(topics) {
// webconsole
err = nm.create(ctx, userCred, api.WEBCONSOLE, receiverIds, webconsoleContacts.UnsortedList(), input.Priority, event.Id)
if err != nil {
output.FailedList = append(output.FailedList, api.FailedElem{
ContactType: api.WEBCONSOLE,
Reason: err.Error(),
})
}
}
// normal contact type
for _, ct := range contactTypes {
@@ -347,6 +350,15 @@ func (nm *SNotificationManager) PerformEventNotify(ctx context.Context, userCred
return output, nil
}
func (nm *SNotificationManager) needWebconsole(topics []STopic) bool {
for i := range topics {
if topics[i].WebconsoleDisable.IsFalse() {
return true
}
}
return false
}
func (nm *SNotificationManager) createWithWebhookRobots(ctx context.Context, userCred mcclient.TokenCredential, webhookRobotIds []string, priority, eventId string) error {
if len(webhookRobotIds) == 0 {
return nil
+2
View File
@@ -89,6 +89,8 @@ func (rm *SRobotManager) InitializeData() error {
robot.IsPublic = true
robot.PublicScope = string(rbacutils.ScopeSystem)
robot.DomainId = idenapi.DEFAULT_DOMAIN_ID
robot.ProjectId = "system"
robot.ProjectSrc = "local"
robot.Status = api.RECEIVER_STATUS_READY
switch configs[i].Type {
case api.FEISHU_ROBOT:
+8 -5
View File
@@ -71,11 +71,12 @@ type STopic struct {
db.SStandaloneResourceBase
db.SEnabledResourceBase
Type string `width:"20" nullable:"false" create:"required" update:"user" list:"user"`
Resources uint64 `nullable:"false"`
Actions uint32 `nullable:"false"`
Results uint8 `nullable:"false"`
AdvanceDays int `nullable:"false"`
Type string `width:"20" nullable:"false" create:"required" update:"user" list:"user"`
Resources uint64 `nullable:"false"`
Actions uint32 `nullable:"false"`
Results uint8 `nullable:"false"`
AdvanceDays int `nullable:"false"`
WebconsoleDisable tristate.TriState
}
const (
@@ -260,6 +261,7 @@ func (sm *STopicManager) InitializeData() error {
notify.ActionSyncDelete,
)
t.Type = notify.TOPIC_TYPE_RESOURCE
t.WebconsoleDisable = tristate.True
}
if topic == nil {
err := sm.TableSpec().Insert(ctx, t)
@@ -271,6 +273,7 @@ func (sm *STopicManager) InitializeData() error {
topic.Resources = t.Resources
topic.Actions = t.Actions
topic.Type = t.Type
topic.WebconsoleDisable = t.WebconsoleDisable
return nil
})
if err != nil {