From 9f6cef4fb4b1031c7f4e4fe3e6f75247a850d524 Mon Sep 17 00:00:00 2001 From: Robert Schroll Date: Mon, 5 Feb 2018 18:12:07 -0800 Subject: [PATCH] Add option to redirect to running Jupyter server This is how the system used to behave, but now it can be turned off, always showing the control panel on login. Adjustment is needed in two places. --- jupyterhub/app.py | 4 ++++ jupyterhub/handlers/base.py | 6 +++++- jupyterhub/handlers/pages.py | 7 ++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/jupyterhub/app.py b/jupyterhub/app.py index 7ce3fb7b..0985493c 100644 --- a/jupyterhub/app.py +++ b/jupyterhub/app.py @@ -249,6 +249,9 @@ class JupyterHub(Application): Default is two weeks. """ ).tag(config=True) + redirect_to_server = Bool(True, + help="Redirect user to server (if running), instead of control panel." + ).tag(config=True) last_activity_interval = Integer(300, help="Interval (in seconds) at which to update last-activity timestamps." ).tag(config=True) @@ -1326,6 +1329,7 @@ class JupyterHub(Application): base_url=self.base_url, cookie_secret=self.cookie_secret, cookie_max_age_days=self.cookie_max_age_days, + redirect_to_server=self.redirect_to_server, login_url=login_url, logout_url=logout_url, static_path=os.path.join(self.data_files_path, 'static'), diff --git a/jupyterhub/handlers/base.py b/jupyterhub/handlers/base.py index 8a003beb..87ddda44 100644 --- a/jupyterhub/handlers/base.py +++ b/jupyterhub/handlers/base.py @@ -165,6 +165,10 @@ class BaseHandler(RequestHandler): def cookie_max_age_days(self): return self.settings.get('cookie_max_age_days', None) + @property + def redirect_to_server(self): + return self.settings.get('redirect_to_server', True) + def get_auth_token(self): """Get the authorization token from Authorization header""" auth_header = self.request.headers.get('Authorization', '') @@ -394,7 +398,7 @@ class BaseHandler(RequestHandler): if not next_url.startswith('/'): next_url = '' if not next_url: - if user and user.running: + if user and user.running and self.redirect_to_server: next_url = user.url else: next_url = self.hub.base_url diff --git a/jupyterhub/handlers/pages.py b/jupyterhub/handlers/pages.py index 91b98d8c..3ab79d58 100644 --- a/jupyterhub/handlers/pages.py +++ b/jupyterhub/handlers/pages.py @@ -45,12 +45,13 @@ class RootHandler(BaseHandler): return user = self.get_current_user() if user: + url = url_path_join(self.hub.base_url, 'home') if user.running: - url = user.url - self.log.debug("User is running: %s", url) + if self.redirect_to_server: + url = user.url + self.log.debug("User is running: %s", user.url) self.set_login_cookie(user) # set cookie else: - url = url_path_join(self.hub.base_url, 'home') self.log.debug("User is not running: %s", url) else: url = self.settings['login_url']