From eb0787d0cbfaa67e557c59ba76e2f0e64d7a1e5d Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 3 Sep 2024 08:43:36 +0100 Subject: [PATCH] Allow GET /devices/:device_id to run on worker --- synapse/rest/__init__.py | 1 - synapse/rest/client/devices.py | 19 +++++++++++++++---- synapse/rest/client/pusher.py | 6 ++++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/synapse/rest/__init__.py b/synapse/rest/__init__.py index 527069ba07..46a71d35be 100644 --- a/synapse/rest/__init__.py +++ b/synapse/rest/__init__.py @@ -172,7 +172,6 @@ class ClientRestResource(JsonResource): for servletfunc in SERVLET_GROUPS[servlet_group]: if not is_main_process and servletfunc in [ - pusher.register_servlets, logout.register_servlets, auth.register_servlets, tokenrefresh.register_servlets, diff --git a/synapse/rest/client/devices.py b/synapse/rest/client/devices.py index 8313d687b7..0116296252 100644 --- a/synapse/rest/client/devices.py +++ b/synapse/rest/client/devices.py @@ -144,13 +144,13 @@ class DeviceRestServlet(RestServlet): super().__init__() self.hs = hs self.auth = hs.get_auth() - handler = hs.get_device_handler() - assert isinstance(handler, DeviceHandler) - self.device_handler = handler + self.device_handler = hs.get_device_handler() self.auth_handler = hs.get_auth_handler() self._msc3852_enabled = hs.config.experimental.msc3852_enabled self._msc3861_oauth_delegation_enabled = hs.config.experimental.msc3861.enabled + self._is_main_process = hs.config.worker.worker_app is None + async def on_GET( self, request: SynapseRequest, device_id: str ) -> Tuple[int, JsonDict]: @@ -181,6 +181,11 @@ class DeviceRestServlet(RestServlet): async def on_DELETE( self, request: SynapseRequest, device_id: str ) -> Tuple[int, JsonDict]: + if not self._is_main_process: + raise UnrecognizedRequestError(code=404) + + assert isinstance(self.device_handler, DeviceHandler) + if self._msc3861_oauth_delegation_enabled: raise UnrecognizedRequestError(code=404) @@ -219,6 +224,11 @@ class DeviceRestServlet(RestServlet): async def on_PUT( self, request: SynapseRequest, device_id: str ) -> Tuple[int, JsonDict]: + if not self._is_main_process: + raise UnrecognizedRequestError(code=404) + + assert isinstance(self.device_handler, DeviceHandler) + requester = await self.auth.get_user_by_req(request, allow_guest=True) body = parse_and_validate_json_object_from_request(request, self.PutBody) @@ -570,10 +580,11 @@ def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None: and not hs.config.experimental.msc3861.enabled ): DeleteDevicesRestServlet(hs).register(http_server) + DevicesRestServlet(hs).register(http_server) + DeviceRestServlet(hs).register(http_server) if hs.config.worker.worker_app is None: - DeviceRestServlet(hs).register(http_server) if hs.config.experimental.msc2697_enabled: DehydratedDeviceServlet(hs).register(http_server) ClaimDehydratedDeviceServlet(hs).register(http_server) diff --git a/synapse/rest/client/pusher.py b/synapse/rest/client/pusher.py index a455f95a26..0fdf8add2f 100644 --- a/synapse/rest/client/pusher.py +++ b/synapse/rest/client/pusher.py @@ -177,5 +177,7 @@ class LegacyPushersRemoveRestServlet(UnsubscribeResource, RestServlet): def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None: PushersRestServlet(hs).register(http_server) - PushersSetRestServlet(hs).register(http_server) - LegacyPushersRemoveRestServlet(hs).register(http_server) + + if hs.config.worker.worker_app is None: + PushersSetRestServlet(hs).register(http_server) + LegacyPushersRemoveRestServlet(hs).register(http_server)