From 583214e91acc31998b4d4b43a92f24fba438d18f Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 18 Dec 2018 20:01:59 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E4=BC=98=E5=8C=96=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E8=B5=84=E4=BA=A7api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/common/tree.py | 7 ++----- apps/perms/api.py | 29 +++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/apps/common/tree.py b/apps/common/tree.py index df8da256f..6b57a3db4 100644 --- a/apps/common/tree.py +++ b/apps/common/tree.py @@ -47,16 +47,13 @@ class TreeNode: def __gt__(self, other): if self.isParent and not other.isParent: return False + elif not self.isParent and other.isParent: + return True return self.id > other.id def __eq__(self, other): return self.id == other.id - def __lt__(self, other): - if self.isParent and not other.isParent: - return True - return self.id < other.id - class Tree: def __init__(self): diff --git a/apps/perms/api.py b/apps/perms/api.py index d28fd4f6d..094f90fd5 100644 --- a/apps/perms/api.py +++ b/apps/perms/api.py @@ -228,15 +228,22 @@ class UserGrantedNodesWithAssetsAsTreeApi(ListAPIView): @staticmethod def parse_asset_to_tree_node(node, asset, system_users): system_users_protocol_matched = [s for s in system_users if s.protocol == asset.protocol] - system_user_serializer = serializers.GrantedSystemUserSerializer( - system_users_protocol_matched, many=True - ) - asset_serializer = serializers.GrantedAssetSerializer(asset) icon_skin = 'file' if asset.platform.lower() == 'windows': icon_skin = 'windows' elif asset.platform.lower() == 'linux': icon_skin = 'linux' + system_users = [] + for system_user in system_users_protocol_matched: + system_users.append({ + 'id': system_user.id, + 'name': system_user.name, + 'username': system_user.username, + 'protocol': system_user.protocol, + 'priority': system_user.priority, + 'login_mode': system_user.login_mode, + 'comment': system_user.comment, + }) data = { 'id': str(asset.id), 'name': asset.hostname, @@ -246,9 +253,19 @@ class UserGrantedNodesWithAssetsAsTreeApi(ListAPIView): 'open': False, 'iconSkin': icon_skin, 'meta': { - 'system_users': system_user_serializer.data, + 'system_users': system_users, 'type': 'asset', - 'asset': asset_serializer.data + 'asset': { + 'id': asset.id, + 'hostname': asset.hostname, + 'ip': asset.ip, + 'port': asset.port, + 'protocol': asset.protocol, + 'platform': asset.platform, + 'domain': None if not asset.domain else asset.domain.id, + 'is_active': asset.is_active, + 'comment': asset.comment + }, } } tree_node = TreeNode(**data)