Add user dispname under the node
This commit is contained in:
parent
c2867d9638
commit
bad43090ff
|
@ -7,6 +7,7 @@ type NodeRole struct {
|
||||||
RoleId int64 `json:"role_id"`
|
RoleId int64 `json:"role_id"`
|
||||||
NodePath string `xorm:"<- 'node_path'" json:"node_path"`
|
NodePath string `xorm:"<- 'node_path'" json:"node_path"`
|
||||||
RoleTxt string `xorm:"-" json:"role_txt"`
|
RoleTxt string `xorm:"-" json:"role_txt"`
|
||||||
|
Dispname string `xorm:"-" json:"dispname"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nr *NodeRole) Save() error {
|
func (nr *NodeRole) Save() error {
|
||||||
|
|
|
@ -22,8 +22,24 @@ func rolesUnderNodeGets(c *gin.Context) {
|
||||||
dangerous(err)
|
dangerous(err)
|
||||||
|
|
||||||
size := len(list)
|
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++ {
|
for i := 0; i < size; i++ {
|
||||||
list[i].RoleTxt = m[list[i].RoleId]
|
list[i].RoleTxt = m[list[i].RoleId]
|
||||||
|
if user, exists := usersMap[list[i].Username]; exists {
|
||||||
|
list[i].Dispname = user.Dispname
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderData(c, gin.H{
|
renderData(c, gin.H{
|
||||||
|
|
Loading…
Reference in New Issue