mirror of https://github.com/jumpserver/jumpserver
fix: 授权树节点排序
parent
32df722e9d
commit
9e1c5bb64d
|
@ -488,11 +488,12 @@ class UserGrantedAssetsQueryUtils(UserGrantedUtilsBase):
|
||||||
|
|
||||||
if granted_status == NodeFrom.granted:
|
if granted_status == NodeFrom.granted:
|
||||||
assets = Asset.objects.order_by().filter(nodes__id=node.id)
|
assets = Asset.objects.order_by().filter(nodes__id=node.id)
|
||||||
return assets
|
|
||||||
elif granted_status == NodeFrom.asset:
|
elif granted_status == NodeFrom.asset:
|
||||||
return self._get_indirect_granted_node_assets(node.id)
|
assets = self._get_indirect_granted_node_assets(node.id)
|
||||||
else:
|
else:
|
||||||
return Asset.objects.none()
|
assets = Asset.objects.none()
|
||||||
|
assets = assets.order_by('hostname')
|
||||||
|
return assets
|
||||||
|
|
||||||
def _get_indirect_granted_node_assets(self, id) -> AssetQuerySet:
|
def _get_indirect_granted_node_assets(self, id) -> AssetQuerySet:
|
||||||
assets = Asset.objects.order_by().filter(nodes__id=id).distinct() & self.get_direct_granted_assets()
|
assets = Asset.objects.order_by().filter(nodes__id=id).distinct() & self.get_direct_granted_assets()
|
||||||
|
@ -538,6 +539,10 @@ class UserGrantedAssetsQueryUtils(UserGrantedUtilsBase):
|
||||||
|
|
||||||
|
|
||||||
class UserGrantedNodesQueryUtils(UserGrantedUtilsBase):
|
class UserGrantedNodesQueryUtils(UserGrantedUtilsBase):
|
||||||
|
def sort(self, nodes):
|
||||||
|
nodes = sorted(nodes, key=lambda x: x.value)
|
||||||
|
return nodes
|
||||||
|
|
||||||
def get_node_children(self, key):
|
def get_node_children(self, key):
|
||||||
if not key:
|
if not key:
|
||||||
return self.get_top_level_nodes()
|
return self.get_top_level_nodes()
|
||||||
|
@ -545,11 +550,13 @@ class UserGrantedNodesQueryUtils(UserGrantedUtilsBase):
|
||||||
node = PermNode.objects.get(key=key)
|
node = PermNode.objects.get(key=key)
|
||||||
granted_status = node.get_granted_status(self.user)
|
granted_status = node.get_granted_status(self.user)
|
||||||
if granted_status == NodeFrom.granted:
|
if granted_status == NodeFrom.granted:
|
||||||
return PermNode.objects.filter(parent_key=key)
|
nodes = PermNode.objects.filter(parent_key=key)
|
||||||
elif granted_status in (NodeFrom.asset, NodeFrom.child):
|
elif granted_status in (NodeFrom.asset, NodeFrom.child):
|
||||||
return self.get_indirect_granted_node_children(key)
|
nodes = self.get_indirect_granted_node_children(key)
|
||||||
else:
|
else:
|
||||||
return PermNode.objects.none()
|
nodes = PermNode.objects.none()
|
||||||
|
nodes = self.sort(nodes)
|
||||||
|
return nodes
|
||||||
|
|
||||||
def get_indirect_granted_node_children(self, key):
|
def get_indirect_granted_node_children(self, key):
|
||||||
"""
|
"""
|
||||||
|
@ -571,7 +578,8 @@ class UserGrantedNodesQueryUtils(UserGrantedUtilsBase):
|
||||||
|
|
||||||
def get_top_level_nodes(self):
|
def get_top_level_nodes(self):
|
||||||
nodes = self.get_special_nodes()
|
nodes = self.get_special_nodes()
|
||||||
nodes.extend(self.get_indirect_granted_node_children(''))
|
real_nodes = self.get_indirect_granted_node_children('')
|
||||||
|
nodes.extend(self.sort(real_nodes))
|
||||||
return nodes
|
return nodes
|
||||||
|
|
||||||
def get_ungrouped_node(self):
|
def get_ungrouped_node(self):
|
||||||
|
|
Loading…
Reference in New Issue