fix: 全局组织-组织角色用户数量不对

pull/12985/head
wangruidong 2024-04-10 18:12:53 +08:00 committed by Bryan
parent 2b05fd5276
commit 6b5d18222e
1 changed files with 5 additions and 2 deletions

View File

@ -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}