File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 1818import json
1919import getpass
2020import os
21+ import re
2122from typing import TYPE_CHECKING , Callable , Dict
2223
2324from graphene_tornado .tornado_graphql_handler import TornadoGraphQLHandler
4445
4546
4647ME = getpass .getuser ()
48+ RE_SLASH = x = re .compile (r'\/+' )
4749
4850
4951def authorised (fun : Callable ) -> Callable :
@@ -258,7 +260,6 @@ def set_default_headers(self) -> None:
258260 self .set_header ("Content-Type" , 'application/json' )
259261
260262 @web .authenticated
261- # @authorised TODO: I can't think why we would want to authorise this
262263 def get (self ):
263264 user_info = {
264265 ** self .current_user .__dict__ ,
@@ -281,6 +282,19 @@ def get(self):
281282 user_info ['mode' ] = 'single user'
282283 else :
283284 user_info ['mode' ] = 'multi user'
285+
286+ user_info ['extensions' ] = {
287+ app .name : RE_SLASH .sub (
288+ '/' , f'{ self .serverapp .base_url } /{ app .default_url } '
289+ )
290+ for extension_apps
291+ in self .serverapp .extension_manager .extension_apps .values ()
292+ # filter out extensions that do not provide a default_url OR
293+ # set it to the root endpoint.
294+ for app in extension_apps
295+ if getattr (app , 'default_url' , '/' ) != '/'
296+ }
297+
284298 self .write (json .dumps (user_info ))
285299
286300
Original file line number Diff line number Diff line change 1515
1616from functools import partial
1717from getpass import getuser
18+ import json
1819from unittest import mock
1920from unittest .mock import MagicMock
2021import 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' ]
You can’t perform that action at this time.
0 commit comments