# HG changeset patch # User Goffi # Date 1622822249 -7200 # Node ID 7472d5a88006c760e82a05237ca9d943857f0feb # Parent 0f3038f3a9544d1281055e16e809ddf580b2b2f5 browser(bridge): allow some bridge methods for session profile: This let the cache to be filled to retrieve identities, and avoid an error message. diff -r 0f3038f3a954 -r 7472d5a88006 libervia/pages/_bridge/page_meta.py --- a/libervia/pages/_bridge/page_meta.py Fri Jun 04 14:45:49 2021 +0200 +++ b/libervia/pages/_bridge/page_meta.py Fri Jun 04 17:57:29 2021 +0200 @@ -1,16 +1,10 @@ #!/usr/bin/env python3 -import tempfile -import os -import os.path import json -from twisted.internet import defer -from twisted.web import static from sat.core.i18n import _ from sat.core.log import getLogger from sat_frontends.bridge.bridge_frontend import BridgeException from libervia.server.constants import Const as C -from libervia.server.utils import ProgressHandler log = getLogger(__name__) @@ -19,6 +13,9 @@ name = "bridge" on_data_post = "continue" +# bridge method allowed when no profile is connected +NO_SESSION_ALLOWED = ("getContacts", "identitiesBaseGet", "identitiesGet") + def parse_url(self, request): self.getPathArgs(request, ["method_name"], min_args=1) @@ -30,11 +27,15 @@ return self.pageError(request, C.HTTP_BAD_REQUEST) data = self.getRData(request) profile = self.getProfile(request) - if profile is None: - log.warning("_bridge endpoint accessed without authorisation") - return self.pageError(request, C.HTTP_UNAUTHORIZED) self.checkCSRF(request) method_name = data["method_name"] + if profile is None: + if method_name in NO_SESSION_ALLOWED: + # this method is allowed, we use the service profile + profile = C.SERVICE_PROFILE + else: + log.warning("_bridge endpoint accessed without authorisation") + return self.pageError(request, C.HTTP_UNAUTHORIZED) method_data = json.load(request.content) try: bridge_method = getattr(self.host.restricted_bridge, method_name) diff -r 0f3038f3a954 -r 7472d5a88006 libervia/pages/_browser/cache.py --- a/libervia/pages/_browser/cache.py Fri Jun 04 14:45:49 2021 +0200 +++ b/libervia/pages/_browser/cache.py Fri Jun 04 17:57:29 2021 +0200 @@ -100,7 +100,7 @@ callback() def fill_identities(self, entities, callback=None): - """Check that identities for identites exist, request them otherwise""" + """Check that identities for entities exist, request them otherwise""" to_get = {e for e in entities if e not in self._cache['identities']} if to_get: bridge.identitiesGet(