diff --git a/jupyterhub/app.py b/jupyterhub/app.py index ac0829d9..2f6dfcc1 100644 --- a/jupyterhub/app.py +++ b/jupyterhub/app.py @@ -55,6 +55,7 @@ from traitlets import ( Instance, Bytes, Float, + Union, observe, default, validate, @@ -1314,12 +1315,23 @@ class JupyterHub(Application): """ ).tag(config=True) - default_url = Unicode( + default_url = Union( + [Unicode(), Callable()], help=""" The default URL for users when they arrive (e.g. when user directs to "/") By default, redirects users to their own server. - """ + + Can be a Unicode string (e.g. '/hub/home') or a callable based on the user object: + + def default_url_fn(user): + if user: + if user.admin: + return '/hub/admin' + return '/hub/home' + + c.JupyterHub.default_url = default_url_fn + """, ).tag(config=True) user_redirect_hook = Callable( diff --git a/jupyterhub/handlers/base.py b/jupyterhub/handlers/base.py index 6a3cac26..9c0833d5 100644 --- a/jupyterhub/handlers/base.py +++ b/jupyterhub/handlers/base.py @@ -638,8 +638,15 @@ class BaseHandler(RequestHandler): ) if not next_url: - # custom default URL - next_url = default or self.default_url + # custom default URL, usually passed because user landed on that page but was not logged in + if default: + next_url = default + else: + # As set in jupyterhub_config.py + if callable(self.default_url): + next_url = self.default_url(user) + else: + next_url = self.default_url if not next_url: # default URL after login