fix(notify): send msg with custom brand (#15791)

This commit is contained in:
屈轩
2023-01-15 13:48:40 +08:00
committed by GitHub
parent 8a270c58a2
commit ae14c430cc
2 changed files with 7 additions and 16 deletions
+7 -3
View File
@@ -96,15 +96,19 @@ func (lt *SLocalTemplateManager) detailsDisplay(resourceType string, details *js
func (lt *SLocalTemplateManager) FillWithTemplate(ctx context.Context, lang string, no notifyv2.SNotification) (params rpcapi.SendParams, err error) {
out, event := rpcapi.SendParams{}, no.Event
rtStr, aStr, resultStr := event.ResourceType(), string(event.Action()), string(event.Result())
dict, err := jsonutils.ParseString(no.Message)
msgObj, err := jsonutils.ParseString(no.Message)
if err != nil {
return out, errors.Wrapf(err, "unable to parse json from %q", no.Message)
}
msg := msgObj.(*jsonutils.JSONDict)
if info, _ := TemplateManager.GetCompanyInfo(ctx); len(info.Name) > 0 {
msg.Set("brand", jsonutils.NewString(info.Name))
}
webhookMsg := jsonutils.NewDict()
webhookMsg.Set("resource_type", jsonutils.NewString(rtStr))
webhookMsg.Set("action", jsonutils.NewString(aStr))
webhookMsg.Set("result", jsonutils.NewString(resultStr))
webhookMsg.Set("resource_details", dict)
webhookMsg.Set("resource_details", msg)
if no.ContactType == api.WEBHOOK {
return rpcapi.SendParams{
Title: no.Event.StringWithDeli("_"),
@@ -130,7 +134,7 @@ func (lt *SLocalTemplateManager) FillWithTemplate(ctx context.Context, lang stri
resultDis = resultStr
}
lt.detailsDisplay(rtStr, dict.(*jsonutils.JSONDict), tag)
lt.detailsDisplay(rtStr, msg, tag)
templateParams := webhookMsg
templateParams.Set("advance_days", jsonutils.NewInt(int64(no.AdvanceDays)))
-13
View File
@@ -132,19 +132,6 @@ type SCompanyInfo struct {
}
func (tm *STemplateManager) GetCompanyInfo(ctx context.Context) (SCompanyInfo, error) {
// fetch copyright and logo
/*session := auth.GetAdminSession(ctx, "", "")
obj, err := yunionagent.Info.Get(session, "info", jsonutils.NewDict())
if err != nil {
return SCompanyInfo{}, err
}
var info SCompanyInfo
err = obj.Unmarshal(&info)
if err != nil {
return SCompanyInfo{}, err
}
return info, nil
*/
return SCompanyInfo{
Name: options.Options.GetPlatformName(appctx.Lang(ctx)),
}, nil