From bea5dadbac475b773513fccc94428af3ddd85573 Mon Sep 17 00:00:00 2001 From: BaiJiangJie Date: Fri, 15 Nov 2019 11:56:51 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9=E7=BB=88?= =?UTF-8?q?=E7=AB=AF=E6=B3=A8=E5=86=8C=E6=9D=A1=E4=BB=B6=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=88=E4=BB=8E=20serializer=20->=20view?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/api_v2/terminal.py | 4 ++++ apps/terminal/serializers_v2/terminal.py | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/terminal/api_v2/terminal.py b/apps/terminal/api_v2/terminal.py index bad0aabc9..629fe6115 100644 --- a/apps/terminal/api_v2/terminal.py +++ b/apps/terminal/api_v2/terminal.py @@ -3,6 +3,7 @@ from rest_framework import viewsets, generics from rest_framework import status from rest_framework.response import Response +from django.conf import settings from common.permissions import IsSuperUser, WithBootstrapToken @@ -29,6 +30,9 @@ class TerminalRegistrationApi(generics.CreateAPIView): serializer = serializers.TerminalSerializer( data=data, context={'request': request} ) + if not settings.SECURITY_SERVICE_ACCOUNT_REGISTRATION: + data = {"error": "service account registration disabled"} + return Response(data=data, status=status.HTTP_400_BAD_REQUEST) serializer.is_valid(raise_exception=True) terminal = serializer.save() sa_serializer = serializer.sa_serializer_class(instance=terminal.user) diff --git a/apps/terminal/serializers_v2/terminal.py b/apps/terminal/serializers_v2/terminal.py index 021519564..f4e26b230 100644 --- a/apps/terminal/serializers_v2/terminal.py +++ b/apps/terminal/serializers_v2/terminal.py @@ -28,9 +28,6 @@ class TerminalSerializer(serializers.ModelSerializer): valid = super().is_valid(raise_exception=raise_exception) if not valid: return valid - if not settings.SECURITY_SERVICE_ACCOUNT_REGISTRATION: - error = {"error": "service account registration disabled"} - raise serializers.ValidationError(error) data = {'name': self.validated_data.get('name')} kwargs = {'data': data} if self.instance and self.instance.user: From 9b5cb8b0c553993a3cfe616442c9abfa8d78d438 Mon Sep 17 00:00:00 2001 From: BaiJiangJie Date: Fri, 15 Nov 2019 12:11:58 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[Update]=20=E9=99=90=E5=88=B6=E9=80=9A?= =?UTF-8?q?=E8=BF=87=20POST=20=E6=96=B9=E6=B3=95=E8=B0=83=E7=94=A8=20Termi?= =?UTF-8?q?nalViewSet=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/api_v2/terminal.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/terminal/api_v2/terminal.py b/apps/terminal/api_v2/terminal.py index 629fe6115..57b8ab3e3 100644 --- a/apps/terminal/api_v2/terminal.py +++ b/apps/terminal/api_v2/terminal.py @@ -18,6 +18,9 @@ class TerminalViewSet(viewsets.ModelViewSet): queryset = Terminal.objects.filter(is_deleted=False) serializer_class = serializers.TerminalSerializer permission_classes = [IsSuperUser] + http_method_names = [ + 'get', 'put', 'patch', 'delete', 'head', 'options', 'trace' + ] class TerminalRegistrationApi(generics.CreateAPIView):