|
|
|
@ -6,8 +6,8 @@ from rest_framework.decorators import action
|
|
|
|
|
from rest_framework import generics |
|
|
|
|
from rest_framework.response import Response |
|
|
|
|
from rest_framework_bulk import BulkModelViewSet |
|
|
|
|
from django.db.models import Prefetch |
|
|
|
|
|
|
|
|
|
from common.db.aggregates import GroupConcat |
|
|
|
|
from common.permissions import ( |
|
|
|
|
IsOrgAdmin, IsOrgAdminOrAppUser, |
|
|
|
|
CanUpdateDeleteUser, IsSuperUser |
|
|
|
@ -44,9 +44,18 @@ class UserViewSet(CommonApiMixin, UserQuerysetMixin, BulkModelViewSet):
|
|
|
|
|
extra_filter_backends = [OrgRoleUserFilterBackend] |
|
|
|
|
|
|
|
|
|
def get_queryset(self): |
|
|
|
|
return super().get_queryset().annotate( |
|
|
|
|
gc_m2m_org_members__role=GroupConcat('m2m_org_members__role'), |
|
|
|
|
).prefetch_related('groups') |
|
|
|
|
queryset = super().get_queryset().prefetch_related( |
|
|
|
|
'groups' |
|
|
|
|
) |
|
|
|
|
if current_org.is_real(): |
|
|
|
|
# 为在列表中计算用户在真实组织里的角色 |
|
|
|
|
queryset = queryset.prefetch_related( |
|
|
|
|
Prefetch( |
|
|
|
|
'm2m_org_members', |
|
|
|
|
queryset=OrganizationMember.objects.filter(org__id=current_org.id) |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
return queryset |
|
|
|
|
|
|
|
|
|
def send_created_signal(self, users): |
|
|
|
|
if not isinstance(users, list): |
|
|
|
|