1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/5db0da0007fc/ changeset: 5db0da0007fc user: greg date: 2011-11-28 22:31:04 summary: Make the use of the 'require_login' config setting functionally correct for the tool shed, and debug it's use in the Galaxy framework as well. affected #: 5 files diff -r 3ee9430186fbe87dd2053b0d4efdc00e70a04b45 -r 5db0da0007fcc59bb23f0e0ae2edb1e961702f14 lib/galaxy/web/controllers/user.py --- a/lib/galaxy/web/controllers/user.py +++ b/lib/galaxy/web/controllers/user.py @@ -15,15 +15,11 @@ log = logging.getLogger( __name__ ) require_login_template = """ -<h1>Welcome to Galaxy</h1> - <p> - This installation of Galaxy has been configured such that only users who are logged in may use it.%s + This %s has been configured such that only users who are logged in may use it.%s </p><p/> """ -require_login_nocreation_template = require_login_template % "" -require_login_creation_template = require_login_template % " If you don't already have an account, <a href='%s'>you may create one</a>." OPENID_PROVIDERS = { 'Google' : 'https://www.google.com/accounts/o8/id', 'Yahoo!' : 'http://yahoo.com', @@ -362,15 +358,23 @@ else: refresh_frames = [ 'masthead', 'history' ] message, status, user, success = self.__validate_login( trans, webapp, **kwd ) - if success and referer and not referer.startswith( trans.request.base + url_for( controller='user', action='logout' ) ): + if success and referer and not referer.startswith( url_for( trans.request.base + url_for( controller='user', action='logout' ) ) ): redirect_url = referer elif success: redirect_url = url_for( '/' ) if not user and trans.app.config.require_login: if trans.app.config.allow_user_creation: - header = require_login_creation_template % web.url_for( action='create', cntrller='user' ) + create_account_str = " If you don't already have an account, <a href='%s'>you may create one</a>." % \ + web.url_for( action='create', cntrller='user', webapp=webapp ) + if webapp == 'galaxy': + header = require_login_template % ( "Galaxy instance", create_account_str ) + else: + header = require_login_template % ( "Galaxy tool shed", create_account_str ) else: - header = require_login_nocreation_template + if webapp == 'galaxy': + header = require_login_template % ( "Galaxy instance", "" ) + else: + header = require_login_template % ( "Galaxy tool shed", "" ) return trans.fill_template( '/user/login.mako', webapp=webapp, email=email, @@ -405,11 +409,12 @@ status = 'error' else: trans.handle_user_login( user, webapp ) - trans.log_event( "User logged in" ) - message = 'You are now logged in as %s.<br>You can <a target="_top" href="%s">go back to the page you were visiting</a> or <a target="_top" href="%s">go to the home page</a>.' % \ - ( user.email, referer, url_for( '/' ) ) - if trans.app.config.require_login: - message += ' <a target="_top" href="%s">Click here</a> to continue to the home page.' % web.url_for( '/static/welcome.html' ) + if webapp == 'galaxy': + trans.log_event( "User logged in" ) + message = 'You are now logged in as %s.<br>You can <a target="_top" href="%s">go back to the page you were visiting</a> or <a target="_top" href="%s">go to the home page</a>.' % \ + ( user.email, referer, url_for( '/' ) ) + if trans.app.config.require_login: + message += ' <a target="_top" href="%s">Click here</a> to continue to the home page.' % web.url_for( '/static/welcome.html' ) success = True return ( message, status, user, success ) @web.expose @@ -419,10 +424,10 @@ refresh_frames = [ 'masthead', 'history', 'tools' ] else: refresh_frames = [ 'masthead', 'history' ] + # Since logging an event requires a session, we'll log prior to ending the session + trans.log_event( "User logged out" ) else: refresh_frames = [ 'masthead' ] - # 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( logout_all=logout_all ) message = 'You have been logged out.<br>You can log in again, <a target="_top" href="%s">go back to the page you were visiting</a> or <a target="_top" href="%s">go to the home page</a>.' % \ ( trans.request.referer, url_for( '/' ) ) @@ -471,10 +476,8 @@ cntrller, subscribe_checked, **kwd ) - if success and not is_admin and webapp != 'galaxy': - # Must be logging into the community space webapp - trans.handle_user_login( user, webapp ) - redirect_url = referer + if webapp == 'community': + redirect_url = url_for( '/' ) if success and not is_admin: # 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 diff -r 3ee9430186fbe87dd2053b0d4efdc00e70a04b45 -r 5db0da0007fcc59bb23f0e0ae2edb1e961702f14 lib/galaxy/web/framework/__init__.py --- a/lib/galaxy/web/framework/__init__.py +++ b/lib/galaxy/web/framework/__init__.py @@ -404,26 +404,38 @@ # If the old session was invalid, get a new history with our new session if invalidate_existing_session: self.new_history() - def _ensure_logged_in_user( self, environ ): - allowed_paths = ( - url_for( controller='root', action='index' ), - url_for( controller='root', action='tool_menu' ), - url_for( controller='root', action='masthead' ), - url_for( controller='root', action='history' ), - url_for( controller='user', action='login' ), - url_for( controller='user', action='create' ), - url_for( controller='user', action='reset_password' ), - url_for( controller='library', action='browse' ) - ) - display_as = url_for( controller='root', action='display_as' ) - if self.galaxy_session.user is None: - if self.app.config.ucsc_display_sites and self.request.path == display_as: - try: - host = socket.gethostbyaddr( self.environ[ 'REMOTE_ADDR' ] )[0] - except( socket.error, socket.herror, socket.gaierror, socket.timeout ): - host = None - if host in UCSC_SERVERS: - return + def _ensure_logged_in_user( self, environ, session_cookie ): + # The value of session_cookie can be one of + # 'galaxysession' or 'galaxycommunitysession' + if session_cookie == 'galaxysession': + # TODO: re-engineer to eliminate the use of allowed_paths + # as maintenance overhead is far too high. + allowed_paths = ( + url_for( controller='root', action='index' ), + url_for( controller='root', action='tool_menu' ), + url_for( controller='root', action='masthead' ), + url_for( controller='root', action='history' ), + url_for( controller='user', action='api_keys' ), + url_for( controller='user', action='create' ), + url_for( controller='user', action='index' ), + url_for( controller='user', action='login' ), + url_for( controller='user', action='logout' ), + url_for( controller='user', action='manage_user_info' ), + url_for( controller='user', action='set_default_permissions' ), + url_for( controller='user', action='reset_password' ), + url_for( controller='library', action='browse' ), + url_for( controller='history', action='list' ), + url_for( controller='dataset', action='list' ) + ) + display_as = url_for( controller='root', action='display_as' ) + if self.galaxy_session.user is None: + if self.app.config.ucsc_display_sites and self.request.path == display_as: + try: + host = socket.gethostbyaddr( self.environ[ 'REMOTE_ADDR' ] )[0] + except( socket.error, socket.herror, socket.gaierror, socket.timeout ): + host = None + if host in UCSC_SERVERS: + return if self.request.path not in allowed_paths: self.response.send_redirect( url_for( controller='root', action='index' ) ) def __create_new_session( self, prev_galaxy_session=None, user_for_new_session=None ): @@ -857,7 +869,7 @@ if self.app.config.use_remote_user and self.galaxy_session.user.deleted: self.response.send_redirect( url_for( '/static/user_disabled.html' ) ) if self.app.config.require_login: - self._ensure_logged_in_user( environ ) + self._ensure_logged_in_user( environ, session_cookie ) def get_user( self ): """Return the current user if logged in or None.""" return self.galaxy_session.user diff -r 3ee9430186fbe87dd2053b0d4efdc00e70a04b45 -r 5db0da0007fcc59bb23f0e0ae2edb1e961702f14 templates/user/index.mako --- a/templates/user/index.mako +++ b/templates/user/index.mako @@ -10,25 +10,25 @@ <p>You are currently logged in as ${trans.user.email}.</p><ul> %if webapp == 'galaxy': - <li><a href="${h.url_for( controller='user', action='manage_user_info', cntrller=cntrller )}">${_('Manage your information')}</a></li> - <li><a href="${h.url_for( controller='user', action='set_default_permissions', cntrller=cntrller )}">${_('Change default permissions')}</a> for new histories</li> + <li><a href="${h.url_for( controller='user', action='manage_user_info', cntrller=cntrller, webapp=webapp )}">${_('Manage your information')}</a></li> + <li><a href="${h.url_for( controller='user', action='set_default_permissions', cntrller=cntrller, webapp=webapp )}">${_('Change default permissions')}</a> for new histories</li> %if trans.app.config.enable_api: - <li><a href="${h.url_for( controller='user', action='api_keys', cntrller=cntrller )}">${_('Manage your API keys')}</a></li> + <li><a href="${h.url_for( controller='user', action='api_keys', cntrller=cntrller, webapp=webapp )}">${_('Manage your API keys')}</a></li> %endif %if trans.app.config.enable_openid: - <li><a href="${h.url_for( controller='user', action='openid_manage', cntrller=cntrller )}">${_('Manage OpenIDs')}</a> linked to your account</li> + <li><a href="${h.url_for( controller='user', action='openid_manage', cntrller=cntrller, webapp=webapp )}">${_('Manage OpenIDs')}</a> linked to your account</li> %endif %if trans.app.config.use_remote_user: %if trans.app.config.remote_user_logout_href: <li><a href="${trans.app.config.remote_user_logout_href}" target="_top">${_('Logout')}</a></li> %endif %else: - <li><a href="${h.url_for( controller='user', action='logout', logout_all=True )}" target="_top">${_('Logout')}</a> ${_('of all user sessions')}</li> + <li><a href="${h.url_for( controller='user', action='logout', webapp=webapp, logout_all=True )}" target="_top">${_('Logout')}</a> ${_('of all user sessions')}</li> %endif %else: - <li><a href="${h.url_for( controller='user', action='manage_user_info', cntrller=cntrller, webapp='community' )}">${_('Manage your information')}</a></li> - <li><a href="${h.url_for( controller='repository', action='manage_email_alerts', cntrller=cntrller, webapp='community' )}">${_('Manage your email alerts')}</a></li> - <li><a href="${h.url_for( controller='user', action='logout', logout_all=True )}" target="_top">${_('Logout')}</a> ${_('of all user sessions')}</li> + <li><a href="${h.url_for( controller='user', action='manage_user_info', cntrller=cntrller, webapp=webapp )}">${_('Manage your information')}</a></li> + <li><a href="${h.url_for( controller='repository', action='manage_email_alerts', cntrller=cntrller, webapp=webapp )}">${_('Manage your email alerts')}</a></li> + <li><a href="${h.url_for( controller='user', action='logout', webapp=webapp, logout_all=True )}" target="_top">${_('Logout')}</a> ${_('of all user sessions')}</li> %endif </ul> %if webapp == 'galaxy': @@ -44,7 +44,7 @@ <p>${n_('You are currently not logged in.')}</p> %endif <ul> - <li><a href="${h.url_for( action='login' )}">${_('Login')}</li> - <li><a href="${h.url_for( action='create', cntrller='user' )}">${_('Register')}</a></li> + <li><a href="${h.url_for( action='login', webapp=webapp )}">${_('Login')}</li> + <li><a href="${h.url_for( action='create', cntrller='user', webapp=webapp )}">${_('Register')}</a></li></ul> %endif diff -r 3ee9430186fbe87dd2053b0d4efdc00e70a04b45 -r 5db0da0007fcc59bb23f0e0ae2edb1e961702f14 templates/webapps/community/base_panels.mako --- a/templates/webapps/community/base_panels.mako +++ b/templates/webapps/community/base_panels.mako @@ -74,12 +74,7 @@ %else: <li>Logged in as <span id="user-email">${user_email}</span></li><li><a target="galaxy_main" href="${h.url_for( controller='/user', action='index', cntrller='user', webapp='community' )}">Preferences</a></li> - <% - if app.config.require_login: - logout_url = h.url_for( controller='/root', action='index', webapp='community', m_c='user', m_a='logout' ) - else: - logout_url = h.url_for( controller='/user', action='logout', webapp='community' ) - %> + <% logout_url = h.url_for( controller='/user', action='logout', webapp='community' ) %><li><a target="_top" href="${logout_url}">Logout</a></li> %endif </ul> diff -r 3ee9430186fbe87dd2053b0d4efdc00e70a04b45 -r 5db0da0007fcc59bb23f0e0ae2edb1e961702f14 templates/webapps/galaxy/base_panels.mako --- a/templates/webapps/galaxy/base_panels.mako +++ b/templates/webapps/galaxy/base_panels.mako @@ -124,7 +124,7 @@ # Menu for user who is not logged in. menu_options = [ [ _("Login"), h.url_for( controller='/user', action='login' ), "galaxy_main" ] ] if app.config.allow_user_creation: - menu_options.append( [ _("Register"), h.url_for( controller='/user', action='create', cntrller='user' ), "galaxy_main" ] ) + menu_options.append( [ _("Register"), h.url_for( controller='/user', action='create', cntrller='user', webapp='galaxy' ), "galaxy_main" ] ) extra_class = "loggedout-only" visible = ( trans.user == None ) tab( "user", _("User"), None, visible=visible, menu_options=menu_options ) @@ -139,23 +139,19 @@ if app.config.remote_user_logout_href: menu_options.append( [ _('Logout'), app.config.remote_user_logout_href, "_top" ] ) else: - menu_options.append( [ _('Preferences'), h.url_for( controller='/user', action='index', cntrller='user' ), "galaxy_main" ] ) + menu_options.append( [ _('Preferences'), h.url_for( controller='/user', action='index', cntrller='user', webapp='galaxy' ), "galaxy_main" ] ) if app.config.get_bool( 'enable_tracks', False ): menu_options.append( [ 'Custom Builds', h.url_for( controller='/user', action='dbkeys' ), "galaxy_main" ] ) - if app.config.require_login: - logout_url = h.url_for( controller='/root', action='index', m_c='user', m_a='logout' ) - else: - logout_url = h.url_for( controller='/user', action='logout' ) - menu_options.append( [ 'Logout', logout_url, "_top" ] ) + menu_options.append( [ 'Logout', h.url_for( controller='/user', action='logout', webapp='galaxy' ), "_top" ] ) menu_options.append( None ) menu_options.append( [ _('Saved Histories'), h.url_for( controller='/history', action='list' ), "galaxy_main" ] ) menu_options.append( [ _('Saved Datasets'), h.url_for( controller='/dataset', action='list' ), "galaxy_main" ] ) if app.config.get_bool( 'enable_pages', False ): menu_options.append( [ _('Saved Pages'), h.url_for( controller='/page', action='list' ), "_top" ] ) if app.config.enable_api: - menu_options.append( [ _('API Keys'), h.url_for( controller='/user', action='api_keys', cntrller='user' ), "galaxy_main" ] ) + menu_options.append( [ _('API Keys'), h.url_for( controller='/user', action='api_keys', cntrller='user', webapp='galaxy' ), "galaxy_main" ] ) if app.config.use_remote_user: - menu_options.append( [ _('Public Name'), h.url_for( controller='/user', action='edit_username', cntrller='user' ), "galaxy_main" ] ) + menu_options.append( [ _('Public Name'), h.url_for( controller='/user', action='edit_username', cntrller='user', webapp='galaxy' ), "galaxy_main" ] ) extra_class = "loggedin-only" visible = ( trans.user != None ) Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.