Skip to content

Commit 66cc74f

Browse files
add jupyter extensions to userprofile handler
1 parent def8d01 commit 66cc74f

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

cylc/uiserver/handlers.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ def set_default_headers(self) -> None:
258258
self.set_header("Content-Type", 'application/json')
259259

260260
@web.authenticated
261-
# @authorised TODO: I can't think why we would want to authorise this
262261
def get(self):
263262
user_info = {
264263
**self.current_user.__dict__,
@@ -281,6 +280,13 @@ def get(self):
281280
user_info['mode'] = 'single user'
282281
else:
283282
user_info['mode'] = 'multi user'
283+
284+
user_info['extensions'] = {
285+
y.name: y.default_url
286+
for x in self.serverapp.extension_manager.extension_apps.values()
287+
for y in x if getattr(y, 'default_url', '/') != '/'
288+
}
289+
284290
self.write(json.dumps(user_info))
285291

286292

cylc/uiserver/tests/test_handlers.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from functools import partial
1717
from getpass import getuser
18+
import json
1819
from unittest import mock
1920
from unittest.mock import MagicMock
2021
import pytest
@@ -120,3 +121,19 @@ def test_assert_callback_handler_gets_called(self):
120121
self.io_loop.run_sync(handler.open,
121122
get_async_test_timeout())
122123
handler.subscription_server.handle.assert_called_once()
124+
125+
126+
@pytest.mark.integration
127+
async def test_userprofile(
128+
jp_fetch, cylc_uis, jp_serverapp,
129+
):
130+
"""Test the userprofile endpoint."""
131+
# patch the default_url back to how it is set in cylc.uiserver.app
132+
cylc_uis.default_url = '/cylc'
133+
134+
response = await jp_fetch('cylc', 'userprofile')
135+
user_profile = json.loads(response.body.decode())
136+
assert user_profile['username'] == getuser()
137+
assert user_profile['owner'] == getuser()
138+
assert 'read' in user_profile['permissions']
139+
assert 'cylc' in user_profile['extensions']

0 commit comments

Comments
 (0)