Unverified Commit 096d4a42 authored by BaiJiangJie's avatar BaiJiangJie Committed by GitHub

Merge pull request #3438 from jumpserver/dev_terminal

[Update] 修改终端注册条件判断逻辑(从 serializer -> view)
parents f3d2e5d1 9b5cb8b0
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
from rest_framework import viewsets, generics from rest_framework import viewsets, generics
from rest_framework import status from rest_framework import status
from rest_framework.response import Response from rest_framework.response import Response
from django.conf import settings
from common.permissions import IsSuperUser, WithBootstrapToken from common.permissions import IsSuperUser, WithBootstrapToken
...@@ -17,6 +18,9 @@ class TerminalViewSet(viewsets.ModelViewSet): ...@@ -17,6 +18,9 @@ class TerminalViewSet(viewsets.ModelViewSet):
queryset = Terminal.objects.filter(is_deleted=False) queryset = Terminal.objects.filter(is_deleted=False)
serializer_class = serializers.TerminalSerializer serializer_class = serializers.TerminalSerializer
permission_classes = [IsSuperUser] permission_classes = [IsSuperUser]
http_method_names = [
'get', 'put', 'patch', 'delete', 'head', 'options', 'trace'
]
class TerminalRegistrationApi(generics.CreateAPIView): class TerminalRegistrationApi(generics.CreateAPIView):
...@@ -29,6 +33,9 @@ class TerminalRegistrationApi(generics.CreateAPIView): ...@@ -29,6 +33,9 @@ class TerminalRegistrationApi(generics.CreateAPIView):
serializer = serializers.TerminalSerializer( serializer = serializers.TerminalSerializer(
data=data, context={'request': request} 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) serializer.is_valid(raise_exception=True)
terminal = serializer.save() terminal = serializer.save()
sa_serializer = serializer.sa_serializer_class(instance=terminal.user) sa_serializer = serializer.sa_serializer_class(instance=terminal.user)
......
...@@ -28,9 +28,6 @@ class TerminalSerializer(serializers.ModelSerializer): ...@@ -28,9 +28,6 @@ class TerminalSerializer(serializers.ModelSerializer):
valid = super().is_valid(raise_exception=raise_exception) valid = super().is_valid(raise_exception=raise_exception)
if not valid: if not valid:
return 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')} data = {'name': self.validated_data.get('name')}
kwargs = {'data': data} kwargs = {'data': data}
if self.instance and self.instance.user: if self.instance and self.instance.user:
......
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