[hg] galaxy 3588: Eliminate the use of message.mako from certain...
details: http://www.bx.psu.edu/hg/galaxy/rev/c30c7c98ce61 changeset: 3588:c30c7c98ce61 user: Greg Von Kuster <greg@bx.psu.edu> date: Wed Mar 31 16:25:21 2010 -0400 description: Eliminate the use of message.mako from certain methods in the user controller, and fix an issue with the handle_user_login method in the framework. diffstat: lib/galaxy/web/controllers/user.py | 101 +++++++++++++++++++++++++++++----- lib/galaxy/web/framework/__init__.py | 63 +++++++++++---------- 2 files changed, 118 insertions(+), 46 deletions(-) diffs (264 lines): diff -r 273535c97761 -r c30c7c98ce61 lib/galaxy/web/controllers/user.py --- a/lib/galaxy/web/controllers/user.py Wed Mar 31 13:11:05 2010 -0400 +++ b/lib/galaxy/web/controllers/user.py Wed Mar 31 16:25:21 2010 -0400 @@ -29,9 +29,7 @@ return trans.fill_template( '/user/index.mako', user=trans.get_user(), webapp=webapp ) @web.expose def login( self, trans, webapp='galaxy', **kwd ): - use_panels = kwd.get( 'use_panels', 'True' ) - # Convert use_panels to Boolean. - use_panels = use_panels in [ 'True', 'true', 't', 'T' ] + use_panels = util.string_as_bool( kwd.get( 'use_panels', True ) ) msg = kwd.get( 'msg', '' ) messagetype = kwd.get( 'messagetype', 'done' ) if kwd.get( 'login_button', False ): @@ -43,6 +41,8 @@ refresh_frames = [ 'masthead', 'history', 'tools' ] else: refresh_frames = [ 'masthead', 'history' ] + else: + refresh_frames = [] user = trans.sa_session.query( trans.app.model.User ).filter( trans.app.model.User.table.c.email==email ).first() if not user: msg = "No such user" @@ -63,7 +63,11 @@ ( user.email, referer, url_for( '/' ) ) if trans.app.config.require_login: msg += ' <a href="%s">Click here</a> to continue to the home page.' % web.url_for( '/static/welcome.html' ) - return trans.show_ok_message( msg, refresh_frames=refresh_frames, use_panels=use_panels, active_view="user" ) + return trans.response.send_redirect( web.url_for( controller='user', + action='login', + use_panels=use_panels, + msg=msg, + message_type='done' ) ) if trans.app.config.require_login: if trans.app.config.allow_user_creation: return trans.fill_template( '/user/login.mako', @@ -99,11 +103,12 @@ # Since logging an event requires a session, we'll log prior to ending the session trans.log_event( "User logged out" ) trans.handle_user_logout() - msg = "You have been logged out.<br>You can <a href='%s'>go back to the page you were visiting</a> or <a href='%s'>go to the home page</a>." % \ + msg = "You have been logged out.<br>You can log in again, <a href='%s'>go back to the page you were visiting</a> or <a href='%s'>go to the home page</a>." % \ ( trans.request.referer, url_for( '/' ) ) - if trans.app.config.require_login: - msg += ' <a href="%s">Click here</a> to return to the login page.' % web.url_for( controller='user', action='login' ) - return trans.show_ok_message( msg, refresh_frames=refresh_frames, use_panels=True, active_view="user" ) + return trans.response.send_redirect( web.url_for( controller='user', + action='login', + msg=msg, + message_type='done' ) ) @web.expose def create( self, trans, webapp='galaxy', **kwd ): params = util.Params( kwd ) @@ -126,8 +131,24 @@ refresh_frames = [ 'masthead', 'history', 'tools' ] else: refresh_frames = [ 'masthead', 'history' ] + else: + refresh_frames = [] if not trans.app.config.allow_user_creation and not trans.user_is_admin(): - return trans.show_error_message( 'User registration is disabled. Please contact your Galaxy administrator for an account.' ) + msg = 'User registration is disabled. Please contact your Galaxy administrator for an account.' + return trans.response.send_redirect( web.url_for( controller='user', + action='create', + webapp=webapp, + email=email, + password=password, + confirm=confirm, + username=username, + subscribe=subscribe, + subscribe_checked=subscribe_checked, + admin_view=admin_view, + use_panels=use_panels, + refresh_frames=refresh_frames, + msg=error, + messagetype='error' ) ) # Create the user, save all the user info and login to Galaxy if params.get( 'create_user_button', False ): # Check email and password validity @@ -135,7 +156,8 @@ if error: return trans.response.send_redirect( web.url_for( controller='user', action='create', - webapp=webapp,email=email, + webapp=webapp, + email=email, password=password, confirm=confirm, username=username, @@ -143,6 +165,7 @@ subscribe_checked=subscribe_checked, admin_view=admin_view, use_panels=use_panels, + refresh_frames=refresh_frames, msg=error, messagetype='error' ) ) # all the values are valid @@ -162,8 +185,21 @@ 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 ) + msg = "Now logged in as " + user.email + ". However, subscribing to the mailing list has failed." + return trans.response.send_redirect( web.url_for( controller='user', + action='create', + webapp=webapp, + email=email, + password=password, + confirm=confirm, + username=username, + subscribe=subscribe, + subscribe_checked=subscribe_checked, + admin_view=admin_view, + use_panels=use_panels, + refresh_frames=refresh_frames, + msg=error, + messagetype='warn' ) ) if not admin_view: # The handle_user_login() method has a call to the history_set_default_permissions() method # (needed when logging in with a history), user needs to have default permissions set before logging in @@ -171,16 +207,42 @@ trans.log_event( "User created a new account" ) trans.log_event( "User logged in" ) # subscribe user to email list - return trans.show_ok_message( "Now logged in as %s.<br><a href='%s'>Return to the home page.</a>" % \ - ( user.email, url_for( '/' ) ), refresh_frames=refresh_frames, use_panels=True ) + msg = "Now logged in as %s.<br><a href='%s'>Return to the home page.</a>" % ( user.email, url_for( '/' ) ) + return trans.response.send_redirect( web.url_for( controller='user', + action='create', + webapp=webapp, + email=email, + password=password, + confirm=confirm, + username=username, + subscribe=subscribe, + subscribe_checked=subscribe_checked, + admin_view=admin_view, + use_panels=True, + refresh_frames=refresh_frames, + msg=msg, + messagetype='done' ) ) else: trans.response.send_redirect( web.url_for( controller='admin', action='users', message='Created new user account (%s)' % user.email, status='done' ) ) else: - return trans.show_ok_message( "Now logged in as %s.<br><a href='%s'>Return to the home page.</a>" % \ - ( user.email, url_for( '/' ) ), use_panels=False ) + msg = "Now logged in as %s.<br><a href='%s'>Return to the home page.</a>" % ( user.email, url_for( '/' ) ) + return trans.response.send_redirect( web.url_for( controller='user', + action='create', + webapp=webapp, + email=email, + password=password, + confirm=confirm, + username=username, + subscribe=subscribe, + subscribe_checked=subscribe_checked, + admin_view=admin_view, + use_panels=False, + refresh_frames=refresh_frames, + msg=error, + messagetype='done' ) ) if webapp == 'galaxy': user_info_select, user_info_form, widgets = self.__user_info_ui( trans, **kwd ) else: @@ -414,6 +476,7 @@ 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" email = util.restore_text( params.get( 'email', user.email ) ) # Do not sanitize passwords, so take from kwd @@ -594,7 +657,11 @@ trans.sa_session.add( reset_user ) trans.sa_session.flush() trans.log_event( "User reset password: %s" % email ) - return trans.show_ok_message( "Password has been reset and emailed to: %s. <a href='%s'>Click here</a> to return to the login form." % ( email, web.url_for( action='login' ) ) ) + msg = "Password has been reset and emailed to: %s. <a href='%s'>Click here</a> to return to the login form." % ( email, web.url_for( action='login' ) ) + return trans.response.send_redirect( web.url_for( controller='user', + action='reset_password', + msg=msg, + messagetype='done' ) ) elif email != None: msg = "The specified user does not exist" messagetype = 'error' diff -r 273535c97761 -r c30c7c98ce61 lib/galaxy/web/framework/__init__.py --- a/lib/galaxy/web/framework/__init__.py Wed Mar 31 13:11:05 2010 -0400 +++ b/lib/galaxy/web/framework/__init__.py Wed Mar 31 16:25:21 2010 -0400 @@ -424,37 +424,42 @@ prev_galaxy_session.is_valid = False # Define a new current_session self.galaxy_session = self.__create_new_session( prev_galaxy_session, user ) - # Associated the current user's last accessed history (if exists) with their new session - history = None - try: - users_last_session = user.galaxy_sessions[0] - last_accessed = True - except: - users_last_session = None - last_accessed = False - if prev_galaxy_session.current_history and prev_galaxy_session.current_history.datasets: - if prev_galaxy_session.current_history.user is None or prev_galaxy_session.current_history.user == user: - # If the previous galaxy session had a history, associate it with the new - # session, but only if it didn't belong to a different user. - history = prev_galaxy_session.current_history - elif self.galaxy_session.current_history: - history = self.galaxy_session.current_history - if not history and users_last_session and users_last_session.current_history: - history = users_last_session.current_history - elif not history: - history = self.get_history( create=True ) - if history not in self.galaxy_session.histories: - self.galaxy_session.add_history( history ) - if history.user is None: - history.user = user - self.galaxy_session.current_history = history - if not last_accessed: - # Only set default history permissions if current history is not from a previous session - self.app.security_agent.history_set_default_permissions( history, dataset=True, bypass_manage_permission=True ) - self.sa_session.add_all( ( prev_galaxy_session, self.galaxy_session, history ) ) + if webapp == 'galaxy': + cookie_name = 'galaxysession' + # Associated the current user's last accessed history (if exists) with their new session + history = None + try: + users_last_session = user.galaxy_sessions[0] + last_accessed = True + except: + users_last_session = None + last_accessed = False + if prev_galaxy_session.current_history and prev_galaxy_session.current_history.datasets: + if prev_galaxy_session.current_history.user is None or prev_galaxy_session.current_history.user == user: + # If the previous galaxy session had a history, associate it with the new + # session, but only if it didn't belong to a different user. + history = prev_galaxy_session.current_history + elif self.galaxy_session.current_history: + history = self.galaxy_session.current_history + if not history and users_last_session and users_last_session.current_history: + history = users_last_session.current_history + elif not history: + history = self.get_history( create=True ) + if history not in self.galaxy_session.histories: + self.galaxy_session.add_history( history ) + if history.user is None: + history.user = user + self.galaxy_session.current_history = history + if not last_accessed: + # Only set default history permissions if current history is not from a previous session + self.app.security_agent.history_set_default_permissions( history, dataset=True, bypass_manage_permission=True ) + self.sa_session.add_all( ( prev_galaxy_session, self.galaxy_session, history ) ) + else: + cookie_name = 'galaxycommunitysession' + self.sa_session.add_all( ( prev_galaxy_session, self.galaxy_session ) ) self.sa_session.flush() # This method is not called from the Galaxy reports, so the cookie will always be galaxysession - self.__update_session_cookie( name='galaxysession' ) + self.__update_session_cookie( name=cookie_name ) def handle_user_logout( self ): """ Logout the current user:
participants (1)
-
Greg Von Kuster