Coverage for girder/api/v1/item : 95%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/env python # -*- coding: utf-8 -*-
############################################################################### # Copyright 2013 Kitware Inc. # # Licensed under the Apache License, Version 2.0 ( the "License" ); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ###############################################################################
"""API endpoint for items"""
""" Get a list of items with given search parameters. Currently accepted search modes are:
1. Searching by folderId. 2. Searching with full text search.
To search with full text search, pass the "text" parameter. To search by parent, (i.e. list child items in a folder) pass folderId. You can also pass limit, offset, sort, and sortdir paramters.
:param text: Pass this to perform a full-text search of items. :param folderId: Get child items of a particular folder. :param limit: The result set size limit, default=50. :param offset: Offset into the results, default=0. :param sort: The field to sort by, default=lowerName. :param sortdir: 1 for ascending, -1 for descending, default=1. """
return self.model('item').textSearch( params['text'], {'name': 1}, user=user, limit=limit) level=AccessType.READ, exc=True)
folder=folder, limit=limit, offset=offset, sort=sort)] else: raise RestException('Invalid search mode.') Description('Search for an item by certain properties.') .responseClass('Item') .param('folderId', "Pass this to list all items in a folder.", required=False) .param('text', "Pass this to perform a full text search for items.", required=False) .param('limit', "Result set size limit (default=50).", required=False, dataType='int') .param('offset', "Offset into result set (default=0).", required=False, dataType='int') .param('sort', "Field to sort the item list by (default=name)", required=False) .param('sortdir', "1 for ascending, -1 for descending (default=1)", required=False, dataType='int') .errorResponse() .errorResponse('Read access was denied on the parent folder.', 403))
def getItem(self, item, params): Description('Get an item by ID.') .responseClass('Item') .param('id', 'The ID of the item.', paramType='path') .errorResponse('ID was invalid.') .errorResponse('Read access was denied for the item.', 403))
""" Create a new item.
:param folderId: The _id of the parent folder. :type folderId: str :param name: The name of the item to create. :param description: Item description. """
level=AccessType.WRITE, exc=True)
folder=folder, name=name, creator=user, description=description)
Description('Create a new item.') .responseClass('Item') .param('folderId', 'The ID of the parent folder.') .param('name', 'Name for the item.') .param('description', "Description for the item.", required=False) .errorResponse() .errorResponse('Write access was denied on the parent folder.', 403))
def updateItem(self, item, params): 'description', item['description']).strip()
Description('Edit an item by ID.') .responseClass('Item') .param('id', 'The ID of the item.', paramType='path') .param('name', 'Name for the item.', required=False) .param('description', 'Description for the item', required=False) .errorResponse('ID was invalid.') .errorResponse('Write access was denied for the item.', 403))
def setMetadata(self, item, params): except ValueError: raise RestException('Invalid JSON passed in request body.')
# Make sure we let user know if we can't accept one of their metadata # keys 'contain a period or begin with a ' + 'dollar sign.')
Description('Set metadata fields on an item.') .responseClass('Item') .notes('Set metadata fields to null in order to delete them.') .param('id', 'The ID of the item.', paramType='path') .param('body', 'A JSON object containing the metadata keys to add', paramType='body') .errorResponse('ID was invalid.') .errorResponse('Invalid JSON passed in request body.') .errorResponse('Metadata key name was invalid.') .errorResponse('Write access was denied for the item.', 403))
'attachment; filename="{}{}"'.format(item['name'], '.zip')
.download(file, headers=False), file['name']):
def getFiles(self, item, params): """Get a page of files in an item.""" item=item, limit=limit, offset=offset, sort=sort)] Description('Get the files within an item.') .responseClass('File') .param('id', 'The ID of the item.', paramType='path') .param('limit', "Result set size limit (default=50).", required=False, dataType='int') .param('offset', "Offset into result set (default=0).", required=False, dataType='int') .param('sort', "Field to sort the result list by (default=name)", required=False) .errorResponse('ID was invalid.') .errorResponse('Read access was denied for the item.', 403))
def download(self, item, params): """ Defers to the underlying assetstore adapter to stream the file or file out. """ item=item, limit=2)]
else: Description('Download the contents of an item.') .param('id', 'The ID of the item.', paramType='path') .errorResponse('ID was invalid.') .errorResponse('Read access was denied for the item.', 403))
def deleteItem(self, item, params): """ Delete an item and its contents. """ Description('Delete an item by ID.') .param('id', 'The ID of the item.', paramType='path') .errorResponse('ID was invalid.') .errorResponse('Admin access was denied for the item.', 403))
def rootpath(self, item, params): """ Get the path to the root of the item's parent hierarchy. """ Description('Get the path to the root of the item\'s hierarchy') .param('id', 'The ID of the item', paramType='path') .errorResponse('ID was invalid.') .errorResponse('Read access was denied for the item.', 403)) |