Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add jupyter extensions to userprofile handler #641

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion cylc/uiserver/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import json
import getpass
import os
import re
from typing import TYPE_CHECKING, Callable, Dict

from graphene_tornado.tornado_graphql_handler import TornadoGraphQLHandler
Expand All @@ -44,6 +45,7 @@


ME = getpass.getuser()
RE_SLASH = re.compile(r'\/+')


def authorised(fun: Callable) -> Callable:
Expand Down Expand Up @@ -258,7 +260,6 @@ def set_default_headers(self) -> None:
self.set_header("Content-Type", 'application/json')

@web.authenticated
# @authorised TODO: I can't think why we would want to authorise this
def get(self):
user_info = {
**self.current_user.__dict__,
Expand All @@ -281,6 +282,19 @@ def get(self):
user_info['mode'] = 'single user'
else:
user_info['mode'] = 'multi user'

user_info['extensions'] = {
app.name: RE_SLASH.sub(
'/', f'{self.serverapp.base_url}/{app.default_url}'
)
for extension_apps
in self.serverapp.extension_manager.extension_apps.values()
# filter out extensions that do not provide a default_url OR
# set it to the root endpoint.
for app in extension_apps
if getattr(app, 'default_url', '/') != '/'
}

self.write(json.dumps(user_info))


Expand Down
17 changes: 17 additions & 0 deletions cylc/uiserver/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from functools import partial
from getpass import getuser
import json
from unittest import mock
from unittest.mock import MagicMock
import pytest
Expand Down Expand Up @@ -120,3 +121,19 @@ def test_assert_callback_handler_gets_called(self):
self.io_loop.run_sync(handler.open,
get_async_test_timeout())
handler.subscription_server.handle.assert_called_once()


@pytest.mark.integration
async def test_userprofile(
jp_fetch, cylc_uis, jp_serverapp,
):
"""Test the userprofile endpoint."""
# patch the default_url back to how it is set in cylc.uiserver.app
cylc_uis.default_url = '/cylc'

response = await jp_fetch('cylc', 'userprofile')
user_profile = json.loads(response.body.decode())
assert user_profile['username'] == getuser()
assert user_profile['owner'] == getuser()
assert 'read' in user_profile['permissions']
assert 'cylc' in user_profile['extensions']