From 20cc8a124f3823bbace5eca0499e6ce9056c3480 Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 18 Feb 2022 11:24:57 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BF=AE=E6=94=B9connection=20token=20?= =?UTF-8?q?domain?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit perf: 添加 org_id --- apps/applications/models/application.py | 1 - apps/authentication/api/connection_token.py | 2 ++ apps/authentication/serializers.py | 17 ++++++++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/apps/applications/models/application.py b/apps/applications/models/application.py index 17f17c13a..fcde3bdef 100644 --- a/apps/applications/models/application.py +++ b/apps/applications/models/application.py @@ -219,7 +219,6 @@ class Application(CommonModelMixin, OrgModelMixin, ApplicationTreeNodeMixin): verbose_name = _('Application') unique_together = [('org_id', 'name')] ordering = ('name',) - verbose_name = _("Application") def __str__(self): category_display = self.get_category_display() diff --git a/apps/authentication/api/connection_token.py b/apps/authentication/api/connection_token.py index 87bde8380..37c51c10f 100644 --- a/apps/authentication/api/connection_token.py +++ b/apps/authentication/api/connection_token.py @@ -261,6 +261,7 @@ class SecretDetailMixin: 'asset': asset, 'application': application, 'gateway': gateway, + 'domain': domain, 'remote_app': remote_app, } @@ -273,6 +274,7 @@ class SecretDetailMixin: return { 'asset': asset, 'application': None, + 'domain': asset.domain, 'gateway': gateway, 'remote_app': None, } diff --git a/apps/authentication/serializers.py b/apps/authentication/serializers.py index d405e5fb8..61450c363 100644 --- a/apps/authentication/serializers.py +++ b/apps/authentication/serializers.py @@ -5,7 +5,7 @@ from rest_framework import serializers from common.utils import get_object_or_none from users.models import User -from assets.models import Asset, SystemUser, Gateway +from assets.models import Asset, SystemUser, Gateway, Domain from applications.models import Application from users.serializers import UserProfileSerializer from assets.serializers import ProtocolsField @@ -169,7 +169,7 @@ class ConnectionTokenAssetSerializer(serializers.ModelSerializer): class ConnectionTokenSystemUserSerializer(serializers.ModelSerializer): class Meta: model = SystemUser - fields = ['id', 'name', 'username', 'password', 'private_key', 'ad_domain'] + fields = ['id', 'name', 'username', 'password', 'private_key', 'ad_domain', 'org_id'] class ConnectionTokenGatewaySerializer(serializers.ModelSerializer): @@ -185,9 +185,19 @@ class ConnectionTokenRemoteAppSerializer(serializers.Serializer): class ConnectionTokenApplicationSerializer(serializers.ModelSerializer): + attrs = serializers.JSONField(read_only=True) + class Meta: model = Application - fields = ['id', 'name', 'category', 'type'] + fields = ['id', 'name', 'category', 'type', 'attrs', 'org_id'] + + +class ConnectionTokenDomainSerializer(serializers.ModelSerializer): + gateways = ConnectionTokenGatewaySerializer(many=True, read_only=True) + + class Meta: + model = Domain + fields = ['id', 'name', 'gateways'] class ConnectionTokenSecretSerializer(serializers.Serializer): @@ -199,6 +209,7 @@ class ConnectionTokenSecretSerializer(serializers.Serializer): remote_app = ConnectionTokenRemoteAppSerializer(read_only=True) application = ConnectionTokenApplicationSerializer(read_only=True) system_user = ConnectionTokenSystemUserSerializer(read_only=True) + domain = ConnectionTokenDomainSerializer(read_only=True) gateway = ConnectionTokenGatewaySerializer(read_only=True) actions = ActionsField() expired_at = serializers.IntegerField()