From 73ccf3be5fa623e105f363af84cbad54d7e34f03 Mon Sep 17 00:00:00 2001 From: xinwen Date: Sun, 22 Nov 2020 11:06:39 +0800 Subject: [PATCH] =?UTF-8?q?fix(perms):=20=E5=BD=93=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E4=B8=BA=E7=A9=BA=E6=97=B6=EF=BC=8C=E6=B8=85?= =?UTF-8?q?=E7=A9=BA=E6=97=A7=E7=9A=84=E6=8E=88=E6=9D=83=E6=A0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/perms/utils/asset/user_permission.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/perms/utils/asset/user_permission.py b/apps/perms/utils/asset/user_permission.py index 274a27d4d..b3529966d 100644 --- a/apps/perms/utils/asset/user_permission.py +++ b/apps/perms/utils/asset/user_permission.py @@ -215,7 +215,7 @@ def compute_tmp_mapping_node_from_perm(user: User, asset_perms_id=None): return [*leaf_nodes, *ancestors] -def create_mapping_nodes(user, nodes, clear=True): +def create_mapping_nodes(user, nodes): to_create = [] for node in nodes: _granted = getattr(node, TMP_GRANTED_FIELD, False) @@ -231,8 +231,6 @@ def create_mapping_nodes(user, nodes, clear=True): assets_amount=_granted_assets_amount, )) - if clear: - UserGrantedMappingNode.objects.filter(user=user).delete() UserGrantedMappingNode.objects.bulk_create(to_create) @@ -254,6 +252,9 @@ def set_node_granted_assets_amount(user, node, asset_perms_id=None): @tmp_to_root_org() def rebuild_user_mapping_nodes(user): logger.info(f'>>> {dt_formater(now())} start rebuild {user} mapping nodes') + + # 先删除旧的授权树🌲 + UserGrantedMappingNode.objects.filter(user=user).delete() asset_perms_id = get_user_all_assetpermissions_id(user) if not asset_perms_id: # 没有授权直接返回