diff --git a/pkg/apis/notify/notification.go b/pkg/apis/notify/notification.go index c7b596f919..097b8f4dd7 100644 --- a/pkg/apis/notify/notification.go +++ b/pkg/apis/notify/notification.go @@ -77,6 +77,7 @@ type NotificationDetails struct { Title string `json:"title"` Content string `json:"content"` ReceiveDetails []ReceiveDetail `json:"receive_details"` + TopicType string `json:"topic_type"` } type NotificationListInput struct { diff --git a/pkg/notify/models/notification.go b/pkg/notify/models/notification.go index 3c8e00fa1d..adae4123a0 100644 --- a/pkg/notify/models/notification.go +++ b/pkg/notify/models/notification.go @@ -464,14 +464,45 @@ func (nm *SNotificationManager) FetchCustomizeColumns( resRows := nm.SStatusStandaloneResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList) var err error + notifications := make([]*SNotification, len(objs)) + for i := range notifications { + notifications[i] = objs[i].(*SNotification) + } + // fetch topic_type + eventTopictypes := make(map[string]string) + for i := range notifications { + eventTopictypes[notifications[i].EventId] = "" + } + eventIds := make([]string, 0, len(eventTopictypes)) + for eventId := range eventTopictypes { + eventIds = append(eventIds, eventId) + } + eventSubq := EventManager.Query("topic_id", "id").In("id", eventIds).SubQuery() + topicQ := TopicManager.Query("type") + topicQ = topicQ.Join(eventSubq, sqlchemy.Equals(topicQ.Field("id"), eventSubq.Field("topic_id"))) + topicQ.AppendField(eventSubq.Field("id", "event_id")) + type eventTopictype struct { + EventId string + Type string + } + ets := make([]eventTopictype, 0) + err = topicQ.All(&ets) + if err != nil { + log.Errorf("unable to fetch topic with eventId %s", eventIds) + return rows + } + for i := range ets { + eventTopictypes[ets[i].EventId] = ets[i].Type + } + for i := range rows { - rows[i], err = objs[i].(*SNotification).getMoreDetails(ctx, userCred, query, rows[i]) + rows[i], err = notifications[i].getMoreDetails(ctx, userCred, query, rows[i]) if err != nil { log.Errorf("Notification.getMoreDetails: %v", err) } + rows[i].TopicType = eventTopictypes[notifications[i].EventId] rows[i].StatusStandaloneResourceDetails = resRows[i] } - return rows }