Skip to content

Commit

Permalink
Touch up #3559 based on post-merge discussions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Apr 3, 2017
1 parent 5169fbe commit 1e70211
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
11 changes: 5 additions & 6 deletions lib/galaxy/webapps/galaxy/api/folder_contents.py
Expand Up @@ -258,8 +258,9 @@ def create( self, trans, encoded_folder_id, payload, **kwd ):
:type extended_metadata: dict
:type payload: dict
:returns: a list of dictionaries containing the id, name, and 'show' url of the new item
:rtype: list
:returns: a dictionary describing the new item if ``from_hda_id`` is supplied or a list of
such dictionaries describing the new items if ``from_hdca_id`` is supplied.
:rtype: object
:raises: ObjectAttributeInvalidException,
InsufficientPermissionsException, ItemAccessibilityException,
Expand All @@ -271,22 +272,20 @@ def create( self, trans, encoded_folder_id, payload, **kwd ):
ldda_message = payload.pop( 'ldda_message', '' )
if ldda_message:
ldda_message = util.sanitize_html.sanitize_html( ldda_message, 'utf-8' )
rvals = []
try:
if from_hda_id:
decoded_hda_id = self.decode_id( from_hda_id )
rvals.append(self._copy_hda_to_library_folder( trans, self.hda_manager, decoded_hda_id, encoded_folder_id_16, ldda_message ))
return self._copy_hda_to_library_folder( trans, self.hda_manager, decoded_hda_id, encoded_folder_id_16, ldda_message )
if from_hdca_id:
decoded_hdca_id = self.decode_id( from_hdca_id )
rvals.extend(self._copy_hdca_to_library_folder( trans, self.hda_manager, decoded_hdca_id, encoded_folder_id_16, ldda_message ))
return self._copy_hdca_to_library_folder( trans, self.hda_manager, decoded_hdca_id, encoded_folder_id_16, ldda_message )
except Exception as exc:
# TODO handle exceptions better within the mixins
if 'not accessible to the current user' in str( exc ) or 'You are not allowed to access this dataset' in str( exc ):
raise exceptions.ItemAccessibilityException( 'You do not have access to the requested item' )
else:
log.exception( exc )
raise exc
return rvals

def __decode_library_content_id( self, trans, encoded_folder_id ):
"""
Expand Down
14 changes: 5 additions & 9 deletions lib/galaxy/webapps/galaxy/api/library_contents.py
Expand Up @@ -183,9 +183,9 @@ def create( self, trans, library_id, payload, **kwd ):
* description: (optional, only if create_type is 'folder')
description of the folder to create
:rtype: list
:returns: a list of dictionaries containing the id, name,
and 'show' url of the new item
:returns: a dictionary describing the new item unless ``from_hdca_id`` is supplied,
in that case a list of such dictionaries is returned.
:rtype: object
"""
if 'create_type' not in payload:
trans.response.status = 400
Expand Down Expand Up @@ -213,15 +213,11 @@ def create( self, trans, library_id, payload, **kwd ):
# are we copying an HDA to the library folder?
# we'll need the id and any message to attach, then branch to that private function
from_hda_id, from_hdca_id, ldda_message = ( payload.pop( 'from_hda_id', None ), payload.pop( 'from_hdca_id', None ), payload.pop( 'ldda_message', '' ) )
log.debug(payload)
if create_type == 'file':
rval = []
if from_hda_id:
rval.append(self._copy_hda_to_library_folder( trans, self.hda_manager, self.decode_id(from_hda_id), real_folder_id, ldda_message ))
return self._copy_hda_to_library_folder( trans, self.hda_manager, self.decode_id(from_hda_id), real_folder_id, ldda_message )
if from_hdca_id:
rval.extend(self._copy_hdca_to_library_folder(trans, self.hda_manager, self.decode_id(from_hdca_id), real_folder_id, ldda_message))
if from_hda_id or from_hdca_id:
return rval
return self._copy_hdca_to_library_folder(trans, self.hda_manager, self.decode_id(from_hdca_id), real_folder_id, ldda_message)

# check for extended metadata, store it and pop it out of the param
# otherwise sanitize_param will have a fit
Expand Down
3 changes: 1 addition & 2 deletions test/api/test_libraries.py
Expand Up @@ -111,8 +111,7 @@ def test_create_dataset_in_folder( self ):
payload = {'from_hda_id': hda_id}
create_response = self._post( "folders/%s/contents" % folder_id, payload )
self._assert_status_code_is( create_response, 200 )
library_datasets = create_response.json()
assert len( library_datasets ) == 1
self._assert_has_keys( create_response.json(), "name", "id" )

def test_create_datasets_in_library_from_collection( self ):
library = self.library_populator.new_private_library( "ForCreateDatasetsFromCollection" )
Expand Down

0 comments on commit 1e70211

Please sign in to comment.