From 6b5d18222ed7dfa720777398748d6b14c1be38a4 Mon Sep 17 00:00:00 2001 From: wangruidong <940853815@qq.com> Date: Wed, 10 Apr 2024 18:12:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=A8=E5=B1=80=E7=BB=84=E7=BB=87-?= =?UTF-8?q?=E7=BB=84=E7=BB=87=E8=A7=92=E8=89=B2=E7=94=A8=E6=88=B7=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E4=B8=8D=E5=AF=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/rbac/api/role.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/rbac/api/role.py b/apps/rbac/api/role.py index 022a2ac05..2b61b59ec 100644 --- a/apps/rbac/api/role.py +++ b/apps/rbac/api/role.py @@ -79,8 +79,11 @@ class RoleViewSet(JMSModelViewSet): ids = [role.id for role in queryset] queryset = Role.objects.filter(id__in=ids).order_by(*self.ordering) org_id = current_org.id - q = Q(role__scope=Role.Scope.system) | Q(role__scope=Role.Scope.org, org_id=org_id) - role_bindings = RoleBinding.objects.filter(q).values_list('role_id').annotate( + if current_org.is_root(): + q = Q(role__scope=Role.Scope.system) | Q(role__scope=Role.Scope.org) + else: + q = Q(role__scope=Role.Scope.system) | Q(role__scope=Role.Scope.org, org_id=org_id) + role_bindings = RoleBinding.objects_raw.filter(q).values_list('role_id').annotate( user_count=Count('user_id', distinct=True) ) role_user_amount_mapper = {role_id: user_count for role_id, user_count in role_bindings}