From 864a4c04858e0f7dcd798bd3ae0623b8d3249d4a Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 16 Apr 2020 12:08:52 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[Bugfix]=20=E4=BF=AE=E5=A4=8D=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=9C=AA=E6=8E=88=E6=9D=83=E8=B5=84=E4=BA=A7=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/utils.py | 10 ++++++++-- apps/perms/utils/asset_permission.py | 6 ++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/assets/utils.py b/apps/assets/utils.py index 25e8a46ea..8ec20388b 100644 --- a/apps/assets/utils.py +++ b/apps/assets/utils.py @@ -76,9 +76,15 @@ class TreeService(Tree): ancestor_ids.pop(0) return ancestor_ids - def ancestors(self, nid, with_self=False, deep=False): + def ancestors(self, nid, with_self=False, deep=False, with_assets=True): ancestor_ids = self.ancestors_ids(nid, with_self=with_self) - return [self.get_node(i, deep=deep) for i in ancestor_ids] + ancestors = [self.get_node(i, deep=deep) for i in ancestor_ids] + if with_assets: + return ancestors + for n in ancestors: + n.data['assets'] = set() + n.data['all_assets'] = None + return ancestors def get_node_full_tag(self, nid): ancestors = self.ancestors(nid, with_self=True) diff --git a/apps/perms/utils/asset_permission.py b/apps/perms/utils/asset_permission.py index 792b842af..f4c06c0a7 100644 --- a/apps/perms/utils/asset_permission.py +++ b/apps/perms/utils/asset_permission.py @@ -290,7 +290,7 @@ class AssetPermissionUtil(AssetPermissionUtilCacheMixin): def parse_user_tree_to_full_tree(self, user_tree): """ 经过前面两个动作,用户授权的节点已放到树上,但是树不是完整的, - 这里要讲树构造成一个完整的书 + 这里要讲树构造成一个完整的树 """ # 开始修正user_tree,保证父节点都在树上 root_children = user_tree.children('') @@ -300,7 +300,8 @@ class AssetPermissionUtil(AssetPermissionUtilCacheMixin): if child.identifier.startswith('-'): continue ancestors = self.full_tree.ancestors( - child.identifier, with_self=False, deep=True + child.identifier, with_self=False, deep=True, + with_assets=False, ) if not ancestors: continue @@ -346,6 +347,7 @@ class AssetPermissionUtil(AssetPermissionUtilCacheMixin): self.add_direct_nodes_to_user_tree(user_tree) self.add_single_assets_node_to_user_tree(user_tree) self.parse_user_tree_to_full_tree(user_tree) + print(user_tree.all_assets('2')) self.add_favorite_node_if_need(user_tree) self.set_user_tree_to_cache_if_need(user_tree) self.set_user_tree_to_local(user_tree) From 6a2a0013a891603ea8fbb9f5e2c21be82d58d9c8 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 16 Apr 2020 12:12:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[Update]=20=E5=8E=BB=E6=8E=89debug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/perms/utils/asset_permission.py | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/perms/utils/asset_permission.py b/apps/perms/utils/asset_permission.py index f4c06c0a7..3a1f81a90 100644 --- a/apps/perms/utils/asset_permission.py +++ b/apps/perms/utils/asset_permission.py @@ -347,7 +347,6 @@ class AssetPermissionUtil(AssetPermissionUtilCacheMixin): self.add_direct_nodes_to_user_tree(user_tree) self.add_single_assets_node_to_user_tree(user_tree) self.parse_user_tree_to_full_tree(user_tree) - print(user_tree.all_assets('2')) self.add_favorite_node_if_need(user_tree) self.set_user_tree_to_cache_if_need(user_tree) self.set_user_tree_to_local(user_tree)