mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-15 22:13:00 +00:00
Allow JupyterHub.default_url to be a callable based on user
This commit is contained in:
@@ -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(
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user