[hg] galaxy 3660: Decouple the Galaxy specific foms stuff ( addr...
details: http://www.bx.psu.edu/hg/galaxy/rev/ed5535c4d48e changeset: 3660:ed5535c4d48e user: Greg Von Kuster <greg@bx.psu.edu> date: Thu Apr 15 15:58:08 2010 -0400 description: Decouple the Galaxy specific foms stuff ( address, etc ) from the User Preferences page. diffstat: lib/galaxy/web/controllers/user.py | 122 ++++++++++------- templates/user/index.mako | 6 +- templates/user/info.mako | 207 ++++++---------------------- templates/webapps/community/user/info.mako | 9 + templates/webapps/galaxy/user/info.mako | 122 +++++++++++++++++ 5 files changed, 252 insertions(+), 214 deletions(-) diffs (651 lines): diff -r 1dc7e6c15272 -r ed5535c4d48e lib/galaxy/web/controllers/user.py --- a/lib/galaxy/web/controllers/user.py Thu Apr 15 12:33:28 2010 -0400 +++ b/lib/galaxy/web/controllers/user.py Thu Apr 15 15:58:08 2010 -0400 @@ -297,6 +297,8 @@ def __validate_username( self, trans, username, user=None ): # User names must be at least four characters in length and contain only lower-case # letters, numbers, and the '-' character. + if username in [ 'None', None, '' ]: + return None if user and user.username == username: return None if len( username ) < 4: @@ -323,17 +325,14 @@ error = self.__validate_username( trans, username ) if not error: if webapp == 'galaxy': - # TODO: the user controller must be decoupled from the model, so this import causes problems. - # The get_all_forms method is used only if Galaxy is the webapp, so it needs to be re-worked - # so that it can be imported with no problems if the controller is not 'galaxy'. from galaxy.web.controllers.forms import get_all_forms if len( get_all_forms( trans, filter=dict( deleted=False ), form_type=trans.app.model.FormDefinition.types.USER_INFO ) ): if not params.get( 'user_info_select', False ): - return 'Select the user type and the user information' + return "Select the user's type and information" return error - def __user_info_ui(self, trans, user=None, **kwd): + def __user_info_ui( self, trans, user=None, **kwd ): ''' This method creates the user type select box & user information form widgets and is called during user registration and editing user information. @@ -342,14 +341,12 @@ show a selectbox containing all the forms, then the user can select the one that fits the user's description the most ''' - # TODO: the user controller must be decoupled from the model, so this import causes problems. - # The get_all_forms method is used only if Galaxy is the webapp, so it needs to be re-worked - # so that it can be imported with no problems if the controller is not 'galaxy'. from galaxy.web.controllers.forms import get_all_forms params = util.Params( kwd ) # get all the user information forms - user_info_forms = get_all_forms( trans, filter=dict(deleted=False), - form_type=trans.app.model.FormDefinition.types.USER_INFO ) + user_info_forms = get_all_forms( trans, + filter=dict( deleted=False ), + form_type=trans.app.model.FormDefinition.types.USER_INFO ) user_info_select = None if user: if user.values: @@ -398,19 +395,15 @@ information, public user name, reset password & other user information obtained during registration ''' - # TODO: the user controller must be decoupled from the model, so this import causes problems. - # The get_all_forms method is used only if Galaxy is the webapp, so it needs to be re-worked - # so that it can be imported with no problems if the controller is not 'galaxy'. - from galaxy.web.controllers.forms import get_all_forms params = util.Params( kwd ) user_id = params.get( 'user_id', None ) + webapp = params.get( 'webapp', 'galaxy' ) if user_id: user = trans.sa_session.query( trans.app.model.User ).get( int( user_id ) ) else: user = trans.user if not user: - # TODO: handle this without the deprecated exception. - raise "In show_info, we don't have a valid user" + raise AssertionError, "The user id (%s) is not valid" % str( user_id ) email = util.restore_text( params.get( 'email', user.email ) ) # Do not sanitize passwords, so take from kwd # instead of params ( which were sanitized ) @@ -423,38 +416,55 @@ admin_view = util.string_as_bool( params.get( 'admin_view', False ) ) message = util.restore_text( params.get( 'message', '' ) ) status = params.get( 'status', 'done' ) - user_info_select, user_info_form, widgets = self.__user_info_ui( trans, 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] + if webapp == 'galaxy': + from galaxy.web.controllers.forms import get_all_forms + user_info_select, user_info_form, widgets = self.__user_info_ui( trans, 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 = get_all_forms( trans, + filter=dict( deleted=False ), + form_type=trans.app.model.FormDefinition.types.USER_INFO ) + return trans.fill_template( '/webapps/galaxy/user/info.mako', + user=user, + email=email, + current=current, + password=password, + confirm=confirm, + username=username, + user_info_select=user_info_select, + user_info_forms=user_info_forms, + user_info_form=user_info_form, + widgets=widgets, + addresses=addresses, + show_filter=show_filter, + admin_view=admin_view, + webapp=webapp, + message=message, + status=status ) else: - addresses = [address for address in user.addresses if not address.deleted] - user_info_forms = get_all_forms( trans, filter=dict(deleted=False), - form_type=trans.app.model.FormDefinition.types.USER_INFO ) - return trans.fill_template( '/user/info.mako', - user=user, - email=email, - current=current, - password=password, - confirm=confirm, - username=username, - user_info_select=user_info_select, - user_info_forms=user_info_forms, - user_info_form=user_info_form, - widgets=widgets, - addresses=addresses, - show_filter=show_filter, - admin_view=admin_view, - message=message, - status=status ) + return trans.fill_template( '/webapps/community/user/info.mako', + user=user, + email=email, + current=current, + password=password, + confirm=confirm, + username=username, + admin_view=False, + webapp=webapp, + message=message, + status=status ) @web.expose def edit_info( self, trans, **kwd ): params = util.Params( kwd ) user_id = params.get( 'user_id', None ) admin_view = util.string_as_bool( params.get( 'admin_view', False ) ) + webapp = params.get( 'webapp', 'galaxy' ) message = util.restore_text( params.get( 'message', '' ) ) status = params.get( 'status', 'done' ) if user_id: @@ -467,11 +477,12 @@ username = util.restore_text( params.get( 'username', '' ) ).lower() # validate the new values error = self.__validate_email( trans, email, user ) - if not error: + if not error and username: error = self.__validate_username( trans, username, user ) if error: return trans.response.send_redirect( web.url_for( controller='user', action='show_info', + webapp=webapp, message=error, status='error') ) # The user's private role name must match the user's login ( email ) @@ -484,15 +495,17 @@ trans.sa_session.add_all( ( user, private_role ) ) trans.sa_session.flush() message = 'The login information has been updated with the changes' - if admin_view: + if webapp == 'galaxy' and admin_view: return trans.response.send_redirect( web.url_for( controller='user', action='show_info', user_id=user.id, admin_view=admin_view, + webapp=webapp, message=message, status='done' ) ) return trans.response.send_redirect( web.url_for( controller='user', action='show_info', + webapp=webapp, message=message, status='done') ) # Change password @@ -502,27 +515,30 @@ password = kwd.get( 'password', '' ) confirm = kwd.get( 'confirm', '' ) # When from the user perspective, validate the current password - if not admin_view: + if not webapp == 'galaxy' and not admin_view: # Do not sanitize passwords, so get from kwd and not params # ( which were sanitized ). current = kwd.get( 'current', '' ) if not trans.user.check_password( current ): return trans.response.send_redirect( web.url_for( controller='user', action='show_info', + webapp=webapp, message='Invalid current password', status='error') ) # validate the new values error = self.__validate_password( trans, password, confirm ) if error: - if admin_view: + if webapp == 'galaxy' and admin_view: return trans.response.send_redirect( web.url_for( controller='user', action='show_info', + webapp=webapp, user_id=user.id, admin_view=admin_view, message=error, status='error' ) ) return trans.response.send_redirect( web.url_for( controller='user', action='show_info', + webapp=webapp, message=error, status='error') ) # save new password @@ -531,40 +547,46 @@ trans.sa_session.flush() trans.log_event( "User change password" ) message = 'The password has been changed.' - if admin_view: + if webapp == 'galaxy' and admin_view: return trans.response.send_redirect( web.url_for( controller='user', action='show_info', + webapp=webapp, user_id=user.id, admin_view=admin_view, message=message, status='done' ) ) return trans.response.send_redirect( web.url_for( controller='user', action='show_info', + webapp=webapp, message=message, status='done') ) - # Edit user information + # Edit user information - webapp MUST BE 'galaxy' elif params.get( 'edit_user_info_button', False ): self.__save_user_info(trans, user, "show_info", new_user=False, **kwd) message = "The user information has been updated with the changes." if admin_view: return trans.response.send_redirect( web.url_for( controller='user', action='show_info', + webapp=webapp, user_id=user.id, admin_view=admin_view, message=message, status='done' ) ) return trans.response.send_redirect( web.url_for( controller='user', action='show_info', + webapp=webapp, message=message, status='done') ) else: - if admin_view: + if webapp == 'galaxy' and admin_view: return trans.response.send_redirect( web.url_for( controller='user', action='show_info', + webapp=webapp, user_id=user.id, admin_view=admin_view ) ) return trans.response.send_redirect( web.url_for( controller='user', - action='show_info' ) ) + action='show_info', + webapp=webapp ) ) @web.expose def reset_password( self, trans, email=None, webapp='galaxy', **kwd ): message = util.restore_text( kwd.get( 'message', '' ) ) diff -r 1dc7e6c15272 -r ed5535c4d48e templates/user/index.mako --- a/templates/user/index.mako Thu Apr 15 12:33:28 2010 -0400 +++ b/templates/user/index.mako Thu Apr 15 15:58:08 2010 -0400 @@ -10,8 +10,10 @@ <p>You are currently logged in as ${trans.user.email}.</p> <ul> %if webapp == 'galaxy': - <li><a href="${h.url_for( action='show_info' )}">${_('Manage your information')}</a></li> - <li><a href="${h.url_for( action='set_default_permissions' )}">${_('Change default permissions')}</a> for new histories</li> + <li><a href="${h.url_for( controller='user', action='show_info' )}">${_('Manage your information')}</a></li> + <li><a href="${h.url_for( controller='user', action='set_default_permissions' )}">${_('Change default permissions')}</a> for new histories</li> + %else: + <li><a href="${h.url_for( controller='user', action='show_info', webapp='community' )}">${_('Manage your information')}</a></li> %endif </ul> %else: diff -r 1dc7e6c15272 -r ed5535c4d48e templates/user/info.mako --- a/templates/user/info.mako Thu Apr 15 12:33:28 2010 -0400 +++ b/templates/user/info.mako Thu Apr 15 15:58:08 2010 -0400 @@ -1,176 +1,59 @@ <%inherit file="/base.mako"/> -<%namespace file="/message.mako" import="render_msg" /> -%if message: - ${render_msg( message, status )} -%endif - -<h2>Manage User Information</h2> -%if not admin_view: - <ul class="manage-table-actions"> - <li> - <a class="action-button" href="${h.url_for( controller='user', action='index')}"> - <span>User preferences</span></a> - </li> - </ul> -%endif - -<script type="text/javascript"> -$( function() { - $( "select[refresh_on_change='true']").change( function() { - var refresh = false; - var refresh_on_change_values = $( this )[0].attributes.getNamedItem( 'refresh_on_change_values' ) - if ( refresh_on_change_values ) { - refresh_on_change_values = refresh_on_change_values.value.split( ',' ); - var last_selected_value = $( this )[0].attributes.getNamedItem( 'last_selected_value' ); - for( i= 0; i < refresh_on_change_values.length; i++ ) { - if ( $( this )[0].value == refresh_on_change_values[i] || ( last_selected_value && last_selected_value.value == refresh_on_change_values[i] ) ){ - refresh = true; - break; - } - } - } - else { - refresh = true; - } - if ( refresh ){ - $( "#user_info" ).submit(); - } - }); -}); -</script> - -<div class="toolForm"> - <form name="login_info" id="login_info" action="${h.url_for( controller='user', action='edit_info', user_id=user.id, admin_view=admin_view )}" method="post" > - <div class="toolFormTitle">Login Information</div> - <div class="form-row"> - <label>Email address:</label> - <input type="text" name="email" value="${email}" size="40"/> - </div> - <div class="form-row"> - <label>Public user name:</label> - <input type="text" name="username" size="40" value="${username}"/> - <div class="toolParamHelp" style="clear: both;"> - Your user name is an optional identifier that will be used to generate addresses for information - you share publicly. User names must be at least four characters in length and contain only lower-case - letters, numbers, and the '-' character. +<%def name="render_user_info()"> + <h2>Manage User Information</h2> + %if not admin_view: + <ul class="manage-table-actions"> + <li> + <a class="action-button" href="${h.url_for( controller='user', action='index' )}"> + <span>User preferences</span></a> + </li> + </ul> + %endif + <div class="toolForm"> + <form name="login_info" id="login_info" action="${h.url_for( controller='user', action='edit_info', user_id=user.id, admin_view=admin_view )}" method="post" > + <div class="toolFormTitle">Login Information</div> + <div class="form-row"> + <label>Email address:</label> + <input type="text" name="email" value="${email}" size="40"/> </div> - </div> - <div class="form-row"> - <input type="submit" name="login_info_button" value="Save"/> - </div> - </form> -</div> -<p></p> -<div class="toolForm"> - <form name="change_password" id="change_password" action="${h.url_for( controller='user', action='edit_info', user_id=user.id, admin_view=admin_view )}" method="post" > - <div class="toolFormTitle">Change Password</div> - %if not admin_view: <div class="form-row"> - <label>Current Password:</label> - <input type="password" name="current" value="${current}" size="40"/> + <label>Public user name:</label> + <input type="text" name="username" size="40" value="${username}"/> + <div class="toolParamHelp" style="clear: both;"> + Your user name is an optional identifier that will be used to generate addresses for information + you share publicly. User names must be at least four characters in length and contain only lower-case + letters, numbers, and the '-' character. + </div> </div> - %endif - <div class="form-row"> - <label>New Password:</label> - <input type="password" name="password" value="${password}" size="40"/> - </div> - <div class="form-row"> - <label>Confirm:</label> - <input type="password" name="confirm" value="${confirm}" size="40"/> - </div> - <div class="form-row"> - <input type="submit" name="change_password_button" value="Save"/> - </div> - </form> -</div> -%if user.values or user_info_forms: - <p></p> - <div class="toolForm"> - <form name="user_info" id="user_info" action="${h.url_for( controller='user', action='edit_info', user_id=user.id, admin_view=admin_view )}" method="post" > - <div class="toolFormTitle">User information</div> - %if user_info_select: - <div class="form-row"> - <label>User type:</label> - ${user_info_select.get_html()} - </div> - %endif - - %for field in widgets: - <div class="form-row"> - <label>${field['label']}:</label> - ${field['widget'].get_html()} - <div class="toolParamHelp" style="clear: both;"> - ${field['helptext']} - </div> - <div style="clear: both"></div> - </div> - %endfor - %if not user_info_select: - <input type="hidden" name="user_info_select" value="${user_info_form.id}"/> - %endif - <div class="form-row"> - <input type="submit" name="edit_user_info_button" value="Save"/> + <input type="hidden" name="webapp" value="${webapp}" size="40"/> + <input type="submit" name="login_info_button" value="Save"/> </div> </form> </div> -%endif -<p></p> -<div class="toolForm"> - <form name="user_info" id="user_info" action="${h.url_for( controller='user', action='new_address', user_id=user.id, admin_view=admin_view )}" method="post" > - <div class="toolFormTitle">User Addresses</div> - <div class="toolFormBody"> - %if user.addresses: + <p></p> + <div class="toolForm"> + <form name="change_password" id="change_password" action="${h.url_for( controller='user', action='edit_info', user_id=user.id, admin_view=admin_view )}" method="post" > + <div class="toolFormTitle">Change Password</div> + %if not admin_view: <div class="form-row"> - <div class="grid-header"> - ##<span class="title">Filter:</span> - %for i, filter in enumerate( ['Active', 'Deleted', 'All'] ): - %if i > 0: - <span>|</span> - %endif - %if show_filter == filter: - <span class="filter"><a href="${h.url_for( controller='user', action='show_info', show_filter=filter, user_id=user.id, admin_view=admin_view )}"><b>${filter}</b></a></span> - %else: - <span class="filter"><a href="${h.url_for( controller='user', action='show_info', show_filter=filter, user_id=user.id, admin_view=admin_view )}">${filter}</a></span> - %endif - %endfor + <label>Current Password:</label> + <input type="password" name="current" value="${current}" size="40"/> </div> - </div> - <table class="grid"> - <tbody> - %for index, address in enumerate(addresses): - <tr class="libraryRow libraryOrFolderRow" id="libraryRow"> - <td> - <div class="form-row"> - <label>${address.desc}:</label> - ${address.get_html()} - </div> - <div class="form-row"> - <ul class="manage-table-actions"> - <li> - %if not address.deleted: - <a class="action-button" href="${h.url_for( controller='user', action='edit_address', admin_view=admin_view, address_id=address.id, user_id=user.id )}"> - <span>Edit</span></a> - <a class="action-button" href="${h.url_for( controller='user', action='delete_address', admin_view=admin_view, address_id=address.id, user_id=user.id)}"> - <span>Delete</span></a> - %else: - <a class="action-button" href="${h.url_for( controller='user', action='undelete_address', admin_view=admin_view, address_id=address.id, user_id=user.id)}"> - <span>Undelete</span></a> - %endif - - </li> - </ul> - </div> - </td> - </tr> - %endfor - </tbody> - </table> %endif <div class="form-row"> - <input type="submit" value="Add a new address"> + <label>New Password:</label> + <input type="password" name="password" value="${password}" size="40"/> </div> - </div> - </form> -</div> + <div class="form-row"> + <label>Confirm:</label> + <input type="password" name="confirm" value="${confirm}" size="40"/> + </div> + <div class="form-row"> + <input type="hidden" name="webapp" value="${webapp}" size="40"/> + <input type="submit" name="change_password_button" value="Save"/> + </div> + </form> + </div> +</%def> diff -r 1dc7e6c15272 -r ed5535c4d48e templates/webapps/community/user/info.mako --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/webapps/community/user/info.mako Thu Apr 15 15:58:08 2010 -0400 @@ -0,0 +1,9 @@ +<%inherit file="/base.mako"/> +<%namespace file="/user/info.mako" import="render_user_info" /> +<%namespace file="/message.mako" import="render_msg" /> + +%if message: + ${render_msg( message, status )} +%endif + +${render_user_info()} diff -r 1dc7e6c15272 -r ed5535c4d48e templates/webapps/galaxy/user/info.mako --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/webapps/galaxy/user/info.mako Thu Apr 15 15:58:08 2010 -0400 @@ -0,0 +1,122 @@ +<%inherit file="/base.mako"/> +<%namespace file="/user/info.mako" import="render_user_info" /> +<%namespace file="/message.mako" import="render_msg" /> + +<script type="text/javascript"> +$( function() { + $( "select[refresh_on_change='true']").change( function() { + var refresh = false; + var refresh_on_change_values = $( this )[0].attributes.getNamedItem( 'refresh_on_change_values' ) + if ( refresh_on_change_values ) { + refresh_on_change_values = refresh_on_change_values.value.split( ',' ); + var last_selected_value = $( this )[0].attributes.getNamedItem( 'last_selected_value' ); + for( i= 0; i < refresh_on_change_values.length; i++ ) { + if ( $( this )[0].value == refresh_on_change_values[i] || ( last_selected_value && last_selected_value.value == refresh_on_change_values[i] ) ){ + refresh = true; + break; + } + } + } + else { + refresh = true; + } + if ( refresh ){ + $( "#user_info" ).submit(); + } + }); +}); +</script> + +%if message: + ${render_msg( message, status )} +%endif + +${render_user_info()} + +%if user.values or user_info_forms: + <p></p> + <div class="toolForm"> + <form name="user_info" id="user_info" action="${h.url_for( controller='user', action='edit_info', user_id=user.id, admin_view=admin_view )}" method="post" > + <div class="toolFormTitle">User information</div> + %if user_info_select: + <div class="form-row"> + <label>User type:</label> + ${user_info_select.get_html()} + </div> + %endif + %for field in widgets: + <div class="form-row"> + <label>${field['label']}:</label> + ${field['widget'].get_html()} + <div class="toolParamHelp" style="clear: both;"> + ${field['helptext']} + </div> + <div style="clear: both"></div> + </div> + %endfor + %if not user_info_select: + <input type="hidden" name="user_info_select" value="${user_info_form.id}"/> + %endif + + <div class="form-row"> + <input type="submit" name="edit_user_info_button" value="Save"/> + </div> + </form> + </div> + <p></p> +%endif + +<div class="toolForm"> + <p></p> + <form name="user_info" id="user_info" action="${h.url_for( controller='user', action='new_address', user_id=user.id, admin_view=admin_view )}" method="post" > + <div class="toolFormTitle">User Addresses</div> + <div class="toolFormBody"> + %if user.addresses: + <div class="form-row"> + <div class="grid-header"> + %for i, filter in enumerate( ['Active', 'Deleted', 'All'] ): + %if i > 0: + <span>|</span> + %endif + %if show_filter == filter: + <span class="filter"><a href="${h.url_for( controller='user', action='show_info', show_filter=filter, user_id=user.id, admin_view=admin_view )}"><b>${filter}</b></a></span> + %else: + <span class="filter"><a href="${h.url_for( controller='user', action='show_info', show_filter=filter, user_id=user.id, admin_view=admin_view )}">${filter}</a></span> + %endif + %endfor + </div> + </div> + <table class="grid"> + <tbody> + %for index, address in enumerate(addresses): + <tr class="libraryRow libraryOrFolderRow" id="libraryRow"> + <td> + <div class="form-row"> + <label>${address.desc}:</label> + ${address.get_html()} + </div> + <div class="form-row"> + <ul class="manage-table-actions"> + <li> + %if not address.deleted: + <a class="action-button" href="${h.url_for( controller='user', action='edit_address', admin_view=admin_view, address_id=address.id, user_id=user.id )}"><span>Edit</span></a> + <a class="action-button" href="${h.url_for( controller='user', action='delete_address', admin_view=admin_view, address_id=address.id, user_id=user.id)}"><span>Delete</span></a> + %else: + <a class="action-button" href="${h.url_for( controller='user', action='undelete_address', admin_view=admin_view, address_id=address.id, user_id=user.id)}"><span>Undelete</span></a> + %endif + </li> + </ul> + </div> + </td> + </tr> + %endfor + </tbody> + </table> + %endif + <div class="form-row"> + <input type="submit" value="Add a new address"> + </div> + </div> + </form> + <p></p> +</div>
participants (1)
-
Greg Von Kuster