【列表中添加默认用户角色】

This commit is contained in:
weizhihong 2023-09-01 17:44:49 +08:00
parent a327bea53b
commit f5a2106634
2 changed files with 15 additions and 6 deletions

View File

@ -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"`

View File

@ -54,13 +54,15 @@ 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))
for i, r := range roles {
rids[i] = r.ID
rspUser.Roles = append(rspUser.Roles, &dto.AuthRoleRspDto{Id: r.ID, Name: r.Name})
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)
@ -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++
}