details: http://www.bx.psu.edu/hg/galaxy/rev/26f6936f59bf changeset: 3705:26f6936f59bf user: Greg Von Kuster <greg@bx.psu.edu> date: Tue Apr 27 14:35:35 2010 -0400 description: Fixes for viewing and editing tool info. diffstat: lib/galaxy/webapps/community/controllers/admin.py | 5 +- lib/galaxy/webapps/community/controllers/common.py | 3 + lib/galaxy/webapps/community/controllers/tool.py | 40 ++++++----- lib/galaxy/webapps/community/security/__init__.py | 5 + templates/webapps/community/tool/edit_tool.mako | 34 +++++++-- templates/webapps/community/tool/view_tool.mako | 72 ++++++++++++++------- 6 files changed, 105 insertions(+), 54 deletions(-) diffs (289 lines): diff -r 0571bc517c2f -r 26f6936f59bf lib/galaxy/webapps/community/controllers/admin.py --- a/lib/galaxy/webapps/community/controllers/admin.py Tue Apr 27 13:52:26 2010 -0400 +++ b/lib/galaxy/webapps/community/controllers/admin.py Tue Apr 27 14:35:35 2010 -0400 @@ -399,7 +399,7 @@ NameColumn( "Name", key="name", model_class=model.Tool, - link=( lambda item: dict( operation="View Tool", id=item.id, webapp="community" ) ), + link=( lambda item: dict( operation="View Tool", id=item.id, cntrller='admin', webapp="community" ) ), attach_popup=True, filterable="advanced" ), CategoryColumn( "Category", @@ -461,7 +461,8 @@ operation = kwargs['operation'].lower() if operation == "browse": return trans.response.send_redirect( web.url_for( controller='tool', - action='browse_tool', + action='browse_tools', + cntrller='admin', **kwargs ) ) elif operation == "edit tool": return trans.response.send_redirect( web.url_for( controller='common', diff -r 0571bc517c2f -r 26f6936f59bf lib/galaxy/webapps/community/controllers/common.py --- a/lib/galaxy/webapps/community/controllers/common.py Tue Apr 27 13:52:26 2010 -0400 +++ b/lib/galaxy/webapps/community/controllers/common.py Tue Apr 27 14:35:35 2010 -0400 @@ -48,8 +48,11 @@ message='Select a tool to view', status='error' ) ) tool = get_tool( trans, id ) + categories = [ tca.category for tca in tool.categories ] return trans.fill_template( '/webapps/community/tool/view_tool.mako', tool=tool, + categories=categories, + cntrller=cntrller, message=message, status=status ) @web.expose diff -r 0571bc517c2f -r 26f6936f59bf lib/galaxy/webapps/community/controllers/tool.py --- a/lib/galaxy/webapps/community/controllers/tool.py Tue Apr 27 13:52:26 2010 -0400 +++ b/lib/galaxy/webapps/community/controllers/tool.py Tue Apr 27 14:35:35 2010 -0400 @@ -61,7 +61,7 @@ NameColumn( "Name", key="name", model_class=model.Tool, - link=( lambda item: dict( operation="View Tool", id=item.id, webapp="community" ) ), + link=( lambda item: dict( operation="View Tool", id=item.id, cntrller='tool', webapp="community" ) ), attach_popup=True, filterable="advanced" ), CategoryColumn( "Category", @@ -86,6 +86,14 @@ grids.GridAction( "Upload tool", dict( controller='upload', action='upload', type='tool' ) ) ] operations = [ + grids.GridOperation( "Download tool", + condition=( lambda item: not item.deleted ), + allow_multiple=False, + url_args=dict( controller="tool", action="download_tool", cntrller="tool", webapp="community" ) ), + grids.GridOperation( "Upload a new version", + condition=( lambda item: not item.deleted ), + allow_multiple=False, + url_args=dict( controller="common", action="upload_new_tool_version", cntrller="tool", webapp="community" ) ), grids.GridOperation( "Edit information", condition=( lambda item: not item.deleted ), allow_multiple=False, @@ -93,12 +101,8 @@ grids.GridOperation( "Manage categories", condition=( lambda item: not item.deleted ), allow_multiple=False, - url_args=dict( controller="common", action="manage_categories", cntrller="tool", webapp="community" ) ), - grids.GridOperation( "Upload a new version", - condition=( lambda item: not item.deleted ), - allow_multiple=False, - url_args=dict( controller="common", action="upload_new_tool_version", cntrller="tool", webapp="community" ) ), - ] + url_args=dict( controller="common", action="manage_categories", cntrller="tool", webapp="community" ) ) + ] standard_filters = [ grids.GridColumnFilter( "Deleted", args=dict( deleted=True ) ), grids.GridColumnFilter( "All", args=dict( deleted='All' ) ) @@ -129,6 +133,7 @@ if operation == "browse": return trans.response.send_redirect( web.url_for( controller='tool', action='browse_tool', + cntrller='tool', **kwargs ) ) elif operation == "view tool": return trans.response.send_redirect( web.url_for( controller='common', @@ -140,6 +145,10 @@ action='edit_tool', cntrller='tool', **kwargs ) ) + elif operation == "download tool": + return trans.response.send_redirect( web.url_for( controller='tool', + action='download_tool', + **kwargs ) ) # Render the list view return self.tool_list_grid( trans, **kwargs ) @web.expose @@ -152,21 +161,16 @@ message=message, status=status ) @web.expose - def download_tool( self, trans, id=None, **kwd ): + def download_tool( self, trans, **kwd ): params = util.Params( kwd ) - tool = None - # Get the tool - tool = None - if id is not None: - id = trans.app.security.decode_id( id ) - tool = trans.sa_session.query( trans.model.Tool ).get( id ) - if tool is None: + id = params.get( 'id', None ) + if not id: return trans.response.send_redirect( web.url_for( controller='tool', action='browse_tools', - message='Please select a Tool to edit (the tool ID provided was invalid)', + message='Select a tool to download', status='error' ) ) - - trans.response.set_content_type(tool.mimetype) + tool = get_tool( trans, id ) + trans.response.set_content_type( tool.mimetype ) trans.response.headers['Content-Length'] = int( os.stat( tool.file_name ).st_size ) trans.response.headers['Content-Disposition'] = 'attachment; filename=%s' % tool.download_file_name return open( tool.file_name ) diff -r 0571bc517c2f -r 26f6936f59bf lib/galaxy/webapps/community/security/__init__.py --- a/lib/galaxy/webapps/community/security/__init__.py Tue Apr 27 13:52:26 2010 -0400 +++ b/lib/galaxy/webapps/community/security/__init__.py Tue Apr 27 14:35:35 2010 -0400 @@ -163,6 +163,11 @@ self.sa_session.refresh( tool ) for category in categories: self.associate_components( tool=tool, category=category ) + def can_edit_item( self, user, item ): + # We currently assume the current user can edit the item if they are the owner (i.e., they + # uploaded the item), and the item is in a NEW state. + return user and user==item.user and item.is_new() + def get_permitted_actions( filter=None ): '''Utility method to return a subset of RBACAgent's permitted actions''' if filter is None: diff -r 0571bc517c2f -r 26f6936f59bf templates/webapps/community/tool/edit_tool.mako --- a/templates/webapps/community/tool/edit_tool.mako Tue Apr 27 13:52:26 2010 -0400 +++ b/templates/webapps/community/tool/edit_tool.mako Tue Apr 27 14:35:35 2010 -0400 @@ -11,7 +11,7 @@ <%def name="title()">Edit Tool</%def> -<h2>Edit Tool</h2> +<h2>Edit ${tool.name} <em>${tool.description}</em></h2> %if message: ${render_msg( message, status )} @@ -21,15 +21,31 @@ <input type="hidden" name="id" value="${trans.app.security.encode_id( tool.id )}"/> <input type="hidden" name="cntrller" value="${cntrller}"/> <div class="toolForm"> - <div class="toolFormTitle">${tool.name} Version: ${tool.version}</div> + <div class="toolFormTitle">${tool.name} + <a id="tool-${tool.id}-popup" class="popup-arrow" style="display: none;">▼</a> + <div popupmenu="tool-${tool.id}-popup"> + <a class="action-button" href="${h.url_for( controller='tool', action='download_tool', id=trans.app.security.encode_id( tool.id ) )}">Download tool</a> + </div> + </div> <div class="toolFormBody"> - <div class="form-row"> - <label>Description:</label> - <div class="form-row-input"><textarea name="description" rows="5" cols="35">${tool.user_description}</textarea></div> - <div style="clear: both"></div> - </div> - <div class="form-row"> - <input type="submit" class="primary-button" name="edit_tool_button" value="Save"> + <div class="form-row"> + <label>Description:</label> + <div class="form-row-input"><textarea name="description" rows="5" cols="35">${tool.user_description}</textarea></div> + <div style="clear: both"></div> + </div> + <div class="form-row"> + <label>Tool Id:</label> + ${tool.tool_id} + <div style="clear: both"></div> + </div> + <div class="form-row"> + <label>Version:</label> + ${tool.version} + <div style="clear: both"></div> + </div> + <div class="form-row"> + <input type="submit" class="primary-button" name="edit_tool_button" value="Save"> + </div> </div> </div> </form> diff -r 0571bc517c2f -r 26f6936f59bf templates/webapps/community/tool/view_tool.mako --- a/templates/webapps/community/tool/view_tool.mako Tue Apr 27 13:52:26 2010 -0400 +++ b/templates/webapps/community/tool/view_tool.mako Tue Apr 27 14:35:35 2010 -0400 @@ -1,5 +1,12 @@ <%namespace file="/message.mako" import="render_msg" /> +<% + from galaxy.web.framework.helpers import time_ago + + if cntrller in [ 'tool' ]: + can_edit = trans.app.security_agent.can_edit_item( trans.user, tool ) +%> + <%! def inherit(context): if context.get('use_panels'): @@ -11,39 +18,54 @@ <%def name="title()">View Tool</%def> +<h2>View ${tool.name} <em>${tool.description}</em></h2> + %if message: ${render_msg( message, status )} %endif <div class="toolForm"> - <div class="toolFormTitle">${tool.name} <em>${tool.description}</em> ${tool.version} (ID: ${tool.tool_id})</div> + <div class="toolFormTitle">${tool.name} + <a id="tool-${tool.id}-popup" class="popup-arrow" style="display: none;">▼</a> + <div popupmenu="tool-${tool.id}-popup"> + %if cntrller=='admin' or can_edit: + <a class="action-button" href="${h.url_for( controller='common', action='edit_tool', id=trans.app.security.encode_id( tool.id ), cntrller=cntrller )}">Edit tool</a> + %endif + <a class="action-button" href="${h.url_for( controller='tool', action='download_tool', id=trans.app.security.encode_id( tool.id ) )}">Download tool</a> + </div> + </div> <div class="toolFormBody"> - <div class="form-row"> - Uploaded by <a href="${h.url_for(controller='tool', action='user_tools')}">${tool.user.username}</a> on ${tool.create_time.strftime('%B %d, %Y')} - <div style="clear: both"></div> - </div> - <div class="form-row"> - <label>Categories:</label> - %for category in [ tca.category for tca in tool.categories ]: - ${category.name} - %endfor - <div style="clear: both"></div> - </div> - <div class="form-row"> - <label>Description:</label> - ${tool.user_description} - <div style="clear: both"></div> - </div> - <div class="form-row"> - <label>Download:</label> - <a href="${h.url_for(controller='tool', action='download_tool', id=trans.app.security.encode_id( tool.id ))}"><img src="${h.url_for('/static/images/silk/page_white_compressed.png')}"> ${tool.tool_id}_${tool.version}</a> - <div style="clear: both"></div> - </div> - %if trans.user.id == tool.user_id: <div class="form-row"> - <em>This is your tool. You may <a href="${h.url_for(controller='tool', action='edit_tool', id=trans.app.security.encode_id( tool.id ) )}">edit it</a>.</em> + <label>Description:</label> + ${tool.user_description} <div style="clear: both"></div> </div> - %endif + <div class="form-row"> + <label>Tool Id:</label> + ${tool.tool_id} + <div style="clear: both"></div> + </div> + <div class="form-row"> + <label>Version:</label> + ${tool.version} + <div style="clear: both"></div> + </div> + <div class="form-row"> + <label>Uploaded by:</label> + ${tool.user.username} + <div style="clear: both"></div> + </div> + <div class="form-row"> + <label>Date uploaded:</label> + ${time_ago( tool.create_time )} + <div style="clear: both"></div> + </div> + <div class="form-row"> + <label>Categories:</label> + %for category in categories: + ${category.name} + %endfor + <div style="clear: both"></div> + </div> </div> </div>