Skip to content

Commit

Permalink
Adding login information section for manage user information feature
Browse files Browse the repository at this point in the history
  • Loading branch information
anuprulez committed Jul 31, 2016
1 parent 77f5655 commit a63f634
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 30 deletions.
8 changes: 7 additions & 1 deletion client/galaxy/scripts/layout/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,14 @@ var Collection = Backbone.Collection.extend({
menu : [{
title : 'Logged in as ' + Galaxy.user.get( 'email' )
},

{
title : 'Preferences Mako',
url : 'user?cntrller=user',
target : 'galaxy_main'
},
{
title : 'Preferences',
title : 'New Preferences',
url : 'user',
onclick : function() {
if (Galaxy.app) {
Expand Down
68 changes: 61 additions & 7 deletions client/galaxy/scripts/mvc/user/manage-user-information.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ var ManageUserInformation = Backbone.View.extend({
original_email: "",
original_username: "",

initialize: function ( ) {
this.render( this );
initialize: function ( data ) {
this.render( this, data );
},

/** validates email and username */
Expand All @@ -16,7 +16,7 @@ var ManageUserInformation = Backbone.View.extend({
var username_re = /^[a-z0-9\-]{3,255}$/;
if ( type === 'email' ) {
return mail_re.test(test_string);
}
}
else if ( type === 'username' ) {
return username_re.test(test_string);
}
Expand Down Expand Up @@ -79,18 +79,72 @@ var ManageUserInformation = Backbone.View.extend({
},

/** renders manage user information */
render: function( self ) {
render: function( self, data ) {
var template = "";
template = template + '<div class="manage-userinfo-section"> <h2>Manage User Information</h2>';
if( !Galaxy.user.attributes.is_admin ) {
template = template + '<ul class="manage-table-actions">' +
'<li>' +
'<a class="action-button back-user-info" target="galaxy_main">User preferences</a>' +
'<a class="action-button back-user-pref" target="galaxy_main">User preferences</a>' +
'</li></ul>';
}

template = template + '<div class="toolForm">' +
'<form name="login_info" id="login_info">' +
'<div class="toolFormTitle">Login Information</div>' +
'<div class="form-row">' +
'<label>Email address:</label>' +
'<input type="text" id ="email_input" name="email" value="'+ data["email"] +'" size="40"/>' +
'<div class="toolParamHelp" style="clear: both;">' +
'If you change your email address you will receive an activation link in the new mailbox and you have to' +
'activate your account by visiting it.' +
'</div>' +
'</div>' +
'<div class="form-row">' +
'<label>Public name:</label>';

if(data['webapp'] === 'tool_shed' ) {
if( data['active_repositories'] ) {
template = template + '<input type="hidden" id="name_input" name="username" value="' + data['username'] + '"/>' +
data['username'] +
'<div class="toolParamHelp" style="clear: both;">' +
'You cannot change your public name after you have created a repository in this tool shed.' +
'</div>';
}
else {
template = template + '<input type="text" id="name_input" name="username" size="40" value="'+ data['username'] +'"/>' +
'<div class="toolParamHelp" style="clear: both;">' +
'Your public name provides a means of identifying you publicly within this tool shed. Public' +
'names must be at least three characters in length and contain only lower-case letters, numbers,' +
'and the "-" character. You cannot change your public name after you have created a repository' +
'in this tool shed.' +
'</div>';
}
}
else {
template = template + '<input type="text" id="name_input" name="username" size="40" value="' + data['username'] + '"/>' +
'<div class="toolParamHelp" style="clear: both;">' +
'Your public name is an identifier that will be used to generate addresses for information' +
'you share publicly. Public names must be at least three characters in length and contain only lower-case' +
'letters, numbers, and the "-" character.' +
'</div>';
}
template = template + '</div>';
template = template +
'<div class="form-row">' +
'<input type="submit" id="send" name="login_info_button" value="Save"/>' +
'</div>' +
'</form>' +
'</div>';
template = template + "</div>";
$('.user-preferences-all').append(template);
}
$('.user-preferences-all').append(template).on( 'click', '.back-user-pref', self.showUserPref );
},

/** go back to all user preferences */
showUserPref: function( e ) {
$('.manage-userinfo-section').css( 'display', 'none' );
$( '.user-pref' ).css( 'display', 'block' );
}
});

return {
Expand Down
11 changes: 7 additions & 4 deletions client/galaxy/scripts/mvc/user/user-preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ var UserPreferences = Backbone.View.extend({

/** redirects to manage user information view */
callManageInfo: function( e ) {
var userInfo = null;
var userInfo = null,
url = Galaxy.root + 'api/user_preferences/manage_user_info';
e.preventDefault();
$( '.user-pref' ).css( 'display','none' );
userInfo = new Manage.ManageUserInformation();
$.getJSON( url, function( data ) {
userInfo = new Manage.ManageUserInformation( data );
});
},

/** fetch data for user preferences */
getUserPreferencesData: function() {
var url = Galaxy.root + 'api/user_preferences/',
var url = Galaxy.root + 'api/user_preferences',
self = this;
$.getJSON( url, function( data ) {
self.render(data);
Expand Down Expand Up @@ -82,7 +85,7 @@ var UserPreferences = Backbone.View.extend({
"</ul>";
}
template = template + "</div></div>";
this.$el.html(template).on( "click", ".manage-userinfo", self.callManageInfo);
this.$el.html(template).on( "click", ".manage-userinfo", self.callManageInfo );
}
});

Expand Down
130 changes: 128 additions & 2 deletions lib/galaxy/webapps/galaxy/api/user_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
API operations on User Preferences objects.
"""

import sys
import logging

from markupsafe import escape
from sqlalchemy import false, true, or_

from galaxy import exceptions, util, web
Expand All @@ -17,14 +19,17 @@
from galaxy.web.base.controller import CreatesApiKeysMixin
from galaxy.web.base.controller import CreatesUsersMixin
from galaxy.web.base.controller import UsesTagsMixin
from galaxy.web.base.controller import (BaseUIController,
UsesFormDefinitionsMixin)
from galaxy.web.form_builder import build_select_field, CheckboxField

log = logging.getLogger( __name__ )


class UserPreferencesAPIController( BaseAPIController, UsesTagsMixin, CreatesUsersMixin, CreatesApiKeysMixin ):
class UserPreferencesAPIController( BaseAPIController, BaseUIController, UsesTagsMixin, CreatesUsersMixin, CreatesApiKeysMixin, UsesFormDefinitionsMixin ):

@expose_api
def index( self, trans, cntrller='user', **kwd ):
def index( self, trans, cntrller='user_preferences', **kwd ):
return {'id': trans.security.encode_id( trans.user.id ),
'message': "",
'username': trans.user.username,
Expand All @@ -37,3 +42,124 @@ def index( self, trans, cntrller='user', **kwd ):
'quota': trans.app.quota_agent.get_quota( trans.user, nice_size=True ),
}

def __get_user_type_form_definition( self, trans, user=None, **kwd ):
params = util.Params( kwd )
if user and user.values:
user_type_fd_id = trans.security.encode_id( user.values.form_definition.id )
else:
user_type_fd_id = params.get( 'user_type_fd_id', 'none' )
if user_type_fd_id not in [ 'none' ]:
user_type_form_definition = trans.sa_session.query( trans.app.model.FormDefinition ).get( trans.security.decode_id( user_type_fd_id ) )
else:
user_type_form_definition = None
return user_type_form_definition

# ===== Methods for building SelectFields ================================
def __build_user_type_fd_id_select_field( self, trans, selected_value ):
# Get all the user information forms
user_info_forms = self.get_all_forms( trans,
filter=dict( deleted=False ),
form_type=trans.model.FormDefinition.types.USER_INFO )
return build_select_field( trans,
objs=user_info_forms,
label_attr='name',
select_field_name='user_type_fd_id',
initial_value='none',
selected_value=selected_value,
refresh_on_change=True )

def __get_widgets( self, trans, user_type_form_definition, user=None, **kwd ):
widgets = []
if user_type_form_definition:
if user:
if user.values:
widgets = user_type_form_definition.get_widgets( user=user,
contents=user.values.content,
**kwd )
else:
widgets = user_type_form_definition.get_widgets( None, contents={}, **kwd )
else:
widgets = user_type_form_definition.get_widgets( None, contents={}, **kwd )
return widgets

@expose_api
def manage_user_info( self, trans, cntrller='user_preferences', **kwd ):
'''Manage a user's login, password, public username, type, addresses, etc.'''
params = util.Params( kwd )
user_id = params.get( 'id', None )
if user_id:
user = trans.sa_session.query( trans.app.model.User ).get( trans.security.decode_id( user_id ) )
else:
user = trans.user
if not user:
raise AssertionError("The user id (%s) is not valid" % str( user_id ))
email = util.restore_text( params.get( 'email', user.email ) )
username = util.restore_text( params.get( 'username', '' ) )
if not username:
username = user.username
message = escape( util.restore_text( params.get( 'message', '' ) ) )
status = params.get( 'status', 'done' )
if trans.webapp.name == 'galaxy':
user_type_form_definition = self.__get_user_type_form_definition( trans, user=user, **kwd )
user_type_fd_id = params.get( 'user_type_fd_id', 'none' )
if user_type_fd_id == 'none' and user_type_form_definition is not None:
user_type_fd_id = trans.security.encode_id( user_type_form_definition.id )
user_type_fd_id_select_field = self.__build_user_type_fd_id_select_field( trans, selected_value=user_type_fd_id )
widgets = self.__get_widgets( trans, user_type_form_definition, user=user, **kwd )
# user's addresses
show_filter = util.restore_text( params.get( 'show_filter', 'Active' ) )
if show_filter == 'All':
addresses = [address for address in user.addresses]
elif show_filter == 'Deleted':
addresses = [address for address in user.addresses if address.deleted]
else:
addresses = [address for address in user.addresses if not address.deleted]
user_info_forms = self.get_all_forms( trans,
filter=dict( deleted=False ),
form_type=trans.app.model.FormDefinition.types.USER_INFO )
# makes the address list JSON iterable
address_list = dict()
index_add = 0
for item in addresses:
address_list[index_add] = dict()
address_list[index_add]["desc"] = item.desc
address_list[index_add]["html"] = item.get_html()
index_add = index_add + 1

# makes the widget list JSON iterable
widget_list = dict()
index_widget = 0
for item in widgets:
widget_list[index_widget] = dict()
widget_list[index_widget]["label"] = item['label']
widget_list[index_widget]["html"] = item['widget'].get_html()
widget_list[index_widget]["helptext"] = item['helptext']
index_widget = index_widget + 1

return {'cntrller': cntrller,
'webapp': trans.webapp.name,
'is_admin': trans.user_is_admin(),
'values': user.values,
'email': email,
'username': username,
'user_type_fd_id_select_field_options': user_type_fd_id_select_field.options,
'user_type_fd_id_select_html': user_type_fd_id_select_field.get_html(),
'user_info_forms': user_info_forms,
'user_type_form_definition': user_type_form_definition,
'user_type_fd_id': user_type_fd_id,
'user_type_fd_id_encoded': trans.security.encode_id( user_type_fd_id ),
'widgets': widget_list,
'addresses' : address_list,
'show_filter': show_filter,
'message': message,
'status': status
}
else:
return {'cntrller': cntrller,
'webapp': trans.webapp.name,
'active_repositories': user.active_repositories,
'email': email,
'username': username,
'message': message,
'status': status
}
7 changes: 7 additions & 0 deletions lib/galaxy/webapps/galaxy/buildapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def paste_app_factory( global_conf, **kwargs ):
webapp.add_client_route( '/tours/{tour_id}' )

webapp.add_client_route( '/user_preferences' )
webapp.add_client_route( '/user_preferences/manage_user_info' )

# STANDARD CONTROLLER ROUTES
webapp.add_ui_controllers( 'galaxy.webapps.galaxy.controllers', app )
Expand Down Expand Up @@ -463,6 +464,12 @@ def populate_api_routes( webapp, app ):
action='index',
conditions=dict( method=["GET"] ) )

webapp.mapper.connect( 'manage_user_info',
'/api/user_preferences/manage_user_info',
controller='user_preferences',
action='manage_user_info',
conditions=dict( method=["GET"] ) )


# =======================
# ===== LIBRARY API =====
Expand Down
Loading

0 comments on commit a63f634

Please sign in to comment.