[hg] galaxy 3075: Added editing of credential properties.
details: http://www.bx.psu.edu/hg/galaxy/rev/7b642483d18c changeset: 3075:7b642483d18c user: Enis Afgan <afgane@gmail.com> date: Wed Oct 28 12:28:57 2009 -0400 description: Added editing of credential properties. diffstat: lib/galaxy/web/controllers/cloud.py | 91 +++++++++++++++++++++++------ templates/cloud/add_credentials.mako | 40 ++++++------- templates/cloud/configure_cloud.mako | 2 +- templates/cloud/edit_credentials.mako | 91 ++++++++++++++++++++++++++++++ templates/cloud/view.mako | 6 +- 5 files changed, 185 insertions(+), 45 deletions(-) diffs (315 lines): diff -r 802b761c5032 -r 7b642483d18c lib/galaxy/web/controllers/cloud.py --- a/lib/galaxy/web/controllers/cloud.py Tue Oct 27 15:32:44 2009 -0400 +++ b/lib/galaxy/web/controllers/cloud.py Wed Oct 28 12:28:57 2009 -0400 @@ -77,7 +77,7 @@ cloudCredentials = trans.sa_session.query( model.CloudUserCredentials ) \ .filter_by( user=user ) \ - .order_by( desc( model.CloudUserCredentials.c.name ) ) \ + .order_by( model.CloudUserCredentials.c.name ) \ .all() liveInstances = trans.sa_session.query( model.UCI ) \ @@ -387,23 +387,64 @@ @web.expose @web.require_login( "use Galaxy cloud" ) - def rename( self, trans, id, new_name=None ): - stored = get_stored_credentials( trans, id ) - if new_name is not None: - stored.name = new_name - trans.sa_session.flush() - trans.set_message( "Credentials renamed to '%s'." % new_name ) - return self.list( trans ) + def edit( self, trans, id, credName=None, accessKey=None, secretKey=None, edited=False ): + error = {} + if not edited: + credentials = get_stored_credentials( trans, id ) + return trans.fill_template( "cloud/edit_credentials.mako", + credential = credentials, + error = error + ) else: - return trans.show_form( - web.FormBuilder( url_for( id=trans.security.encode_id(stored.id) ), "Rename credentials", submit_text="Rename" ) - .add_text( "new_name", "Credentials Name", value=stored.name ) ) - + user = trans.get_user() + credentials = get_stored_credentials( trans, id ) + if credName=='' or len( credName ) > 255: + error['cred_error'] = "Credentials name must be between 1 and 255 characters in length." + elif trans.app.model.CloudUserCredentials \ + .filter_by( user=user ) \ + .filter( and_( trans.app.model.CloudUserCredentials.table.c.id != credentials.id, trans.app.model.CloudUserCredentials.table.c.name==credName ) ) \ + .first(): + error['cred_error'] = "Credentials with name '" + credName + "' already exist. Please choose an alternative name." + elif accessKey=='' or len( accessKey ) > 255: + error['access_key_error'] = "Access key must be between 1 and 255 characters long." + elif secretKey=='' or len( secretKey ) > 255: + error['secret_key_error'] = "Secret key must be between 1 and 255 characters long." + + if error: + return trans.fill_template( "cloud/edit_credentials.mako", + credential = credentials, + error = error + ) + else: + # Edit user stored credentials + credentials.name = credName + credentials.access_key = accessKey + credentials.secret_key = secretKey + # Persist + session = trans.sa_session + session.save_or_update( credentials ) + session.flush() + # Log and display the management page + trans.set_message( "Credential '%s' edited." % credentials.name ) +# if defaultCred: +# self.makeDefault( trans, credentials.id) + return self.list( trans ) + @web.expose @web.require_login( "use Galaxy cloud" ) def renameInstance( self, trans, id, new_name=None ): instance = get_uci( trans, id ) if new_name is not None: + if len(new_name) > 255: + error( "Instance name must be less than 255 characters long." ) + user = trans.get_user() + name_exists = trans.sa_session.query( model.UCI ) \ + .filter_by( user=user, name=new_name ) \ + .first() + if name_exists: + error( "Specified name ('%s') is already used by an existing instance. Please choose an alternative name." % new_name ) + + # Update name in local DB instance.name = new_name trans.sa_session.flush() trans.set_message( "Instance renamed to '%s'." % new_name ) @@ -522,17 +563,27 @@ @web.require_login( "delete credentials" ) def delete( self, trans, id=None ): """ - Delete user's cloud credentials - TODO: Because UCI's depend on specific credentials, need to handle case where given credentials are being used by a UCI + Delete user's cloud credentials checking that no registered instances are tied to given credentials. """ # Load credentials from database + user = trans.get_user() stored = get_stored_credentials( trans, id ) - # Delete and save - sess = trans.sa_session - sess.delete( stored ) - stored.flush() - # Display the management page - trans.set_message( "Credentials '%s' deleted." % stored.name ) + UCIs = trans.sa_session.query( model.UCI ) \ + .filter_by( user=user, credentials_id=stored.id ) \ + .filter( model.UCI.c.state!=uci_states.DELETED ) \ + .all() + + if len(UCIs) == 0: + # Delete and save + sess = trans.sa_session + sess.delete( stored ) + stored.flush() + # Display the management page + trans.set_message( "Credentials '%s' deleted." % stored.name ) + return self.list( trans ) + + error( "Existing instance(s) depend on credentials '%s'. You must delete those instances before being able \ + to delete these credentials." % stored.name ) return self.list( trans ) @web.expose diff -r 802b761c5032 -r 7b642483d18c templates/cloud/add_credentials.mako --- a/templates/cloud/add_credentials.mako Tue Oct 27 15:32:44 2009 -0400 +++ b/templates/cloud/add_credentials.mako Wed Oct 28 12:28:57 2009 -0400 @@ -20,8 +20,8 @@ <div class="form"> <div class="form-title">Add credentials</div> <div class="form-body"> - <form name="Add credentials" action="${h.url_for( action='add' )}" method="post" > - + <form name="Add credentials" action="${h.url_for( action='add' )}" method="post" > + <% cls = "form-row" if error.has_key('cred_error'): @@ -44,23 +44,23 @@ if error.has_key('provider_error'): cls += " form-row-error" %> - <div class="${cls}"> - <label>Cloud provider name:</label> - <div class="form-row-input"> - <select name="providerName" style="width:40em"> - <option value="">Select Provider...</option> - %for provider in providers: - <option value="${provider.name}">${provider.name}</option> - %endfor - </select> - <br/>or <a href="${h.url_for( action='add_provider' )}"> - <span>register additional cloud provider</span></a> - </div> - %if error.has_key('provider_error'): - <div class="form-row-error-message">${error['provider_error']}</div> - %endif - <div style="clear: both"></div> - </div> + <div class="${cls}"> + <label>Cloud provider name:</label> + <div class="form-row-input"> + <select name="providerName" style="width:40em"> + <option value="">Select Provider...</option> + %for provider in providers: + <option value="${provider.name}">${provider.name}</option> + %endfor + </select> + <br/>or <a href="${h.url_for( action='add_provider' )}"> + <span>register additional cloud provider</span></a> + </div> + %if error.has_key('provider_error'): + <div class="form-row-error-message">${error['provider_error']}</div> + %endif + <div style="clear: both"></div> + </div> <% cls = "form-row" @@ -95,9 +95,7 @@ <div style="clear: both"></div> </div> - <div class="form-row"><input type="submit" value="Add"></div> - </form> </div> </div> diff -r 802b761c5032 -r 7b642483d18c templates/cloud/configure_cloud.mako --- a/templates/cloud/configure_cloud.mako Tue Oct 27 15:32:44 2009 -0400 +++ b/templates/cloud/configure_cloud.mako Wed Oct 28 12:28:57 2009 -0400 @@ -109,7 +109,7 @@ <td> <div popupmenu="cr-${i}-popup"> <a class="action-button" href="${h.url_for( action='view', id=trans.security.encode_id(cloudCredential.id) )}">View</a> - <a class="action-button" href="${h.url_for( action='rename', id=trans.security.encode_id(cloudCredential.id) )}">Rename</a> + <a class="action-button" href="${h.url_for( action='edit', id=trans.security.encode_id(cloudCredential.id) )}">Edit</a> <a class="action-button" confirm="Are you sure you want to delete credentials '${cloudCredential.name}'?" href="${h.url_for( action='delete', id=trans.security.encode_id(cloudCredential.id) )}">Delete</a> </div> </td> diff -r 802b761c5032 -r 7b642483d18c templates/cloud/edit_credentials.mako --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/cloud/edit_credentials.mako Wed Oct 28 12:28:57 2009 -0400 @@ -0,0 +1,91 @@ +<% _=n_ %> +<%inherit file="/base.mako"/> +<%def name="title()">Add credentials</%def> + +<%def name="javascripts()"> +${parent.javascripts()} +<script type="text/javascript"> +$(function(){ + $("input:text:first").focus(); +}) +</script> +</%def> + +%if header: + ${header} +%endif + +%if credential: + +<div class="form"> + <div class="form-title">Edit credentials</div> + <div class="form-body"> + <form name="edit_credentials" action="${h.url_for( action='edit', id=trans.security.encode_id(credential.id), edited="true" )}" method="post" > + + <% + cls = "form-row" + if error.has_key('cred_error'): + cls += " form-row-error" + %> + <div class="${cls}"> + <label>Credentials name:</label> + <div class="form-row-input"> + <input type="text" name="credName" value="${credential.name}" size="40"> + </div> + %if error.has_key('cred_error'): + <div class="form-row-error-message">${error['cred_error']}</div> + %endif + <div style="clear: both"></div> + </div> + + + <% + cls = "form-row" + if error.has_key('provider_error'): + cls += " form-row-error" + %> + <div class="${cls}"> + <label>Cloud provider name (type):</label> + <div class="form-row-input">${credential.provider.name} (${credential.provider.type})</div> + <div style="clear: both"></div> + </div> + <% + cls = "form-row" + if error.has_key('access_key_error'): + cls += " form-row-error" + %> + <div class="${cls}"> + <label>Access key:</label> + <div class="form-row-input"> + <input type="text" name="accessKey" value="${credential.access_key}" size="40"> + </div> + %if error.has_key('access_key_error'): + <div class="form-row-error-message">${error['access_key_error']}</div> + %endif + <div style="clear: both"></div> + </div> + + <% + cls = "form-row" + if error.has_key('secret_key_error'): + cls += " form-row-error" + %> + <div class="${cls}"> + <label>Secret key:</label> + <div class="form-row-input"> + <input type="password" name="secretKey" value="${credential.secret_key}" size="40"> + </div> + %if error.has_key('secret_key_error'): + <div class="form-row-error-message">${error['secret_key_error']}</div> + %endif + <div style="clear: both"></div> + </div> + + <div class="form-row"><input type="submit" value="Edit"></div> + </form> + </div> +</div> + +%else: + Specified credentials could not be found. +%endif diff -r 802b761c5032 -r 7b642483d18c templates/cloud/view.mako --- a/templates/cloud/view.mako Tue Oct 27 15:32:44 2009 -0400 +++ b/templates/cloud/view.mako Wed Oct 28 12:28:57 2009 -0400 @@ -71,12 +71,12 @@ </a> </div> <div id="fullComment2" style="DISPLAY: none"> - <nobr><b>${credDetails.secret_key}</b></nobr><br/> - <a onclick="document.getElementById('shortComment2').style.display = 'block'; + <a onclick="document.getElementById('shortComment2').style.display = 'block'; document.getElementById('fullComment2').style.display = 'none'; return 0;" href="javascript:void(0)"> - Hide - </a> + </a><br /> + <nobr><b>${credDetails.secret_key}</b></nobr><br/> </div> </td> </tr>
participants (1)
-
Greg Von Kuster