mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
feat(notify,region): improvement of news subscription
This commit is contained in:
@@ -52,6 +52,11 @@ var (
|
||||
ActionExpiredRelease = api.ActionExpiredRelease
|
||||
ActionExecute = api.ActionExecute
|
||||
|
||||
ActionMigrate = api.ActionMigrate
|
||||
ActionCreateBackupServer = api.ActionCreateBackupServer
|
||||
ActionDelBackupServer = api.ActionDelBackupServer
|
||||
ActionSyncStatus = api.ActionSyncStatus
|
||||
|
||||
ActionPendingDelete = api.ActionPendingDelete
|
||||
)
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ func NotifyAllWithoutRobotWithCtx(ctx context.Context, recipientId []string, isG
|
||||
|
||||
// NotifyRobot will send messages via all robot contact type such as dingtalk-robot.
|
||||
func NotifyRobot(robotIds []string, priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) error {
|
||||
return NotifyRobotWithCtx(context.Background(), robotIds, priority, event, data)
|
||||
return NotifyRobotWithCtx(context.Background(), robotIds, priority, event, data)
|
||||
}
|
||||
|
||||
// NotifyRobot will send messages via all robot contact type such as dingtalk-robot.
|
||||
@@ -141,7 +141,7 @@ func NotifyRobotWithCtx(ctx context.Context, robotIds []string, priority npk.TNo
|
||||
event: event,
|
||||
data: data,
|
||||
})
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func SystemNotify(priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) {
|
||||
@@ -221,7 +221,9 @@ type SEventMessage struct {
|
||||
|
||||
type SEventNotifyParam struct {
|
||||
Obj db.IModel
|
||||
ResourceType string
|
||||
Action api.SAction
|
||||
IsFail bool
|
||||
ObjDetailsDecorator func(context.Context, *jsonutils.JSONDict)
|
||||
AdvanceDays int
|
||||
}
|
||||
@@ -247,9 +249,6 @@ func (t *eventTask) Run() {
|
||||
}
|
||||
|
||||
func EventNotify(ctx context.Context, userCred mcclient.TokenCredential, ep SEventNotifyParam) {
|
||||
// disable EventNotify for now
|
||||
return
|
||||
|
||||
ret, err := db.FetchCustomizeColumns(ep.Obj.GetModelManager(), ctx, userCred, jsonutils.NewDict(), []interface{}{ep.Obj}, stringutils2.SSortedStrings{}, false)
|
||||
if err != nil {
|
||||
log.Errorf("unable to FetchCustomizeColumns: %v", err)
|
||||
@@ -263,7 +262,14 @@ func EventNotify(ctx context.Context, userCred mcclient.TokenCredential, ep SEve
|
||||
if ep.ObjDetailsDecorator != nil {
|
||||
ep.ObjDetailsDecorator(ctx, objDetails)
|
||||
}
|
||||
event := api.Event.WithAction(ep.Action).WithResourceType(ep.Obj.GetModelManager().Keyword())
|
||||
rt := ep.ResourceType
|
||||
if len(rt) == 0 {
|
||||
rt = ep.Obj.GetModelManager().Keyword()
|
||||
}
|
||||
event := api.Event.WithAction(ep.Action).WithResourceType(rt)
|
||||
if ep.IsFail {
|
||||
event = event.WithResult(api.ResultFailed)
|
||||
}
|
||||
var (
|
||||
projectId string
|
||||
projectDomainId string
|
||||
@@ -274,6 +280,7 @@ func EventNotify(ctx context.Context, userCred mcclient.TokenCredential, ep SEve
|
||||
projectDomainId = ownerId.GetProjectDomainId()
|
||||
}
|
||||
params := api.NotificationManagerEventNotifyInput{
|
||||
ReceiverIds: []string{userCred.GetUserId()},
|
||||
ResourceDetails: objDetails,
|
||||
Event: event.String(),
|
||||
AdvanceDays: ep.AdvanceDays,
|
||||
|
||||
@@ -212,7 +212,7 @@ func genMsgViaLang(ctx context.Context, p sNotifyParams) ([]npk.SNotifyMessage,
|
||||
var langMap map[language.Tag]*sTarget
|
||||
|
||||
if p.channel == npk.NotifyByRobot {
|
||||
langMap, err = langRobot(ctx, p.robots)
|
||||
langMap, err = langRobot(ctx, p.robots)
|
||||
} else {
|
||||
langMap, err = lang(ctx, p.channel, reIds, p.contacts)
|
||||
if err != nil {
|
||||
@@ -226,7 +226,7 @@ func genMsgViaLang(ctx context.Context, p sNotifyParams) ([]npk.SNotifyMessage,
|
||||
msg := npk.SNotifyMessage{}
|
||||
msg.Uid = t.reIds
|
||||
msg.Priority = p.priority
|
||||
msg.Robots = p.robots
|
||||
msg.Robots = p.robots
|
||||
msg.Contacts = t.contacts
|
||||
msg.ContactType = p.channel
|
||||
topic, _ := getContent(langSuffix, p.event, "title", p.channel, p.data)
|
||||
|
||||
@@ -65,26 +65,26 @@ func getUserLang(uids []string) (map[string]string, error) {
|
||||
}
|
||||
|
||||
func getRobotLang(robots []string) (map[string]string, error) {
|
||||
s, err := AdminSessionGenerator(context.Background(), consts.GetRegion(), "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
robotLang := make(map[string]string)
|
||||
if len(robots) > 0 {
|
||||
params := jsonutils.NewDict()
|
||||
s, err := AdminSessionGenerator(context.Background(), consts.GetRegion(), "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
robotLang := make(map[string]string)
|
||||
if len(robots) > 0 {
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("filter", jsonutils.NewString(fmt.Sprintf("id.in(%s)", strings.Join(robots, ","))))
|
||||
params.Set("scope", jsonutils.NewString("system"))
|
||||
ret, err := modules.NotifyRobot.List(s, params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range ret.Data {
|
||||
id, _ := ret.Data[i].GetString("id")
|
||||
langStr, _ := ret.Data[i].GetString("lang")
|
||||
robotLang[id] = langStr
|
||||
}
|
||||
}
|
||||
return robotLang, nil
|
||||
ret, err := modules.NotifyRobot.List(s, params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range ret.Data {
|
||||
id, _ := ret.Data[i].GetString("id")
|
||||
langStr, _ := ret.Data[i].GetString("lang")
|
||||
robotLang[id] = langStr
|
||||
}
|
||||
}
|
||||
return robotLang, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
Reference in New Issue
Block a user