mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 06:09:39 +08:00
feat(notify): add WebconsoleDisable for topic
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user