Commit 583214e9 authored by ibuler's avatar ibuler

[Update] 优化获取授权资产api

parent 90b77fdb
...@@ -47,16 +47,13 @@ class TreeNode: ...@@ -47,16 +47,13 @@ class TreeNode:
def __gt__(self, other): def __gt__(self, other):
if self.isParent and not other.isParent: if self.isParent and not other.isParent:
return False return False
elif not self.isParent and other.isParent:
return True
return self.id > other.id return self.id > other.id
def __eq__(self, other): def __eq__(self, other):
return self.id == other.id 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: class Tree:
def __init__(self): def __init__(self):
......
...@@ -228,15 +228,22 @@ class UserGrantedNodesWithAssetsAsTreeApi(ListAPIView): ...@@ -228,15 +228,22 @@ class UserGrantedNodesWithAssetsAsTreeApi(ListAPIView):
@staticmethod @staticmethod
def parse_asset_to_tree_node(node, asset, system_users): 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_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' icon_skin = 'file'
if asset.platform.lower() == 'windows': if asset.platform.lower() == 'windows':
icon_skin = 'windows' icon_skin = 'windows'
elif asset.platform.lower() == 'linux': elif asset.platform.lower() == 'linux':
icon_skin = '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 = { data = {
'id': str(asset.id), 'id': str(asset.id),
'name': asset.hostname, 'name': asset.hostname,
...@@ -246,9 +253,19 @@ class UserGrantedNodesWithAssetsAsTreeApi(ListAPIView): ...@@ -246,9 +253,19 @@ class UserGrantedNodesWithAssetsAsTreeApi(ListAPIView):
'open': False, 'open': False,
'iconSkin': icon_skin, 'iconSkin': icon_skin,
'meta': { 'meta': {
'system_users': system_user_serializer.data, 'system_users': system_users,
'type': 'asset', '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) tree_node = TreeNode(**data)
......
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