Merge pull request #6555 from jumpserver/pr@dev@user_collection_node_fix

fix: 用户管理-用户-授权的资产-收藏夹下拉菜单报404bug修复
pull/6563/head
feng626 2021-07-28 14:39:53 +08:00 committed by GitHub
commit c1e6bc5d60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 6 deletions

View File

@ -30,7 +30,7 @@ logger = get_logger(__name__)
def get_user_all_asset_perm_ids(user) -> set: def get_user_all_asset_perm_ids(user) -> set:
asset_perm_ids = set() asset_perm_ids = set()
user_perm_id = AssetPermission.users.through.objects\ user_perm_id = AssetPermission.users.through.objects \
.filter(user_id=user.id) \ .filter(user_id=user.id) \
.values_list('assetpermission_id', flat=True) \ .values_list('assetpermission_id', flat=True) \
.distinct() .distinct()
@ -41,8 +41,8 @@ def get_user_all_asset_perm_ids(user) -> set:
.values_list('usergroup_id', flat=True) \ .values_list('usergroup_id', flat=True) \
.distinct() .distinct()
group_ids = list(group_ids) group_ids = list(group_ids)
groups_perm_id = AssetPermission.user_groups.through.objects\ groups_perm_id = AssetPermission.user_groups.through.objects \
.filter(usergroup_id__in=group_ids)\ .filter(usergroup_id__in=group_ids) \
.values_list('assetpermission_id', flat=True) \ .values_list('assetpermission_id', flat=True) \
.distinct() .distinct()
asset_perm_ids.update(groups_perm_id) 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}') logger.info(f'Rebuild user tree: user={self.user} org={current_org}')
utils = UserGrantedTreeBuildUtils(user) utils = UserGrantedTreeBuildUtils(user)
utils.rebuild_user_granted_tree() 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: class UserGrantedUtilsBase:
@ -547,14 +548,16 @@ class UserGrantedNodesQueryUtils(UserGrantedUtilsBase):
if not key: if not key:
return self.get_top_level_nodes() return self.get_top_level_nodes()
nodes = PermNode.objects.none()
if key == PermNode.FAVORITE_NODE_KEY:
return nodes
node = PermNode.objects.get(key=key) node = PermNode.objects.get(key=key)
granted_status = node.get_granted_status(self.user) granted_status = node.get_granted_status(self.user)
if granted_status == NodeFrom.granted: if granted_status == NodeFrom.granted:
nodes = PermNode.objects.filter(parent_key=key) nodes = PermNode.objects.filter(parent_key=key)
elif granted_status in (NodeFrom.asset, NodeFrom.child): elif granted_status in (NodeFrom.asset, NodeFrom.child):
nodes = self.get_indirect_granted_node_children(key) nodes = self.get_indirect_granted_node_children(key)
else:
nodes = PermNode.objects.none()
nodes = self.sort(nodes) nodes = self.sort(nodes)
return nodes return nodes