diff --git a/synapse/appservice/api.py b/synapse/appservice/api.py index 8651134ce4..cf9ab28bec 100644 --- a/synapse/appservice/api.py +++ b/synapse/appservice/api.py @@ -268,6 +268,7 @@ class ApplicationServiceApi(SimpleHttpClient): user_id: str, from_user_id: Optional[UserID] = None, key: Optional[str] = None, + origin_server: Optional[str] = None, ) -> Optional[JsonDict]: if service.url is None: return None @@ -281,6 +282,8 @@ class ApplicationServiceApi(SimpleHttpClient): args["access_token"] = service.hs_token if from_user_id: args["from_user_id"] = from_user_id.to_string() + if origin_server: + args["origin_server"] = origin_server url = f"{service.url}{APP_SERVICE_PREFIX}/profile/{urllib.parse.quote(user_id)}" diff --git a/synapse/handlers/appservice.py b/synapse/handlers/appservice.py index a0b5738ca0..2259e82f54 100644 --- a/synapse/handlers/appservice.py +++ b/synapse/handlers/appservice.py @@ -737,7 +737,7 @@ class ApplicationServicesHandler: return False async def query_profile( - self, user_id: str, from_user_id: Optional[UserID] = None, key: Optional[str] = None + self, user_id: str, from_user_id: Optional[UserID] = None, key: Optional[str] = None, origin_server: Optional[str] = None ) -> Optional[JsonDict]: """Check if any application service knows this user_id exists. @@ -751,7 +751,7 @@ class ApplicationServicesHandler: for user_service in user_query_services: if user_service.supports_profile_lookup: profile = await self.appservice_api.query_profile( - user_service, user_id, from_user_id, key + user_service, user_id, from_user_id, key, origin_server ) if profile: accumulated_profile.update(profile) diff --git a/synapse/handlers/profile.py b/synapse/handlers/profile.py index eb03a875a1..3029918665 100644 --- a/synapse/handlers/profile.py +++ b/synapse/handlers/profile.py @@ -139,6 +139,8 @@ class ProfileHandler: raise e.to_synapse_error() # Check whether the appservice has any information about the user. + + logger.info(f"query_profile {user_id} {from_user_id}") as_profile = await self._as.query_profile(user_id, from_user_id) ret.update(as_profile) @@ -464,6 +466,7 @@ class ProfileHandler: The value for the profile field or None if the field does not exist. """ + logger.info(f"get_profile_field {field_name} {from_user_id}") # Check whether the appservice has any information about the user. as_profile = await self._as.query_profile( target_user.to_string(), from_user_id, field_name @@ -576,9 +579,12 @@ class ProfileHandler: raise SynapseError(400, "User is not hosted on this homeserver") just_field = args.get("field") + origin_server = args.get("origin") + + assert origin_server # Check whether the appservice has any information about the user. - as_profile = await self._as.query_profile(user.to_string(), key=just_field) + as_profile = await self._as.query_profile(user.to_string(), key=just_field, origin_server=origin_server) if just_field and just_field in as_profile: return as_profile[just_field] diff --git a/synapse/rest/client/profile.py b/synapse/rest/client/profile.py index db1aa64cbb..0e5d6af76e 100644 --- a/synapse/rest/client/profile.py +++ b/synapse/rest/client/profile.py @@ -113,11 +113,8 @@ class ProfileFieldRestServlet(RestServlet): async def on_GET( self, request: SynapseRequest, user_id: str, field_name: str ) -> Tuple[int, JsonDict]: - requester_user = None - - if self.hs.config.server.require_auth_for_profile_requests: - requester = await self.auth.get_user_by_req(request) - requester_user = requester.user + requester = await self.auth.get_user_by_req(request) + requester_user = requester.user if not UserID.is_valid(user_id): raise SynapseError( @@ -137,7 +134,7 @@ class ProfileFieldRestServlet(RestServlet): ) user = UserID.from_string(user_id) - await self.profile_handler.check_profile_query_allowed(user, requester_user) + await self.profile_handler.check_profile_query_allowed(user, requester_user if self.hs.config.server.require_auth_for_profile_requests else None) if field_name == ProfileFields.DISPLAYNAME: field_value: JsonValue = await self.profile_handler.get_displayname(