Skip to content

Commit

Permalink
add jupyter extensions to userprofile handler
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-sanders committed Nov 1, 2024
1 parent def8d01 commit 66cc74f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cylc/uiserver/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,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 +280,13 @@ def get(self):
user_info['mode'] = 'single user'
else:
user_info['mode'] = 'multi user'

user_info['extensions'] = {
y.name: y.default_url
for x in self.serverapp.extension_manager.extension_apps.values()
for y in x if getattr(y, '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']

0 comments on commit 66cc74f

Please sign in to comment.