From a70f85e3469c6c4380c5e20ece5ec5a4a240a8af Mon Sep 17 00:00:00 2001 From: Bai Date: Fri, 2 Dec 2022 18:09:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=20ConnectionToken=20S?= =?UTF-8?q?erializer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/acls/models/command_acl.py | 2 ++ apps/authentication/models/connection_token.py | 11 ++++++++--- apps/authentication/serializers/connection_token.py | 7 +++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/apps/acls/models/command_acl.py b/apps/acls/models/command_acl.py index 37ce641f9..30c19a4b3 100644 --- a/apps/acls/models/command_acl.py +++ b/apps/acls/models/command_acl.py @@ -125,6 +125,8 @@ class CommandFilterACL(OrgModelMixin, BaseACL): @classmethod def get_command_groups(cls, user_id=None, user_group_id=None, account=None, asset_id=None, org_id=None): + # Todo: Do + return CommandGroup.objects.all() from assets.models import Account, Asset user_groups = [] diff --git a/apps/authentication/models/connection_token.py b/apps/authentication/models/connection_token.py index b3f5ba981..e987fc48c 100644 --- a/apps/authentication/models/connection_token.py +++ b/apps/authentication/models/connection_token.py @@ -121,26 +121,31 @@ class ConnectionToken(OrgModelMixin, JMSBaseModel): @lazyproperty def account(self): + from assets.models import Account if not self.asset: return None account = self.asset.accounts.filter(name=self.account_name).first() if self.account_name == '@INPUT' or not account: - return { + data = { 'name': self.account_name, 'username': self.input_username, 'secret_type': 'password', 'secret': self.input_secret, - 'su_from': None + 'su_from': None, + 'org_id': self.asset.org_id } + Account(**data) else: - return { + data = { 'name': account.name, 'username': account.username, 'secret_type': account.secret_type, 'secret': account.secret or self.input_secret, 'su_from': account.su_from, + 'org_id': account.org_id } + return Account(**data) @lazyproperty def domain(self): diff --git a/apps/authentication/serializers/connection_token.py b/apps/authentication/serializers/connection_token.py index 30ad46975..3fefbb5af 100644 --- a/apps/authentication/serializers/connection_token.py +++ b/apps/authentication/serializers/connection_token.py @@ -120,8 +120,8 @@ class ConnectionTokenGatewaySerializer(serializers.ModelSerializer): class Meta: model = Asset fields = [ - 'id', 'address', 'port', 'username', - 'password', 'private_key' + 'id', 'address', 'port', + # 'username', 'password', 'private_key' ] @@ -131,8 +131,7 @@ class ConnectionTokenACLCmdGroupSerializer(serializers.ModelSerializer): class Meta: model = CommandGroup fields = [ - 'id', 'type', 'content', 'ignore_case', 'pattern', - 'action', 'date_created', + 'id', 'type', 'content', 'ignore_case', 'pattern' ]