From ba38771d1a5aef29341e041180bc9b1efea45b90 Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 8 Nov 2022 13:55:06 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BF=AE=E6=94=B9=20applets=20related?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/api/applet/host.py | 5 +++++ apps/terminal/api/applet/relation.py | 3 ++- apps/terminal/serializers/applet_host.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/terminal/api/applet/host.py b/apps/terminal/api/applet/host.py index 1a16c3bba..e5fb1c754 100644 --- a/apps/terminal/api/applet/host.py +++ b/apps/terminal/api/applet/host.py @@ -4,6 +4,7 @@ from rest_framework.response import Response from common.permissions import IsServiceAccount from common.drf.api import JMSModelViewSet +from orgs.utils import tmp_to_builtin_org from terminal.serializers import ( AppletHostSerializer, AppletHostDeploymentSerializer, AppletHostStartupSerializer @@ -19,6 +20,10 @@ class AppletHostViewSet(JMSModelViewSet): serializer_class = AppletHostSerializer queryset = AppletHost.objects.all() + def dispatch(self, request, *args, **kwargs): + with tmp_to_builtin_org(system=1): + return super().dispatch(request, *args, **kwargs) + def get_permissions(self): if self.action == 'startup': return [IsServiceAccount()] diff --git a/apps/terminal/api/applet/relation.py b/apps/terminal/api/applet/relation.py index a613a0197..513be6aab 100644 --- a/apps/terminal/api/applet/relation.py +++ b/apps/terminal/api/applet/relation.py @@ -1,6 +1,7 @@ from typing import Callable from django.shortcuts import get_object_or_404 +from django.conf import settings from rest_framework.request import Request from rest_framework.decorators import action from rest_framework.response import Response @@ -27,7 +28,7 @@ class HostMixin: ) def get_permissions(self): - if self.kwargs.get('host'): + if self.kwargs.get('host') and settings.DEBUG: return [RBACPermission()] else: return [IsServiceAccount()] diff --git a/apps/terminal/serializers/applet_host.py b/apps/terminal/serializers/applet_host.py index e28a4aa59..b94d615c8 100644 --- a/apps/terminal/serializers/applet_host.py +++ b/apps/terminal/serializers/applet_host.py @@ -97,7 +97,7 @@ class AppletHostDeploymentSerializer(serializers.ModelSerializer): class AppletHostAccountSerializer(serializers.ModelSerializer): class Meta: model = Account - fields = ['id', 'username', 'secret', 'date_updated'] + fields = ['id', 'username', 'secret', 'is_active', 'date_updated'] class AppletHostAppletReportSerializer(serializers.Serializer):