From 3ef328a5a35bf70713af9aa5b1a1fe7bac5aa8b5 Mon Sep 17 00:00:00 2001 From: richjohnrambo Date: Sun, 20 Sep 2026 22:03:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=9A=90=E8=97=8F=E5=86=85=E7=BD=AE?= =?UTF-8?q?=E8=B6=85=E7=AE=A1=E6=97=B6=E4=BF=9D=E7=95=99=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E6=A0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/internal/logic/admin/role.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/server/internal/logic/admin/role.go b/server/internal/logic/admin/role.go index 1fff050..d671d29 100644 --- a/server/internal/logic/admin/role.go +++ b/server/internal/logic/admin/role.go @@ -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)+"%") }