Skip to content

Commit

Permalink
Merge pull request #19 from guerler/fix_communication_settings
Browse files Browse the repository at this point in the history
Revise api key generation form
  • Loading branch information
anuprulez authored Sep 9, 2016
2 parents 4b7324b + d59fa62 commit ab55907
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 60 deletions.
1 change: 1 addition & 0 deletions client/galaxy/scripts/mvc/form/form-parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ define(['utils/utils',
id : 'field-' + input_def.id,
type : input_def.type,
area : input_def.area,
readonly : input_def.readonly,
placeholder : input_def.placeholder,
onchange : input_def.onchange
});
Expand Down
6 changes: 5 additions & 1 deletion client/galaxy/scripts/mvc/ui/ui-misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ define(['utils/utils',
type : 'text',
placeholder : '',
disabled : false,
readonly : false,
visible : true,
cls : '',
area : false,
Expand All @@ -103,6 +104,7 @@ define(['utils/utils',
return this.model.get( 'value' );
},
render: function() {
var self = this;
this.$el.removeClass()
.addClass( 'ui-' + this.tagName )
.addClass( this.model.get( 'cls' ) )
Expand All @@ -115,7 +117,9 @@ define(['utils/utils',
if ( this.model.get( 'value' ) !== this.$el.val() ) {
this.$el.val( this.model.get( 'value' ) );
}
this.model.get( 'disabled' ) ? this.$el.attr( 'disabled', true ) : this.$el.removeAttr( 'disabled' );
_.each( [ 'readonly', 'disabled' ], function( attr_name ) {
self.model.get( attr_name ) ? self.$el.attr( attr_name, true ) : self.$el.removeAttr( attr_name );
});
this.$el[ this.model.get( 'visible' ) ? 'show' : 'hide' ]();
return this;
},
Expand Down
42 changes: 19 additions & 23 deletions client/galaxy/scripts/mvc/user/api-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,44 @@ define( [ 'mvc/form/form-view', 'mvc/ui/ui-misc' ], function( Form, Ui ) {
initialize: function ( app, options ) {
var self = this;
this.model = options && options.model || new Backbone.Model( options );
this.help_text = ' An API key will allow you to access ' + ( options["app_name"] === 'galaxy' ? 'Galaxy' : 'the Tool Shed' ) +
' via its web API. Please note that this key acts as an alternate means to access your account and should be' +
' treated with the same care as your login password.';
this.key = options["has_api_key"] ? options["user_api_key"] : 'none set';
this.form = new Form({
title : 'Web API Key',
inputs : [ { name: 'api-key', type: 'text', label: 'Current API key:', value: self.key },
{ name: 'API Key Information', type: 'section', label: 'API Key Information', help: self.help_text,
inputs: { }, expanded: true }
],
operations : {
'back' : new Ui.ButtonIcon({
inputs : [ { name : 'api-key',
type : 'text',
label : 'Current API key:',
value : options.user_api_key || 'Not available.',
readonly : true,
help : ' An API key will allow you to access ' + ( options.app_name === 'galaxy' ? 'Galaxy' : 'the Tool Shed' ) +
' via its web API. Please note that this key acts as an alternate means to access your account and should be' +
' treated with the same care as your login password.' } ],
operations : {
'back' : new Ui.ButtonIcon({
icon : 'fa-caret-left',
tooltip : 'Return to user preferences',
title : 'Preferences',
onclick : function() { self.remove(); app.showPreferences() }
})
},
buttons : {
buttons : {
'generatenewkey' : new Ui.Button({
tooltip : 'Generate new key ' + ( options["has_api_key"] ? '(invalidates old key) ' : '' ),
title : 'Generate a new key now',
tooltip : 'Generate new key ' + ( options.user_api_key ? '(invalidates old key) ' : '' ),
title : 'Generate a new key',
cls : 'ui-button btn btn-primary',
floating: 'clear',
onclick : function() { self._getNewApiKey() }
})
}
});
this.setElement( this.form.$el );
setTimeout( function(){ $('div[tour_id="api-key"] .ui-input').attr( 'readonly', 'readonly'); $('tmessage').remove(); });
},

/** generates new API key */
/** Generate new API key */
_getNewApiKey: function() {
var url = Galaxy.root + 'api/user_preferences/api_keys',
data = {},
self = this;
data = { 'message': "", 'status': "", 'new_api_key_button': true };
$.getJSON( url, data, function( response ) {
var $key_input = $( 'div[tour_id="api-key"] .ui-input' );
if( response["has_api_key"] ) {
$key_input.val( response["user_api_key"] );
var self = this;
$.getJSON( Galaxy.root + 'api/user_preferences/api_keys', { 'new_api_key': true }, function( response ) {
if( response.user_api_key ) {
var input_id = self.form.data.match( 'api-key' );
self.form.field_list[ input_id ].value( response.user_api_key );
self.form.message.update({
message : response.message,
status : response.status === 'error' ? 'danger' : 'success',
Expand Down
38 changes: 13 additions & 25 deletions lib/galaxy/webapps/galaxy/api/user_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,33 +687,21 @@ def get_iterable_roles( self, role_list ):

@expose_api
def api_keys( self, trans, cntrller='user_preferences', **kwd ):
'''
"""
Generate API keys
'''
params = util.Params( kwd )
message = escape( util.restore_text( params.get( 'message', '' ) ) )
status = params.get( 'status', 'done' )
if params.get( 'new_api_key_button', False ):
"""
params = util.Params( kwd )
message = 'API key unchanged.'
status = 'done'
if params.get( 'new_api_key', False ):
self.create_api_key( trans, trans.user )
message = "Generated a new web API key"
status = "done"

if( trans.user.api_keys ):
return {
'message': message,
'status': status,
'has_api_key': True,
'user_api_key': trans.user.api_keys[0].key,
'app_name': trans.webapp.name
}
else:
return {
'message': message,
'status': status,
'has_api_key': False,
'app_name': trans.webapp.name
}

message = 'Generated a new web API key.'
return {
'message' : message,
'status' : status,
'user_api_key' : trans.user.api_keys[ 0 ].key if trans.user.api_keys else None,
'app_name' : trans.webapp.name
}

def tool_filters( self, trans, cntrller='user_preferences', **kwd ):
"""
Expand Down
2 changes: 1 addition & 1 deletion static/maps/mvc/form/form-parameters.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ab55907

Please sign in to comment.