def list(self, request: Request, *args, **kwargs): """ 此算法依赖 UserGrantedMappingNode 获取所有授权的节点和资产 Node = UserGrantedMappingNode + 授权节点的子节点 Asset = 授权节点的资产 + 直接授权的资产 """ user = request.user data = [] asset_perms_id = get_user_all_assetpermissions_id(user) system_user_id = request.query_params.get('system_user') if system_user_id: asset_perms_id = list(AssetPermission.objects.valid().filter( id__in=asset_perms_id, system_users__id=system_user_id, actions__gt=0).values_list('id', flat=True).distinct()) self.add_ungrouped_resource(data, user, asset_perms_id) self.add_favorite_resource(data, user, asset_perms_id) if system_user_id: self.add_node_filtered_by_system_user(data, user, asset_perms_id) else: rebuild_user_tree_if_need(request, user) all_nodes = get_user_granted_nodes_list_via_mapping_node(user) data.extend(self.serialize_nodes(all_nodes, with_asset_amount=True)) self.add_assets(data, user, asset_perms_id) return Response(data=data)
def list(self, request: Request, *args, **kwargs): key = self.request.query_params.get('key') if key is None: key = self.id2key_if_have() user = self.user rebuild_user_tree_if_need(request, user) nodes, assets = self.get_data(key, user) tree_nodes = self.serialize_nodes(nodes, with_asset_amount=True) tree_assets = self.serialize_assets(assets, key) return Response(data=[*tree_nodes, *tree_assets])
def list(self, request: Request, *args, **kwargs): """ 此算法依赖 UserGrantedMappingNode 获取所有授权的节点和资产 Node = UserGrantedMappingNode + 授权节点的子节点 Asset = 授权节点的资产 + 直接授权的资产 """ user = request.user rebuild_user_tree_if_need(request, user) all_nodes = get_user_granted_nodes_list_via_mapping_node(user) all_assets = get_user_granted_all_assets(user) all_assets = all_assets.annotate(parent_key=F('nodes__key')) all_assets = all_assets.prefetch_related('platform') data = [ *self.serialize_nodes(all_nodes, with_asset_amount=True), *self.serialize_assets(all_assets) ] return Response(data=data)
def list(self, request: Request, *args, **kwargs): rebuild_user_tree_if_need(request, self.user) nodes = self.get_nodes() nodes = self.serialize_nodes(nodes, with_asset_amount=True) return Response(data=nodes)
def list(self, request, *args, **kwargs): rebuild_user_tree_if_need(request, self.user) nodes = self.get_nodes() serializer = self.get_serializer(nodes, many=True) return Response(serializer.data)