【列表中添加默认用户角色】
This commit is contained in:
parent
a327bea53b
commit
f5a2106634
|
@ -59,6 +59,10 @@ func IsSystemRole(role int32) bool {
|
||||||
return role == int32(ADMIN) || role == int32(USER)
|
return role == int32(ADMIN) || role == int32(USER)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetDefaultAuthRole() *AuthRoleRspDto {
|
||||||
|
return &AuthRoleRspDto{Id: int32(USER), Name: "普通用户"}
|
||||||
|
}
|
||||||
|
|
||||||
type AuthUserStorageDto struct {
|
type AuthUserStorageDto struct {
|
||||||
UID int32 `json:"uid" form:"uid"`
|
UID int32 `json:"uid" form:"uid"`
|
||||||
IsAdmin bool `json:"isAdmin" form:"isAdmin"`
|
IsAdmin bool `json:"isAdmin" form:"isAdmin"`
|
||||||
|
|
|
@ -54,13 +54,15 @@ func FindUserInfo(userId int32) *dto.UserRspDto {
|
||||||
}
|
}
|
||||||
rspUser := dto.ConvertFromUserDto(user)
|
rspUser := dto.ConvertFromUserDto(user)
|
||||||
roles := QueryAuthRoleByUid(user.ID)
|
roles := QueryAuthRoleByUid(user.ID)
|
||||||
if len(roles) == 0 { // 如果没有指派用户时,指定普通用户信息
|
|
||||||
roles = []*model.AuthRole{{ID: int32(dto.USER), Name: "普通用户"}}
|
|
||||||
}
|
|
||||||
rids := make([]int32, len(roles))
|
rids := make([]int32, len(roles))
|
||||||
for i, r := range roles {
|
if len(roles) == 0 { // 如果没有指派用户时,指定普通用户信息
|
||||||
rids[i] = r.ID
|
rspUser.Roles = append(rspUser.Roles, dto.GetDefaultAuthRole())
|
||||||
rspUser.Roles = append(rspUser.Roles, &dto.AuthRoleRspDto{Id: r.ID, Name: r.Name})
|
rids = append(rids, int32(dto.USER))
|
||||||
|
} else {
|
||||||
|
for i, r := range roles {
|
||||||
|
rids[i] = r.ID
|
||||||
|
rspUser.Roles = append(rspUser.Roles, &dto.AuthRoleRspDto{Id: r.ID, Name: r.Name})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 查询权限路径
|
// 查询权限路径
|
||||||
rspUser.Paths = QueryAuthApiPathByRids(rids)
|
rspUser.Paths = QueryAuthApiPathByRids(rids)
|
||||||
|
@ -110,6 +112,9 @@ func linkUserRole(users []*model.User) []*dto.UserRspDto {
|
||||||
userArr := make([]*dto.UserRspDto, un)
|
userArr := make([]*dto.UserRspDto, un)
|
||||||
i := 0
|
i := 0
|
||||||
for _, u := range userMap {
|
for _, u := range userMap {
|
||||||
|
if len(u.Roles) == 0 {
|
||||||
|
u.Roles = append(u.Roles, dto.GetDefaultAuthRole())
|
||||||
|
}
|
||||||
userArr[i] = u
|
userArr[i] = u
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue