【列表中添加默认用户角色】
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)
|
||||
}
|
||||
|
||||
func GetDefaultAuthRole() *AuthRoleRspDto {
|
||||
return &AuthRoleRspDto{Id: int32(USER), Name: "普通用户"}
|
||||
}
|
||||
|
||||
type AuthUserStorageDto struct {
|
||||
UID int32 `json:"uid" form:"uid"`
|
||||
IsAdmin bool `json:"isAdmin" form:"isAdmin"`
|
||||
|
@ -54,14 +54,16 @@ func FindUserInfo(userId int32) *dto.UserRspDto {
|
||||
}
|
||||
rspUser := dto.ConvertFromUserDto(user)
|
||||
roles := QueryAuthRoleByUid(user.ID)
|
||||
if len(roles) == 0 { // 如果没有指派用户时,指定普通用户信息
|
||||
roles = []*model.AuthRole{{ID: int32(dto.USER), Name: "普通用户"}}
|
||||
}
|
||||
rids := make([]int32, len(roles))
|
||||
if len(roles) == 0 { // 如果没有指派用户时,指定普通用户信息
|
||||
rspUser.Roles = append(rspUser.Roles, dto.GetDefaultAuthRole())
|
||||
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)
|
||||
return rspUser
|
||||
@ -110,6 +112,9 @@ func linkUserRole(users []*model.User) []*dto.UserRspDto {
|
||||
userArr := make([]*dto.UserRspDto, un)
|
||||
i := 0
|
||||
for _, u := range userMap {
|
||||
if len(u.Roles) == 0 {
|
||||
u.Roles = append(u.Roles, dto.GetDefaultAuthRole())
|
||||
}
|
||||
userArr[i] = u
|
||||
i++
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user