fix(perms): 由于组织不对,导致生成或显示授权树错误

pull/4959/head
xinwen 2020-11-06 20:48:18 +08:00 committed by 老广
parent 02b8533ea0
commit 49c17d18b3
2 changed files with 7 additions and 1 deletions

View File

@ -18,6 +18,7 @@ from ...utils.user_asset_permission import (
from assets.models import Asset, FavoriteAsset from assets.models import Asset, FavoriteAsset
from assets.api import SerializeToTreeNodeMixin from assets.api import SerializeToTreeNodeMixin
from orgs.utils import tmp_to_root_org
from ...hands import Node from ...hands import Node
logger = get_logger(__name__) logger = get_logger(__name__)
@ -26,6 +27,7 @@ logger = get_logger(__name__)
class MyGrantedNodesWithAssetsAsTreeApi(SerializeToTreeNodeMixin, ListAPIView): class MyGrantedNodesWithAssetsAsTreeApi(SerializeToTreeNodeMixin, ListAPIView):
permission_classes = (IsValidUser,) permission_classes = (IsValidUser,)
@tmp_to_root_org()
def list(self, request: Request, *args, **kwargs): def list(self, request: Request, *args, **kwargs):
""" """
此算法依赖 UserGrantedMappingNode 此算法依赖 UserGrantedMappingNode

View File

@ -1,5 +1,5 @@
from functools import reduce, wraps from functools import reduce, wraps
from operator import or_, and_ from operator import or_
from uuid import uuid4 from uuid import uuid4
import threading import threading
import inspect import inspect
@ -229,9 +229,13 @@ def set_node_granted_assets_amount(user, node, asset_perms_id=None):
setattr(node, TMP_GRANTED_ASSETS_AMOUNT_FIELD, assets_amount) setattr(node, TMP_GRANTED_ASSETS_AMOUNT_FIELD, assets_amount)
@tmp_to_root_org()
def rebuild_user_mapping_nodes(user): def rebuild_user_mapping_nodes(user):
logger.info(f'>>> {dt_formater(now())} start rebuild {user} mapping nodes') logger.info(f'>>> {dt_formater(now())} start rebuild {user} mapping nodes')
asset_perms_id = get_user_all_assetpermissions_id(user) asset_perms_id = get_user_all_assetpermissions_id(user)
if not asset_perms_id:
# 没有授权直接返回
return
tmp_nodes = compute_tmp_mapping_node_from_perm(user, asset_perms_id) tmp_nodes = compute_tmp_mapping_node_from_perm(user, asset_perms_id)
for _node in tmp_nodes: for _node in tmp_nodes:
set_node_granted_assets_amount(user, _node, asset_perms_id) set_node_granted_assets_amount(user, _node, asset_perms_id)