def get_queryset(self):
     if getattr(self, 'swagger_fake_view', False):
         return Asset.objects.none()
     user = self.user
     assets = get_user_direct_granted_assets(user)\
         .prefetch_related('platform')\
         .only(*self.only_fields)
     return assets
 def get_data(self, key, user):
     assets, nodes = [], []
     if not key:
         root_nodes = get_top_level_granted_nodes(user)
         nodes.extend(root_nodes)
     elif key == UNGROUPED_NODE_KEY:
         assets = get_user_direct_granted_assets(user)
         assets = assets.prefetch_related('platform')
     elif key == FAVORITE_NODE_KEY:
         assets = FavoriteAsset.get_user_favorite_assets(user)
     else:
         nodes, assets = self.dispatch_get_data(key, user)
     return nodes, assets
    def add_ungrouped_resource(self, data: list, user, asset_perms_id):
        if not settings.PERM_SINGLE_ASSET_TO_UNGROUP_NODE:
            return

        ungrouped_node = get_ungrouped_node(user,
                                            asset_perms_id=asset_perms_id)
        direct_granted_assets = get_user_direct_granted_assets(
            user, asset_perms_id=asset_perms_id).annotate(
                parent_key=Value(ungrouped_node.key, output_field=CharField()
                                 )).prefetch_related('platform')

        data.extend(
            self.serialize_nodes([ungrouped_node], with_asset_amount=True))
        data.extend(self.serialize_assets(direct_granted_assets))
Example #4
0
 def get_queryset(self):
     user = self.user
     assets = get_user_direct_granted_assets(user)\
         .prefetch_related('platform')\
         .only(*self.only_fields)
     return assets