mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #8379 from yousong/feature/yousong-logger-action
Feature/yousong logger action
This commit is contained in:
@@ -928,6 +928,12 @@ func (dispatcher *DBModelDispatcher) Get(ctx context.Context, idStr string, quer
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if data != nil {
|
||||
if dataDict, ok := data.(*jsonutils.JSONDict); ok {
|
||||
i18nDict := dispatcher.modelManager.GetI18N(ctx, idStr, data)
|
||||
if i18nDict != nil {
|
||||
dataDict.Set("_i18n", i18nDict)
|
||||
}
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -127,6 +127,8 @@ type IModelManager interface {
|
||||
QueryDistinctExtraField(q *sqlchemy.SQuery, field string) (*sqlchemy.SQuery, error)
|
||||
|
||||
GetPagingConfig() *SPagingConfig
|
||||
|
||||
GetI18N(ctx context.Context, idstr string, resObj jsonutils.JSONObject) *jsonutils.JSONDict
|
||||
}
|
||||
|
||||
type IModel interface {
|
||||
|
||||
@@ -359,14 +359,15 @@ func (manager *SModelBaseManager) GetPropertyDistinctField(ctx context.Context,
|
||||
}
|
||||
}
|
||||
|
||||
var res = jsonutils.NewDict()
|
||||
q := im.Query()
|
||||
q, err = ListItemQueryFilters(im, ctx, q, userCred, query, policy.PolicyActionList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var backupQuery = *q
|
||||
|
||||
var (
|
||||
backupQuery = *q
|
||||
res = jsonutils.NewDict()
|
||||
)
|
||||
// query field
|
||||
for i := 0; i < len(fields); i++ {
|
||||
var nq = backupQuery
|
||||
@@ -424,6 +425,10 @@ func (manager *SModelBaseManager) OnCreateFailed(ctx context.Context, userCred m
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *SModelBaseManager) GetI18N(ctx context.Context, idstr string, resObj jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (model *SModelBase) GetId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -76,10 +76,30 @@ func (action *SActionlog) CustomizeCreate(ctx context.Context, userCred mcclient
|
||||
|
||||
func (action *SActionlog) GetI18N(ctx context.Context) *jsonutils.JSONDict {
|
||||
r := jsonutils.NewDict()
|
||||
r.Set("action", jsonutils.NewString(logclient.OpsActionI18nTable.Lookup(ctx, action.Action)))
|
||||
act18 := logclient.OpsActionI18nTable.Lookup(ctx, action.Action)
|
||||
r.Set("action", jsonutils.NewString(act18))
|
||||
return r
|
||||
}
|
||||
|
||||
func (man *SActionlogManager) GetI18N(ctx context.Context, idstr string, resObj jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
if idstr != "distinct-field" {
|
||||
return nil
|
||||
}
|
||||
res := &struct {
|
||||
Action []string `json:"action"`
|
||||
}{}
|
||||
if err := resObj.Unmarshal(res); err != nil {
|
||||
return nil
|
||||
}
|
||||
for i, act := range res.Action {
|
||||
act18 := logclient.OpsActionI18nTable.Lookup(ctx, act)
|
||||
res.Action[i] = act18
|
||||
}
|
||||
robj := jsonutils.Marshal(res)
|
||||
rdict := robj.(*jsonutils.JSONDict)
|
||||
return rdict
|
||||
}
|
||||
|
||||
// Websockets 不再拉取 ActionLog 的消息,因此注释掉如下代码
|
||||
// 可以保留,以便有需求时,再次打开
|
||||
// func (manager *SActionlogManager) OnCreateComplete(ctx context.Context, items []db.IModel, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
|
||||
Reference in New Issue
Block a user