fix: 隐藏内置超管时保留角色树

This commit is contained in:
richjohnrambo
2026-09-20 22:03:51 +08:00
parent 2b93d27a4e
commit 3ef328a5a3
+16 -2
View File
@@ -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)+"%")
}