From cd0b3e05e2a881c994e35206f3f060183f4a5b3b Mon Sep 17 00:00:00 2001 From: Rollin Thomas Date: Sat, 5 Oct 2019 10:43:51 -0700 Subject: [PATCH 1/3] Add service links --- jupyterhub/handlers/base.py | 11 +++++++++++ share/jupyterhub/templates/page.html | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/jupyterhub/handlers/base.py b/jupyterhub/handlers/base.py index 03d9cf3b..054e4a82 100644 --- a/jupyterhub/handlers/base.py +++ b/jupyterhub/handlers/base.py @@ -1107,11 +1107,22 @@ class BaseHandler(RequestHandler): logout_url=self.settings['logout_url'], static_url=self.static_url, version_hash=self.version_hash, + services=self.get_accessible_services(user), ) if self.settings['template_vars']: ns.update(self.settings['template_vars']) return ns + def get_accessible_services(self, user): + accessible_services = list() + for service in self.services.values(): + if not service.url: + continue + if service.admin and not user.admin: + continue + accessible_services.append(service) + return accessible_services + def write_error(self, status_code, **kwargs): """render custom error pages""" exc_info = kwargs.get('exc_info') diff --git a/share/jupyterhub/templates/page.html b/share/jupyterhub/templates/page.html index cd50ee11..2ffac9ec 100644 --- a/share/jupyterhub/templates/page.html +++ b/share/jupyterhub/templates/page.html @@ -118,6 +118,16 @@ {% if user.admin %}
  • Admin
  • {% endif %} + {% if services %} + + {% endif %} {% endblock %} {% endif %} From e0c4f9fc23f0def9f30e1d0dbfbe41ad1ba59e16 Mon Sep 17 00:00:00 2001 From: "R. C. Thomas" Date: Thu, 17 Oct 2019 18:23:34 -0700 Subject: [PATCH 2/3] No services accessible if user is None Co-Authored-By: Min RK --- jupyterhub/handlers/base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jupyterhub/handlers/base.py b/jupyterhub/handlers/base.py index 054e4a82..bfbef9d4 100644 --- a/jupyterhub/handlers/base.py +++ b/jupyterhub/handlers/base.py @@ -1114,7 +1114,9 @@ class BaseHandler(RequestHandler): return ns def get_accessible_services(self, user): - accessible_services = list() + accessible_services = [] + if user is None: + return accessible_services for service in self.services.values(): if not service.url: continue From bc425a78bb8b86160472080f01c922aa6a48e17c Mon Sep 17 00:00:00 2001 From: "R. C. Thomas" Date: Thu, 17 Oct 2019 18:27:47 -0700 Subject: [PATCH 3/3] Keep admin-enabled services in the list --- jupyterhub/handlers/base.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/jupyterhub/handlers/base.py b/jupyterhub/handlers/base.py index bfbef9d4..3d61e5e6 100644 --- a/jupyterhub/handlers/base.py +++ b/jupyterhub/handlers/base.py @@ -1120,8 +1120,6 @@ class BaseHandler(RequestHandler): for service in self.services.values(): if not service.url: continue - if service.admin and not user.admin: - continue accessible_services.append(service) return accessible_services