details: http://www.bx.psu.edu/hg/galaxy/rev/a83d7220136f changeset: 3051:a83d7220136f user: Enis Afgan <afgane@gmail.com> date: Mon Aug 24 12:19:57 2009 -0400 description: Enabled editing/viewing of user credentials. diffstat: lib/galaxy/web/controllers/cloud.py | 169 +++++++++++---------------------- static/images/silk/resultset_previous.png | templates/cloud/configure_cloud.mako | 3 +- templates/cloud/view.mako | 60 ++++++++++++ 4 files changed, 120 insertions(+), 112 deletions(-) diffs (276 lines): diff -r 6f32d42dab74 -r a83d7220136f lib/galaxy/web/controllers/cloud.py --- a/lib/galaxy/web/controllers/cloud.py Fri Aug 21 17:36:40 2009 -0400 +++ b/lib/galaxy/web/controllers/cloud.py Mon Aug 24 12:19:57 2009 -0400 @@ -33,7 +33,9 @@ """ user = trans.get_user() #awsCredentials = 0 - awsCredentials = trans.sa_session.query ( model.StoredUserCredentials ).all() + awsCredentials = trans.sa_session.query ( model.StoredUserCredentials ) \ + .order_by( desc( model.StoredUserCredentials.c.update_time ) ) \ + .all() log.debug( "in list" ) log.debug( awsCredentials ) @@ -50,6 +52,7 @@ def makeDefault( self, trans ): """ Set current credentials as default to be used for submitting jobs + TODO: Implement, this is only a dummy method. """ awsCredentials = trans.sa_session.query ( model.StoredUserCredentials ).all() @@ -170,119 +173,63 @@ else: return form( url_for( id=trans.security.encode_id(stored.id) ), "Rename credentials", submit_text="Rename" ) \ .add_text( "new_name", "Credentials Name", value=stored.name ) + + @web.expose + @web.require_login( "add credentials" ) + def add( self, trans, credName='', accessKey='', secretKey='', default=False ): + """ + Add user's AWS credentials stored under name `credName`. + TODO: Make use of 'default' credential selection + """ + user = trans.get_user() + cred_error = accessKey_error = secretKey_error = None + if credName: + if len( credName ) > 255: + cred_error = "Credentials name exceeds maximum allowable length." + elif trans.app.model.StoredUserCredentials.filter( + trans.app.model.StoredUserCredentials.table.c.name==credName ).first(): + cred_error = "Credentials with that name already exist." + else: + # Create new user stored credentials + credentials = model.StoredUserCredentials() + credentials.name = credName + credentials.user = user + 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.log_event( "User added new credentials" ) + trans.set_message( "Credential '%s' created" % credentials.name ) + if default: + mail = os.popen("%s -t" % trans.app.config.sendmail_path, 'w') + mail.write("To: %s\nFrom: %s\nSubject: Join Mailing List\n\nJoin Mailing list." % (trans.app.config.mailing_join_addr,email) ) + if mail.close(): + return trans.show_warn_message( "Now logged in as " + user.email+". However, subscribing to the mailing list has failed.", refresh_frames=refresh_frames ) + return self.list( trans ) + return trans.show_form( + web.FormBuilder( web.url_for(), "Add credentials", submit_text="Add" ) + .add_text( "credName", "Credentials name", value="Unnamed credentials", error=cred_error ) + .add_text( "accessKey", "Access key", value='', error=accessKey_error ) + .add_password( "secretKey", "Secret key", value='', error=secretKey_error ) + .add_input( "checkbox","Make default credentials","default", value='default' ) ) @web.expose - @web.require_login( "use Galaxy workflows" ) - def clone( self, trans, id ): - stored = get_stored_workflow( trans, id, check_ownership=False ) - user = trans.get_user() - if stored.user == user: - owner = True - else: - if trans.sa_session.query( model.StoredWorkflowUserShareAssociation ) \ - .filter_by( user=user, stored_workflow=stored ).count() == 0: - error( "Workflow is not owned by or shared with current user" ) - owner = False - new_stored = model.StoredWorkflow() - new_stored.name = "Clone of '%s'" % stored.name - new_stored.latest_workflow = stored.latest_workflow - if not owner: - new_stored.name += " shared by '%s'" % stored.user.email - new_stored.user = user - # Persist - session = trans.sa_session - session.save_or_update( new_stored ) - session.flush() - # Display the management page - trans.set_message( 'Clone created with name "%s"' % new_stored.name ) - return self.list( trans ) - + @web.require_login( "view credentials" ) + def view( self, trans, id=None ): + """ + View details for user credentials + """ + # Load credentials from database + stored = get_stored_credentials( trans, id ) + + return trans.fill_template( "cloud/view.mako", + credDetails = stored) + @web.expose - @web.require_login( "create workflows" ) - def create( self, trans, workflow_name=None ): - """ - Create a new stored workflow with name `workflow_name`. - """ - user = trans.get_user() - if workflow_name is not None: - # Create the new stored workflow - stored_workflow = model.StoredWorkflow() - stored_workflow.name = workflow_name - stored_workflow.user = user - # And the first (empty) workflow revision - workflow = model.Workflow() - workflow.name = workflow_name - workflow.stored_workflow = stored_workflow - stored_workflow.latest_workflow = workflow - # Persist - session = trans.sa_session - session.save_or_update( stored_workflow ) - session.flush() - # Display the management page - trans.set_message( "Workflow '%s' created" % stored_workflow.name ) - return self.list( trans ) - else: - return form( url_for(), "Create new workflow", submit_text="Create" ) \ - .add_text( "workflow_name", "Workflow Name", value="Unnamed cloud" ) - - @web.expose - @web.require_login( "add AWS credentials" ) - def add( self, trans, account_name=None ): - """ - Add user's AWS credentials stored under name `account_name`. - """ - user = trans.get_user() - - """ - awsCredentials = trans.sa_session.query ( model.StoredUserCredentials ).all() - log.debug( "in add" ) - log.debug( user ) - log.debug( credentials.name ) - log.debug( awsCredentials ) - """ - - if account_name is not None: - # Create new user stored credentials - credentials = model.StoredUserCredentials() - credentials.name = account_name - credentials.user = user - credentials.access_key = "access key" - credentials.secret_key = "secret key" - # Persist - session = trans.sa_session - session.save_or_update( credentials ) - session.flush() - # Display the management page - trans.set_message( "Credential '%s' created" % credentials.name ) - return self.list( trans ) - - """ - # Create the new stored workflow - stored_workflow = model.StoredWorkflow() - stored_workflow.name = workflow_name - stored_workflow.user = user - # And the first (empty) workflow revision - workflow = model.Workflow() - workflow.name = workflow_name - workflow.stored_workflow = stored_workflow - stored_workflow.latest_workflow = workflow - # Persist - session = trans.sa_session - session.save_or_update( stored_workflow ) - session.flush() - # Display the management page - trans.set_message( "Workflow '%s' created" % stored_workflow.name ) - return self.list( trans ) - """ - else: - return trans.fill_template("cloud/credentials.mako") - """ - form( url_for(), "Add AWS credentials", submit_text="Add" ) \ - .add_text( "account_name", "Account Name", value="Unnamed credentials" ) - .add_text( "access_key", "Access Key", value="" ) - .add_text( "secret_key", "Secret Key", value="" ) - """ - @web.expose + @web.require_login( "delete credentials" ) def delete( self, trans, id=None ): """ Delete credentials diff -r 6f32d42dab74 -r a83d7220136f static/images/silk/resultset_previous.png Binary file static/images/silk/resultset_previous.png has changed diff -r 6f32d42dab74 -r a83d7220136f templates/cloud/configure_cloud.mako --- a/templates/cloud/configure_cloud.mako Fri Aug 21 17:36:40 2009 -0400 +++ b/templates/cloud/configure_cloud.mako Mon Aug 24 12:19:57 2009 -0400 @@ -44,8 +44,9 @@ ##<td>${str(awsCredentials.update_time)[:19]}</td> <td> <div popupmenu="wf-${i}-popup"> - <a class="action-button" href="${h.url_for( action='makeDefault', id=trans.security.encode_id(awsCredential.id) )}" target="_parent">Made default</a> + <a class="action-button" href="${h.url_for( action='view', id=trans.security.encode_id(awsCredential.id) )}">View</a> <a class="action-button" href="${h.url_for( action='rename', id=trans.security.encode_id(awsCredential.id) )}">Rename</a> + <a class="action-button" href="${h.url_for( action='makeDefault', id=trans.security.encode_id(awsCredential.id) )}" target="_parent">Make default</a> <a class="action-button" confirm="Are you sure you want to delete workflow '${awsCredential.name}'?" href="${h.url_for( action='delete', id=trans.security.encode_id(awsCredential.id) )}">Delete</a> </div> </td> diff -r 6f32d42dab74 -r a83d7220136f templates/cloud/view.mako --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/cloud/view.mako Mon Aug 24 12:19:57 2009 -0400 @@ -0,0 +1,60 @@ +<%inherit file="/base.mako"/> +<%def name="title()">Cloud home</%def> + + +<h2>Credentials details</h2> + +%if credDetails: + <ul class="manage-table-actions"> + <li> + <a class="action-button" href="${h.url_for( action='list' )}"> + <img src="${h.url_for('/static/images/silk/resultset_previous.png')}" /> + <span>Return to cloud management console</span> + </a> + </li> + </ul> + + <table class="mange-table colored" border="0" cellspacing="0" cellpadding="0" width="100%"> + <tr> + <td> Credentials name: </td> + <td> + ${credDetails.name} + <a id="wf-popup" class="popup-arrow" style="display: none;">▼</a> + </td> + <td> + <div popupmenu="wf-popup"> + <a class="action-button" href="${h.url_for( action='rename', id=trans.security.encode_id(credDetails.id) )}">Rename</a> + <a class="action-button" confirm="Are you sure you want to delete workflow '${credDetails.name}'?" href="${h.url_for( action='delete', id=trans.security.encode_id(credDetails.id) )}">Delete</a> + </div> + </td> + </tr> + <tr> + <td> Access key: </td> + <td> + ${credDetails.access_key} + </td> + </tr> + <tr> + <td> Secret key: </td> + <td> + <div id="shortComment2"> + <a onclick="document.getElementById('fullComment2').style.display = 'block'; + document.getElementById('shortComment2').style.display = 'none'; return 0" + href="javascript:void(0)"> + + Show + </a> + </div> + <div id="fullComment2" style="DISPLAY: none"> + <nobr><b>${credDetails.secret_key}</b></nobr><br/> + <a onclick="document.getElementById('shortComment2').style.display = 'block'; + document.getElementById('fullComment2').style.display = 'none'; return 0;" + href="javascript:void(0)"> + - Hide + </a> + </div> + </td> + </tr> + </table> +%else: + There are no credentials under that name. +%endif