feat(notify): add WebconsoleDisable for topic

This commit is contained in:
rainzm
2021-10-29 19:33:15 +08:00
parent 123cd0addc
commit 2a3dccfe15
2 changed files with 27 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
+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 {