diff --git a/src/models/node_role.go b/src/models/node_role.go index 0f4faeae..fdb81217 100644 --- a/src/models/node_role.go +++ b/src/models/node_role.go @@ -7,6 +7,7 @@ type NodeRole struct { RoleId int64 `json:"role_id"` NodePath string `xorm:"<- 'node_path'" json:"node_path"` RoleTxt string `xorm:"-" json:"role_txt"` + Dispname string `xorm:"-" json:"dispname"` } func (nr *NodeRole) Save() error { diff --git a/src/modules/rdb/http/router_node_role.go b/src/modules/rdb/http/router_node_role.go index d04be6c2..29505625 100644 --- a/src/modules/rdb/http/router_node_role.go +++ b/src/modules/rdb/http/router_node_role.go @@ -22,8 +22,24 @@ func rolesUnderNodeGets(c *gin.Context) { dangerous(err) size := len(list) + var usernames []string + for i := 0; i < size; i++ { + usernames = append(usernames, list[i].Username) + } + + users, err := models.UserGetByNames(usernames) + dangerous(err) + + usersMap := make(map[string]models.User) + for i := 0; i < len(users); i++ { + usersMap[users[i].Username] = users[i] + } + for i := 0; i < size; i++ { list[i].RoleTxt = m[list[i].RoleId] + if user, exists := usersMap[list[i].Username]; exists { + list[i].Dispname = user.Dispname + } } renderData(c, gin.H{