From d0680c375358dc2a02c27a1a24c7e0c27328dcd1 Mon Sep 17 00:00:00 2001 From: feng626 <1304903146@qq.com> Date: Wed, 28 Jul 2021 14:21:53 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86?= =?UTF-8?q?-=E7=94=A8=E6=88=B7-=E6=8E=88=E6=9D=83=E7=9A=84=E8=B5=84?= =?UTF-8?q?=E4=BA=A7-=E6=94=B6=E8=97=8F=E5=A4=B9=E4=B8=8B=E6=8B=89?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=8A=A5404bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/perms/utils/asset/user_permission.py | 25 ++++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/apps/perms/utils/asset/user_permission.py b/apps/perms/utils/asset/user_permission.py index 7f3a0941f..24b0e8eab 100644 --- a/apps/perms/utils/asset/user_permission.py +++ b/apps/perms/utils/asset/user_permission.py @@ -30,7 +30,7 @@ logger = get_logger(__name__) def get_user_all_asset_perm_ids(user) -> set: asset_perm_ids = set() - user_perm_id = AssetPermission.users.through.objects\ + user_perm_id = AssetPermission.users.through.objects \ .filter(user_id=user.id) \ .values_list('assetpermission_id', flat=True) \ .distinct() @@ -41,8 +41,8 @@ def get_user_all_asset_perm_ids(user) -> set: .values_list('usergroup_id', flat=True) \ .distinct() group_ids = list(group_ids) - groups_perm_id = AssetPermission.user_groups.through.objects\ - .filter(usergroup_id__in=group_ids)\ + groups_perm_id = AssetPermission.user_groups.through.objects \ + .filter(usergroup_id__in=group_ids) \ .values_list('assetpermission_id', flat=True) \ .distinct() asset_perm_ids.update(groups_perm_id) @@ -203,7 +203,8 @@ class UserGrantedTreeRefreshController: logger.info(f'Rebuild user tree: user={self.user} org={current_org}') utils = UserGrantedTreeBuildUtils(user) utils.rebuild_user_granted_tree() - logger.info(f'Rebuild user tree ok: cost={time.time() - t_start} user={self.user} org={current_org}') + logger.info( + f'Rebuild user tree ok: cost={time.time() - t_start} user={self.user} org={current_org}') class UserGrantedUtilsBase: @@ -547,14 +548,14 @@ class UserGrantedNodesQueryUtils(UserGrantedUtilsBase): if not key: return self.get_top_level_nodes() - node = PermNode.objects.get(key=key) - granted_status = node.get_granted_status(self.user) - if granted_status == NodeFrom.granted: - nodes = PermNode.objects.filter(parent_key=key) - elif granted_status in (NodeFrom.asset, NodeFrom.child): - nodes = self.get_indirect_granted_node_children(key) - else: - nodes = PermNode.objects.none() + nodes = PermNode.objects.none() + if key != PermNode.FAVORITE_NODE_KEY: + node = PermNode.objects.get(key=key) + granted_status = node.get_granted_status(self.user) + if granted_status == NodeFrom.granted: + nodes = PermNode.objects.filter(parent_key=key) + elif granted_status in (NodeFrom.asset, NodeFrom.child): + nodes = self.get_indirect_granted_node_children(key) nodes = self.sort(nodes) return nodes From da588ce0ae651b0b9a53e12f5d29850553b253b2 Mon Sep 17 00:00:00 2001 From: feng626 <1304903146@qq.com> Date: Wed, 28 Jul 2021 14:33:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?perf:=20=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/perms/utils/asset/user_permission.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/perms/utils/asset/user_permission.py b/apps/perms/utils/asset/user_permission.py index 24b0e8eab..b91039dcc 100644 --- a/apps/perms/utils/asset/user_permission.py +++ b/apps/perms/utils/asset/user_permission.py @@ -549,13 +549,15 @@ class UserGrantedNodesQueryUtils(UserGrantedUtilsBase): return self.get_top_level_nodes() nodes = PermNode.objects.none() - if key != PermNode.FAVORITE_NODE_KEY: - node = PermNode.objects.get(key=key) - granted_status = node.get_granted_status(self.user) - if granted_status == NodeFrom.granted: - nodes = PermNode.objects.filter(parent_key=key) - elif granted_status in (NodeFrom.asset, NodeFrom.child): - nodes = self.get_indirect_granted_node_children(key) + if key == PermNode.FAVORITE_NODE_KEY: + return nodes + + node = PermNode.objects.get(key=key) + granted_status = node.get_granted_status(self.user) + if granted_status == NodeFrom.granted: + nodes = PermNode.objects.filter(parent_key=key) + elif granted_status in (NodeFrom.asset, NodeFrom.child): + nodes = self.get_indirect_granted_node_children(key) nodes = self.sort(nodes) return nodes