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

[Update] 修改获取资产时使用in (#3053)

parent c706a410
...@@ -213,10 +213,10 @@ class NodeUtil: ...@@ -213,10 +213,10 @@ class NodeUtil:
children.add(node) children.add(node)
return list(children) return list(children)
def get_children(self, node, with_self=True): def get_all_children(self, node, with_self=True):
return self.get_all_children_by_key(node.key, with_self=with_self) return self.get_all_children_by_key(node.key, with_self=with_self)
def get_children_keys_by_key(self, key, with_self=True): def get_all_children_keys_by_key(self, key, with_self=True):
nodes = self.get_all_children_by_key(key, with_self=with_self) nodes = self.get_all_children_by_key(key, with_self=with_self)
return [n.key for n in nodes] return [n.key for n in nodes]
......
...@@ -449,6 +449,8 @@ class AssetPermissionUtil(AssetPermissionCacheMixin): ...@@ -449,6 +449,8 @@ class AssetPermissionUtil(AssetPermissionCacheMixin):
self._nodes = None self._nodes = None
self._assets_direct = None self._assets_direct = None
self._nodes_direct = None self._nodes_direct = None
self.node_util = NodeUtil()
self.tree._node_util = self.node_util
@staticmethod @staticmethod
def change_org_if_need(): def change_org_if_need():
...@@ -491,13 +493,14 @@ class AssetPermissionUtil(AssetPermissionCacheMixin): ...@@ -491,13 +493,14 @@ class AssetPermissionUtil(AssetPermissionCacheMixin):
self.tree.add_nodes(nodes_keys) self.tree.add_nodes(nodes_keys)
pattern = set() all_nodes_keys = set()
for key in nodes_keys: for key in nodes_keys:
pattern.add(r'^{0}$|^{0}:'.format(key)) children_keys = self.node_util.get_all_children_keys_by_key(key)
pattern = '|'.join(list(pattern)) all_nodes_keys.update(set(children_keys))
if pattern:
if all_nodes_keys:
assets_ids = Asset.objects.filter( assets_ids = Asset.objects.filter(
nodes__key__regex=pattern nodes__key__in=all_nodes_keys
).valid().values_list("id", flat=True).distinct() ).valid().values_list("id", flat=True).distinct()
else: else:
assets_ids = [] assets_ids = []
......
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