Commit 3b4db38f authored by ibuler's avatar ibuler

[Update] 添加serializer class避免报错

parent bfd88167
...@@ -24,8 +24,6 @@ class CustomSwaggerAutoSchema(SwaggerAutoSchema): ...@@ -24,8 +24,6 @@ class CustomSwaggerAutoSchema(SwaggerAutoSchema):
if dump_keys[0] == "perms" and dump_keys[1] == "users": if dump_keys[0] == "perms" and dump_keys[1] == "users":
if self.path.find('{id}') < 0: if self.path.find('{id}') < 0:
dump_keys.insert(2, "my") dump_keys.insert(2, "my")
print(self.path)
print(dump_keys)
if action.replace('bulk_', '') == dump_keys[-1]: if action.replace('bulk_', '') == dump_keys[-1]:
dump_keys[-1] = action dump_keys[-1] = action
return super().get_operation_id(tuple(dump_keys)) return super().get_operation_id(tuple(dump_keys))
......
...@@ -16,7 +16,7 @@ from .models import Setting ...@@ -16,7 +16,7 @@ from .models import Setting
from .utils import LDAPUtil from .utils import LDAPUtil
from common.permissions import IsOrgAdmin, IsSuperUser from common.permissions import IsOrgAdmin, IsSuperUser
from common.utils import get_logger from common.utils import get_logger
from .serializers import MailTestSerializer, LDAPTestSerializer from .serializers import MailTestSerializer, LDAPTestSerializer, LDAPUserSerializer
logger = get_logger(__file__) logger = get_logger(__file__)
...@@ -96,6 +96,7 @@ class LDAPTestingAPI(APIView): ...@@ -96,6 +96,7 @@ class LDAPTestingAPI(APIView):
class LDAPUserListApi(generics.ListAPIView): class LDAPUserListApi(generics.ListAPIView):
pagination_class = LimitOffsetPagination pagination_class = LimitOffsetPagination
permission_classes = (IsOrgAdmin,) permission_classes = (IsOrgAdmin,)
serializer_class = LDAPUserSerializer
def get_queryset(self): def get_queryset(self):
util = LDAPUtil() util = LDAPUtil()
...@@ -103,7 +104,7 @@ class LDAPUserListApi(generics.ListAPIView): ...@@ -103,7 +104,7 @@ class LDAPUserListApi(generics.ListAPIView):
users = util.search_user_items() users = util.search_user_items()
except Exception as e: except Exception as e:
users = [] users = []
logger.error(e, exc_info=True) logger.error(e)
# 前端data_table会根据row.id对table.selected值进行操作 # 前端data_table会根据row.id对table.selected值进行操作
for user in users: for user in users:
user['id'] = user['username'] user['id'] = user['username']
......
...@@ -21,4 +21,9 @@ class LDAPTestSerializer(serializers.Serializer): ...@@ -21,4 +21,9 @@ class LDAPTestSerializer(serializers.Serializer):
AUTH_LDAP_START_TLS = serializers.BooleanField(required=False) AUTH_LDAP_START_TLS = serializers.BooleanField(required=False)
class LDAPUserSerializer(serializers.Serializer):
id = serializers.CharField()
username = serializers.CharField()
email = serializers.CharField()
existing = serializers.BooleanField(read_only=True)
...@@ -91,6 +91,8 @@ class CommandViewSet(CommandQueryMixin, viewsets.ModelViewSet): ...@@ -91,6 +91,8 @@ class CommandViewSet(CommandQueryMixin, viewsets.ModelViewSet):
class CommandExportApi(CommandQueryMixin, generics.ListAPIView): class CommandExportApi(CommandQueryMixin, generics.ListAPIView):
serializer_class = SessionCommandSerializer
def list(self, request, *args, **kwargs): def list(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset()) queryset = self.filter_queryset(self.get_queryset())
......
...@@ -19,8 +19,7 @@ from common.permissions import ( ...@@ -19,8 +19,7 @@ from common.permissions import (
from common.mixins import IDInCacheFilterMixin from common.mixins import IDInCacheFilterMixin
from common.utils import get_logger from common.utils import get_logger
from orgs.utils import current_org from orgs.utils import current_org
from ..serializers import UserSerializer, UserPKUpdateSerializer, \ from .. import serializers
UserUpdateGroupSerializer, ChangeUserPasswordSerializer
from ..models import User from ..models import User
from ..signals import post_user_create from ..signals import post_user_create
...@@ -37,7 +36,7 @@ class UserViewSet(IDInCacheFilterMixin, BulkModelViewSet): ...@@ -37,7 +36,7 @@ class UserViewSet(IDInCacheFilterMixin, BulkModelViewSet):
filter_fields = ('username', 'email', 'name', 'id') filter_fields = ('username', 'email', 'name', 'id')
search_fields = filter_fields search_fields = filter_fields
queryset = User.objects.exclude(role=User.ROLE_APP) queryset = User.objects.exclude(role=User.ROLE_APP)
serializer_class = UserSerializer serializer_class = serializers.UserSerializer
permission_classes = (IsOrgAdmin, CanUpdateDeleteSuperUser) permission_classes = (IsOrgAdmin, CanUpdateDeleteSuperUser)
pagination_class = LimitOffsetPagination pagination_class = LimitOffsetPagination
...@@ -102,7 +101,7 @@ class UserViewSet(IDInCacheFilterMixin, BulkModelViewSet): ...@@ -102,7 +101,7 @@ class UserViewSet(IDInCacheFilterMixin, BulkModelViewSet):
class UserChangePasswordApi(generics.RetrieveUpdateAPIView): class UserChangePasswordApi(generics.RetrieveUpdateAPIView):
permission_classes = (IsOrgAdmin,) permission_classes = (IsOrgAdmin,)
queryset = User.objects.all() queryset = User.objects.all()
serializer_class = ChangeUserPasswordSerializer serializer_class = serializers.ChangeUserPasswordSerializer
def perform_update(self, serializer): def perform_update(self, serializer):
user = self.get_object() user = self.get_object()
...@@ -112,13 +111,13 @@ class UserChangePasswordApi(generics.RetrieveUpdateAPIView): ...@@ -112,13 +111,13 @@ class UserChangePasswordApi(generics.RetrieveUpdateAPIView):
class UserUpdateGroupApi(generics.RetrieveUpdateAPIView): class UserUpdateGroupApi(generics.RetrieveUpdateAPIView):
queryset = User.objects.all() queryset = User.objects.all()
serializer_class = UserUpdateGroupSerializer serializer_class = serializers.UserUpdateGroupSerializer
permission_classes = (IsOrgAdmin,) permission_classes = (IsOrgAdmin,)
class UserResetPasswordApi(generics.UpdateAPIView): class UserResetPasswordApi(generics.UpdateAPIView):
queryset = User.objects.all() queryset = User.objects.all()
serializer_class = UserSerializer serializer_class = serializers.UserSerializer
permission_classes = (IsAuthenticated,) permission_classes = (IsAuthenticated,)
def perform_update(self, serializer): def perform_update(self, serializer):
...@@ -133,7 +132,7 @@ class UserResetPasswordApi(generics.UpdateAPIView): ...@@ -133,7 +132,7 @@ class UserResetPasswordApi(generics.UpdateAPIView):
class UserResetPKApi(generics.UpdateAPIView): class UserResetPKApi(generics.UpdateAPIView):
queryset = User.objects.all() queryset = User.objects.all()
serializer_class = UserSerializer serializer_class = serializers.UserSerializer
permission_classes = (IsAuthenticated,) permission_classes = (IsAuthenticated,)
def perform_update(self, serializer): def perform_update(self, serializer):
...@@ -147,7 +146,7 @@ class UserResetPKApi(generics.UpdateAPIView): ...@@ -147,7 +146,7 @@ class UserResetPKApi(generics.UpdateAPIView):
# 废弃 # 废弃
class UserUpdatePKApi(generics.UpdateAPIView): class UserUpdatePKApi(generics.UpdateAPIView):
queryset = User.objects.all() queryset = User.objects.all()
serializer_class = UserPKUpdateSerializer serializer_class = serializers.UserPKUpdateSerializer
permission_classes = (IsCurrentUserOrReadOnly,) permission_classes = (IsCurrentUserOrReadOnly,)
def perform_update(self, serializer): def perform_update(self, serializer):
...@@ -159,7 +158,7 @@ class UserUpdatePKApi(generics.UpdateAPIView): ...@@ -159,7 +158,7 @@ class UserUpdatePKApi(generics.UpdateAPIView):
class UserUnblockPKApi(generics.UpdateAPIView): class UserUnblockPKApi(generics.UpdateAPIView):
queryset = User.objects.all() queryset = User.objects.all()
permission_classes = (IsOrgAdmin,) permission_classes = (IsOrgAdmin,)
serializer_class = UserSerializer serializer_class = serializers.UserSerializer
key_prefix_limit = "_LOGIN_LIMIT_{}_{}" key_prefix_limit = "_LOGIN_LIMIT_{}_{}"
key_prefix_block = "_LOGIN_BLOCK_{}" key_prefix_block = "_LOGIN_BLOCK_{}"
...@@ -174,7 +173,7 @@ class UserUnblockPKApi(generics.UpdateAPIView): ...@@ -174,7 +173,7 @@ class UserUnblockPKApi(generics.UpdateAPIView):
class UserProfileApi(generics.RetrieveAPIView): class UserProfileApi(generics.RetrieveAPIView):
permission_classes = (IsAuthenticated,) permission_classes = (IsAuthenticated,)
serializer_class = UserSerializer serializer_class = serializers.UserSerializer
def get_object(self): def get_object(self):
return self.request.user return self.request.user
...@@ -183,6 +182,7 @@ class UserProfileApi(generics.RetrieveAPIView): ...@@ -183,6 +182,7 @@ class UserProfileApi(generics.RetrieveAPIView):
class UserResetOTPApi(generics.RetrieveAPIView): class UserResetOTPApi(generics.RetrieveAPIView):
queryset = User.objects.all() queryset = User.objects.all()
permission_classes = (IsOrgAdmin,) permission_classes = (IsOrgAdmin,)
serializer_class = serializers.ResetOTPSerializer
def retrieve(self, request, *args, **kwargs): def retrieve(self, request, *args, **kwargs):
user = self.get_object() if kwargs.get('pk') else request.user user = self.get_object() if kwargs.get('pk') else request.user
......
...@@ -4,7 +4,7 @@ from django.utils.translation import ugettext_lazy as _ ...@@ -4,7 +4,7 @@ from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers from rest_framework import serializers
from common.utils import get_signer, validate_ssh_public_key from common.utils import validate_ssh_public_key
from common.mixins import BulkSerializerMixin from common.mixins import BulkSerializerMixin
from common.fields import StringManyToManyField from common.fields import StringManyToManyField
from common.serializers import AdaptedBulkListSerializer from common.serializers import AdaptedBulkListSerializer
...@@ -15,13 +15,11 @@ from ..models import User, UserGroup ...@@ -15,13 +15,11 @@ from ..models import User, UserGroup
__all__ = [ __all__ = [
'UserSerializer', 'UserPKUpdateSerializer', 'UserUpdateGroupSerializer', 'UserSerializer', 'UserPKUpdateSerializer', 'UserUpdateGroupSerializer',
'UserGroupSerializer', 'UserGroupListSerializer', 'UserGroupSerializer', 'UserGroupListSerializer',
'UserGroupUpdateMemberSerializer', 'ChangeUserPasswordSerializer' 'UserGroupUpdateMemberSerializer', 'ChangeUserPasswordSerializer',
'ResetOTPSerializer',
] ]
signer = get_signer()
class UserSerializer(BulkSerializerMixin, serializers.ModelSerializer): class UserSerializer(BulkSerializerMixin, serializers.ModelSerializer):
class Meta: class Meta:
...@@ -139,3 +137,7 @@ class ChangeUserPasswordSerializer(serializers.ModelSerializer): ...@@ -139,3 +137,7 @@ class ChangeUserPasswordSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = User model = User
fields = ['password'] fields = ['password']
class ResetOTPSerializer(serializers.Serializer):
msg = serializers.CharField(read_only=True)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment