Add user dispname under the node

This commit is contained in:
710leo 2020-12-31 18:09:42 +08:00
parent c2867d9638
commit bad43090ff
2 changed files with 17 additions and 0 deletions

View File

@ -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 {

View File

@ -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{