mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-16 06:22:59 +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,
|
Instance,
|
||||||
Bytes,
|
Bytes,
|
||||||
Float,
|
Float,
|
||||||
|
Union,
|
||||||
observe,
|
observe,
|
||||||
default,
|
default,
|
||||||
validate,
|
validate,
|
||||||
@@ -1314,12 +1315,23 @@ class JupyterHub(Application):
|
|||||||
"""
|
"""
|
||||||
).tag(config=True)
|
).tag(config=True)
|
||||||
|
|
||||||
default_url = Unicode(
|
default_url = Union(
|
||||||
|
[Unicode(), Callable()],
|
||||||
help="""
|
help="""
|
||||||
The default URL for users when they arrive (e.g. when user directs to "/")
|
The default URL for users when they arrive (e.g. when user directs to "/")
|
||||||
|
|
||||||
By default, redirects users to their own server.
|
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)
|
).tag(config=True)
|
||||||
|
|
||||||
user_redirect_hook = Callable(
|
user_redirect_hook = Callable(
|
||||||
|
@@ -638,8 +638,15 @@ class BaseHandler(RequestHandler):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if not next_url:
|
if not next_url:
|
||||||
# custom default URL
|
# custom default URL, usually passed because user landed on that page but was not logged in
|
||||||
next_url = default or self.default_url
|
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:
|
if not next_url:
|
||||||
# default URL after login
|
# default URL after login
|
||||||
|
Reference in New Issue
Block a user