Unverified Commit 62758223 authored by 老广's avatar 老广 Committed by GitHub

Merge pull request #1268 from jumpserver/bufix_for_perm_tree

[Bugfix] 解决上次引入的bug
parents 59eb1f8e 5103dab7
...@@ -108,18 +108,18 @@ class NodeChildrenApi(mixins.ListModelMixin, generics.CreateAPIView): ...@@ -108,18 +108,18 @@ class NodeChildrenApi(mixins.ListModelMixin, generics.CreateAPIView):
return node return node
def get_queryset(self): def get_queryset(self):
queryset = set() queryset = []
query_all = self.request.query_params.get("all") query_all = self.request.query_params.get("all")
query_assets = self.request.query_params.get('assets') query_assets = self.request.query_params.get('assets')
node = self.get_object() node = self.get_object()
if node == Node.root(): if node == Node.root():
queryset.add(node) queryset.append(node)
if query_all: if query_all:
children = node.get_all_children() children = node.get_all_children()
else: else:
children = node.get_children() children = node.get_children()
queryset.update(set(children)) queryset.extend(list(children))
if query_assets: if query_assets:
assets = node.get_assets() assets = node.get_assets()
for asset in assets: for asset in assets:
...@@ -128,7 +128,7 @@ class NodeChildrenApi(mixins.ListModelMixin, generics.CreateAPIView): ...@@ -128,7 +128,7 @@ class NodeChildrenApi(mixins.ListModelMixin, generics.CreateAPIView):
node_fake.parent = node node_fake.parent = node
node_fake.value = asset.hostname node_fake.value = asset.hostname
node_fake.is_node = False node_fake.is_node = False
queryset.add(node_fake) queryset.append(node_fake)
queryset = sorted(queryset, key=lambda x: x.is_node, reverse=True) queryset = sorted(queryset, key=lambda x: x.is_node, reverse=True)
return queryset return queryset
......
...@@ -18,8 +18,7 @@ class NodeTMPSerializer(serializers.ModelSerializer): ...@@ -18,8 +18,7 @@ class NodeTMPSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Node model = Node
fields = ['id', 'key', 'value', 'parent', 'assets_amount', fields = ['id', 'key', 'value', 'parent', 'assets_amount', 'is_node']
'is_asset']
list_serializer_class = BulkListSerializer list_serializer_class = BulkListSerializer
@staticmethod @staticmethod
......
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