fix: 隐藏内置超管时保留角色树
This commit is contained in:
@@ -58,6 +58,14 @@ func isAdminScopeSuper(ctx context.Context, memberId, roleId int64) bool {
|
||||
return value.String() == consts.ImPlatformRoleKey
|
||||
}
|
||||
|
||||
func getSuperRoleId(ctx context.Context) (int64, error) {
|
||||
value, err := dao.AdminRole.Ctx(ctx).Fields(dao.AdminRole.Columns().Id).Where(dao.AdminRole.Columns().Key, consts.SuperRoleKey).Value()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return value.Int64(), nil
|
||||
}
|
||||
|
||||
// Verify 验证权限
|
||||
func (s *sAdminRole) Verify(ctx context.Context, path, method string) bool {
|
||||
var (
|
||||
@@ -90,8 +98,14 @@ func (s *sAdminRole) List(ctx context.Context, in *adminin.RoleListInp) (res *ad
|
||||
pid int64 = 0
|
||||
)
|
||||
|
||||
// 非超管只获取下级角色
|
||||
if !isAdminScopeSuper(ctx, contexts.GetUserId(ctx), contexts.GetRoleId(ctx)) {
|
||||
// 超管隐藏内置根角色,但从内置根角色的子级开始展示角色树。
|
||||
if isAdminScopeSuper(ctx, contexts.GetUserId(ctx), contexts.GetRoleId(ctx)) {
|
||||
pid, err = getSuperRoleId(ctx)
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
pid = contexts.GetRoleId(ctx)
|
||||
mod = mod.WhereLike(dao.AdminRole.Columns().Tree, "%"+tree.GetIdLabel(pid)+"%")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user