[Update] 添加组织详情->组织用户tab页,解决组织详情页面加载超时问题

pull/3973/head
Bai 2020-05-06 15:31:08 +08:00
parent cc30a20b7c
commit aec78dc3c7
4 changed files with 35 additions and 4 deletions

View File

@ -1,14 +1,16 @@
# -*- coding: utf-8 -*-
#
from rest_framework import status
from django.shortcuts import get_object_or_404
from rest_framework import status, generics
from rest_framework.views import Response
from rest_framework_bulk import BulkModelViewSet
from common.permissions import IsSuperUserOrAppUser
from .models import Organization
from .serializers import OrgSerializer, OrgReadSerializer, \
OrgMembershipUserSerializer, OrgMembershipAdminSerializer
OrgMembershipUserSerializer, OrgMembershipAdminSerializer, \
OrgAllUserSerializer
from users.models import User, UserGroup
from assets.models import Asset, Domain, AdminUser, SystemUser, Label
from perms.models import AssetPermission
@ -67,3 +69,15 @@ class OrgMembershipUsersViewSet(OrgMembershipModelViewSetMixin, BulkModelViewSet
membership_class = Organization.users.through
permission_classes = (IsSuperUserOrAppUser, )
class OrgAllUserListApi(generics.ListAPIView):
permission_classes = (IsSuperUserOrAppUser,)
serializer_class = OrgAllUserSerializer
filter_fields = ("username", "name")
search_fields = filter_fields
def get_queryset(self):
pk = self.kwargs.get("pk")
org = get_object_or_404(Organization, pk=pk)
users = org.get_org_users().only(*self.serializer_class.Meta.only_fields)
return users

View File

@ -80,3 +80,15 @@ class OrgMembershipUserSerializer(OrgMembershipSerializerMixin, ModelSerializer)
model = Organization.users.through
list_serializer_class = AdaptedBulkListSerializer
fields = '__all__'
class OrgAllUserSerializer(serializers.Serializer):
user = serializers.UUIDField(read_only=True, source='id')
user_display = serializers.SerializerMethodField()
class Meta:
only_fields = ['id', 'username', 'name']
@staticmethod
def get_user_display(obj):
return str(obj)

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
from django.urls import re_path
from django.urls import re_path, path
from rest_framework.routers import DefaultRouter
from common import api as capi
@ -24,6 +24,7 @@ old_version_urlpatterns = [
]
urlpatterns = [
path('<uuid:pk>/users/all/', api.OrgAllUserListApi.as_view(), name='org-all-users'),
]
urlpatterns += router.urls + old_version_urlpatterns

View File

@ -1,9 +1,13 @@
# -*- coding: utf-8 -*-
#
from .. import utils
from users.models import User
class UserQuerysetMixin:
def get_queryset(self):
queryset = utils.get_current_org_members()
if self.request.query_params.get('all'):
queryset = User.objects.exclude(role=User.ROLE_APP)
else:
queryset = utils.get_current_org_members()
return queryset