comparison libervia/pages/_bridge/page_meta.py @ 1431:7472d5a88006

browser(bridge): allow some bridge methods for session profile: This let the cache to be filled to retrieve identities, and avoid an error message.
author Goffi <goffi@goffi.org>
date Fri, 04 Jun 2021 17:57:29 +0200
parents b1215347b5c3
children 106bae41f5c8
comparison
equal deleted inserted replaced
1430:0f3038f3a954 1431:7472d5a88006
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 2
3 import tempfile
4 import os
5 import os.path
6 import json 3 import json
7 from twisted.internet import defer
8 from twisted.web import static
9 from sat.core.i18n import _ 4 from sat.core.i18n import _
10 from sat.core.log import getLogger 5 from sat.core.log import getLogger
11 from sat_frontends.bridge.bridge_frontend import BridgeException 6 from sat_frontends.bridge.bridge_frontend import BridgeException
12 from libervia.server.constants import Const as C 7 from libervia.server.constants import Const as C
13 from libervia.server.utils import ProgressHandler
14 8
15 9
16 log = getLogger(__name__) 10 log = getLogger(__name__)
17 """access to restricted bridge""" 11 """access to restricted bridge"""
18 12
19 name = "bridge" 13 name = "bridge"
20 on_data_post = "continue" 14 on_data_post = "continue"
15
16 # bridge method allowed when no profile is connected
17 NO_SESSION_ALLOWED = ("getContacts", "identitiesBaseGet", "identitiesGet")
21 18
22 19
23 def parse_url(self, request): 20 def parse_url(self, request):
24 self.getPathArgs(request, ["method_name"], min_args=1) 21 self.getPathArgs(request, ["method_name"], min_args=1)
25 22
28 if request.method != b'POST': 25 if request.method != b'POST':
29 log.warning(f"Bad method used with _bridge endpoint: {request.method.decode()}") 26 log.warning(f"Bad method used with _bridge endpoint: {request.method.decode()}")
30 return self.pageError(request, C.HTTP_BAD_REQUEST) 27 return self.pageError(request, C.HTTP_BAD_REQUEST)
31 data = self.getRData(request) 28 data = self.getRData(request)
32 profile = self.getProfile(request) 29 profile = self.getProfile(request)
33 if profile is None:
34 log.warning("_bridge endpoint accessed without authorisation")
35 return self.pageError(request, C.HTTP_UNAUTHORIZED)
36 self.checkCSRF(request) 30 self.checkCSRF(request)
37 method_name = data["method_name"] 31 method_name = data["method_name"]
32 if profile is None:
33 if method_name in NO_SESSION_ALLOWED:
34 # this method is allowed, we use the service profile
35 profile = C.SERVICE_PROFILE
36 else:
37 log.warning("_bridge endpoint accessed without authorisation")
38 return self.pageError(request, C.HTTP_UNAUTHORIZED)
38 method_data = json.load(request.content) 39 method_data = json.load(request.content)
39 try: 40 try:
40 bridge_method = getattr(self.host.restricted_bridge, method_name) 41 bridge_method = getattr(self.host.restricted_bridge, method_name)
41 except AttributeError: 42 except AttributeError:
42 log.warning(_( 43 log.warning(_(