[hg] galaxy 3081: Added ability for administrators to edit regis...
details: http://www.bx.psu.edu/hg/galaxy/rev/89276f68513a changeset: 3081:89276f68513a user: Enis Afgan <afgane@gmail.com> date: Tue Nov 03 13:20:26 2009 -0500 description: Added ability for administrators to edit registered machine image values. diffstat: lib/galaxy/web/controllers/cloud.py | 54 +++++++++++++++++++++++---- templates/cloud/configure_cloud.mako | 10 +---- templates/cloud/edit_image.mako | 64 ++++++++++++++++++++++++++++++++ templates/cloud/list_images.mako | 12 ++++-- 4 files changed, 119 insertions(+), 21 deletions(-) diffs (204 lines): diff -r b7857b33dbd8 -r 89276f68513a lib/galaxy/web/controllers/cloud.py --- a/lib/galaxy/web/controllers/cloud.py Mon Nov 02 17:11:03 2009 -0500 +++ b/lib/galaxy/web/controllers/cloud.py Tue Nov 03 13:20:26 2009 -0500 @@ -350,16 +350,17 @@ "<br />Note: you will be able to add more storage later", value='', error=vol_error ) ) @web.expose - #@web.require_login( "add a cloud image" ) @web.require_admin def addNewImage( self, trans, image_id='', manifest='', state=None ): - error = None + id_error = None + manifest_error = None if image_id: - if len( image_id ) > 255: - error = "Image ID name exceeds maximum allowable length." + if image_id=='' or len( image_id ) > 255: + id_error = "Image ID must be between 1 and 255 characters long." elif trans.app.model.CloudUserCredentials.filter( trans.app.model.CloudImage.table.c.image_id==image_id ).first(): - error = "Image with that ID is already registered." + id_error = "Image with ID '" + image_id + "' is already registered. \ + Please choose another ID.ga" else: # Create new image image = model.CloudImage() @@ -379,8 +380,8 @@ return trans.show_form( web.FormBuilder( web.url_for(), "Add new cloud image", submit_text="Add" ) - .add_text( "image_id", "Machine Image ID (AMI or EMI)", value='', error=error ) - .add_text( "manifest", "Manifest", value='', error=error ) ) + .add_text( "image_id", "Machine Image ID (AMI or EMI)", value='', error=id_error ) + .add_text( "manifest", "Manifest", value='', error=manifest_error ) ) @web.expose @web.require_login( "use Galaxy cloud" ) @@ -398,7 +399,44 @@ image.delete() image.flush() return self.listMachineImages( trans ) - + + @web.expose + @web.require_admin + def editImage( self, trans, image_id, manifest, id=None, edited=False ): + error = {} + if not isinstance( id, int ): + id = trans.security.decode_id( id ) + + if not edited: + image = trans.sa_session.query( model.CloudImage ).get( id ) + return trans.fill_template( "cloud/edit_image.mako", + image = image, + error = error + ) + else: + image = trans.sa_session.query( model.CloudImage ).get( id ) + if image_id=='' or len( image_id ) > 255: + error['id_error'] = "Image ID must be between 1 and 255 characters in length." + elif trans.app.model.CloudImage \ + .filter( and_( trans.app.model.CloudImage.table.c.id != image.id, trans.app.model.CloudImage.table.c.image_id==image_id ) ) \ + .first(): + error['id_error'] = "Image with ID '" + image_id + "' already exist. Please choose an alternative name." + if error: + return trans.fill_template( "cloud/edit_image.mako", + image = image, + error = error + ) + else: + image.image_id = image_id + image.manifest = manifest + # Persist + session = trans.sa_session + session.save_or_update( image ) + session.flush() + # Log and display the management page + trans.set_message( "Image '%s' edited." % image.image_id ) + return self.listMachineImages( trans ) + @web.expose @web.require_login( "use Galaxy cloud" ) def edit( self, trans, id, credName=None, accessKey=None, secretKey=None, edited=False ): diff -r b7857b33dbd8 -r 89276f68513a templates/cloud/configure_cloud.mako --- a/templates/cloud/configure_cloud.mako Mon Nov 02 17:11:03 2009 -0500 +++ b/templates/cloud/configure_cloud.mako Tue Nov 03 13:20:26 2009 -0500 @@ -284,12 +284,4 @@ or <a href="http://aws.amazon.com/" target="_blank"> open AWS account with Amazon</a>. - -%endif - -<p /><br /> -<ul class="manage-table-actions"> - <li> - <a class="action-button" href="${h.url_for( action='addNewImage' )}"><span>Add new image</span></a> - </li> -</ul> \ No newline at end of file +%endif \ No newline at end of file diff -r b7857b33dbd8 -r 89276f68513a templates/cloud/edit_image.mako --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/cloud/edit_image.mako Tue Nov 03 13:20:26 2009 -0500 @@ -0,0 +1,64 @@ +<% _=n_ %> +<%inherit file="/base.mako"/> +<%def name="title()">Edit machine image</%def> + +<%def name="javascripts()"> +${parent.javascripts()} +<script type="text/javascript"> +$(function(){ + $("input:text:first").focus(); +}) +</script> +</%def> + +%if header: + ${header} +%endif + +%if image: + +<div class="form"> + <div class="form-title">Edit image</div> + <div class="form-body"> + <form name="edit_image" action="${h.url_for( action='editImage', id=trans.security.encode_id(image.id), edited="true" )}" method="post" > + + <% + cls = "form-row" + if error.has_key('id_error'): + cls += " form-row-error" + %> + <div class="${cls}"> + <label>Machine Image ID (AMI or EMI):</label> + <div class="form-row-input"> + <input type="text" name="image_id" value="${image.image_id}" size="40"> + </div> + %if error.has_key('id_error'): + <div class="form-row-error-message">${error['id_error']}</div> + %endif + <div style="clear: both"></div> + </div> + <% + cls = "form-row" + if error.has_key('manifest_error'): + cls += " form-row-error" + %> + <div class="${cls}"> + <label>Manifest:</label> + <div class="form-row-input"> + <input type="text" name="manifest" value="${image.manifest}" size="40"> + </div> + %if error.has_key('manifest_error'): + <div class="form-row-error-message">${error['manifest_error']}</div> + %endif + <div style="clear: both"></div> + </div> + + + <div class="form-row"><input type="submit" value="Save"></div> + </form> + </div> +</div> + +%else: + Specified machine image could not be found. +%endif diff -r b7857b33dbd8 -r 89276f68513a templates/cloud/list_images.mako --- a/templates/cloud/list_images.mako Mon Nov 02 17:11:03 2009 -0500 +++ b/templates/cloud/list_images.mako Tue Nov 03 13:20:26 2009 -0500 @@ -24,11 +24,12 @@ <colgroup width="13%"></colgroup> <colgroup width="70%"></colgroup> <colgroup width="5%"></colgroup> - + <colgroup width="5%"></colgroup> <tr class="header"> <th>#</th> <th>Machime image ID</th> <th>Manifest</th> + <th>Edit</th> <th>Delete</th> <th></th> </tr> @@ -49,10 +50,13 @@ N/A %endif </td> - <td><div align="center"> - <a confirm="Are you sure you want to delete machine image '${image.image_id}'?" + <td> + <a href="${h.url_for( controller='cloud', action='editImage', image_id=image.image_id, manifest=image.manifest, id=trans.security.encode_id(image.id) )}">e</a> + </td> + <td> + <a confirm="Are you sure you want to delete machine image '${image.image_id}'? Note that this may result in users' UCI's not to work any more!" href="${h.url_for( controller='cloud', action='deleteImage', id=trans.security.encode_id(image.id) )}">x</a> - </div></td> + </td> </tr> %endfor </table>
participants (1)
-
Greg Von Kuster