File tree 2 files changed +32
-1
lines changed
2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 18
18
import json
19
19
import getpass
20
20
import os
21
+ import re
21
22
from typing import TYPE_CHECKING , Callable , Dict
22
23
23
24
from graphene_tornado .tornado_graphql_handler import TornadoGraphQLHandler
44
45
45
46
46
47
ME = getpass .getuser ()
48
+ RE_SLASH = re .compile (r'\/+' )
47
49
48
50
49
51
def authorised (fun : Callable ) -> Callable :
@@ -258,7 +260,6 @@ def set_default_headers(self) -> None:
258
260
self .set_header ("Content-Type" , 'application/json' )
259
261
260
262
@web .authenticated
261
- # @authorised TODO: I can't think why we would want to authorise this
262
263
def get (self ):
263
264
user_info = {
264
265
** self .current_user .__dict__ ,
@@ -281,6 +282,19 @@ def get(self):
281
282
user_info ['mode' ] = 'single user'
282
283
else :
283
284
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
+
284
298
self .write (json .dumps (user_info ))
285
299
286
300
Original file line number Diff line number Diff line change 15
15
16
16
from functools import partial
17
17
from getpass import getuser
18
+ import json
18
19
from unittest import mock
19
20
from unittest .mock import MagicMock
20
21
import pytest
@@ -120,3 +121,19 @@ def test_assert_callback_handler_gets_called(self):
120
121
self .io_loop .run_sync (handler .open ,
121
122
get_async_test_timeout ())
122
123
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