Skip to content

Commit

Permalink
expose API to update lib folder;
Browse files Browse the repository at this point in the history
make manager not update when nothing changes
  • Loading branch information
martenson committed Sep 23, 2015
1 parent bab1e3b commit b288104
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/galaxy/managers/folders.py
Expand Up @@ -152,13 +152,13 @@ def update( self, trans, folder, name=None, description=None):
changed = False
if not trans.user_is_admin():
if not self.check_manageable( trans, folder ):
raise InsufficientPermissionsException( "Only admins can update library folders." )
raise InsufficientPermissionsException( "You do not have proper permission to update library folders." )
if folder.deleted == True:
raise ItemAccessibilityException( "You cannot update deleted library folder. Undelete it first." )
if name is not None:
if name is not None and name != folder.name:
folder.name = name
changed = True
if description is not None:
if description is not None and description != folder.description:
folder.description = description
changed = True
if changed:
Expand Down
36 changes: 33 additions & 3 deletions lib/galaxy/webapps/galaxy/api/folders.py
Expand Up @@ -246,7 +246,6 @@ def delete( self, trans, id, **kwd ):
:returns: detailed folder information
:rtype: dictionary
:raises: ItemAccessibilityException, MalformedId, ObjectNotFound
"""
folder = self.folder_manager.get( trans, self.folder_manager.cut_and_decode( trans, id ), True )
undelete = util.string_as_bool( kwd.get( 'undelete', False ) )
Expand All @@ -255,11 +254,42 @@ def delete( self, trans, id, **kwd ):
return folder_dict

@expose_api
def update( self, trans, id, library_id, payload, **kwd ):
def update( self, trans, encoded_folder_id, **kwd ):
"""
PUT /api/folders/{encoded_folder_id}
* PATCH /api/folders/{encoded_folder_id}
Updates the folder defined by an ``encoded_folder_id`` with the data in the payload.
.. note:: Currently, only admin users can update library folders. Also the folder must not be `deleted`.
:param id: the encoded id of the folder
:type id: an encoded id string
:param payload: (required) dictionary structure containing::
'name': new folder's name, cannot be empty
'description': new folder's description
:type payload: dict
:returns: detailed folder information
:rtype: dict
:raises: RequestParameterMissingException
"""
decoded_folder_id = self.folder_manager.cut_and_decode( trans, encoded_folder_id )
folder = self.folder_manager.get( trans, decoded_folder_id )

payload = kwd.get( 'payload', None )
if payload:
name = payload.get( 'name', None )
if not name:
raise exceptions.RequestParameterMissingException( "Parameter 'name' of folder is required. You cannot remove it." )
if payload.get( 'description', None ) or payload.get( 'description', None ) == '':
description = payload.get( 'description', None )
else:
raise exceptions.RequestParameterMissingException( "You did not specify any payload." )
updated_folder = self.folder_manager.update( trans, folder, name, description )
folder_dict = self.folder_manager.get_folder_dict( trans, updated_folder )
return folder_dict

raise exceptions.NotImplemented( 'Updating folder through this endpoint is not implemented yet.' )

# TODO move to Role manager
Expand Down
6 changes: 6 additions & 0 deletions lib/galaxy/webapps/galaxy/buildapp.py
Expand Up @@ -487,6 +487,12 @@ def populate_api_routes( webapp, app ):
action='create',
conditions=dict( method=[ "POST" ] ) )

webapp.mapper.connect( 'update_folder',
'/api/folders/{encoded_folder_id}',
controller='folders',
action='update',
conditions=dict( method=[ "PATCH", "PUT" ] ) )

webapp.mapper.resource( 'folder',
'folders',
path_prefix='/api' )
Expand Down

0 comments on commit b288104

Please sign in to comment.