From 37f4253bda4942adc6356e9ed73dc40582764c9b Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sat, 11 Jan 2025 01:20:59 +0100 Subject: [PATCH] Implement allowed_room_ids for room summaries --- synapse/handlers/room_summary.py | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/synapse/handlers/room_summary.py b/synapse/handlers/room_summary.py index 720459f1e787..5bec1235e620 100644 --- a/synapse/handlers/room_summary.py +++ b/synapse/handlers/room_summary.py @@ -308,7 +308,7 @@ async def _get_room_hierarchy( # inaccessible to the requesting user. if room_entry: # Add the room (including the stripped m.space.child events). - rooms_result.append(room_entry.as_json(for_client=True)) + rooms_result.append(room_entry.as_json()) # If this room is not at the max-depth, check if there are any # children to process. @@ -445,7 +445,7 @@ async def _summarize_local_room( if not await self._is_local_room_accessible(room_id, requester, origin): return None - room_entry = await self._build_room_entry(room_id, for_federation=bool(origin)) + room_entry = await self._build_room_entry(room_id) # If the room is not a space return just the room information. if room_entry.get("room_type") != RoomTypes.SPACE or not include_children: @@ -701,14 +701,12 @@ async def _is_remote_room_accessible( # pending invite, etc. return await self._is_local_room_accessible(room_id, requester) - async def _build_room_entry(self, room_id: str, for_federation: bool) -> JsonDict: + async def _build_room_entry(self, room_id: str) -> JsonDict: """ Generate en entry summarising a single room. Args: room_id: The room ID to summarize. - for_federation: True if this is a summary requested over federation - (which includes additional fields). Returns: The JSON dictionary for the room. @@ -739,9 +737,6 @@ async def _build_room_entry(self, room_id: str, for_federation: bool) -> JsonDic entry["im.nheko.summary.version"] = stats.version entry["im.nheko.summary.encryption"] = stats.encryption - # Federation requests need to provide additional information so the - # requested server is able to filter the response appropriately. - if for_federation: current_state_ids = ( await self._storage_controllers.state.get_current_state_ids(room_id) ) @@ -866,7 +861,6 @@ async def get_room_summary( raise NotFoundError("Room not found or is not accessible") room = dict(room_entry.room) - room.pop("allowed_room_ids", None) # If there was a requester, add their membership. # We keep the membership in the local membership table unless the @@ -909,25 +903,16 @@ class _RoomEntry: # This may not include all children. children_state_events: Sequence[JsonDict] = () - def as_json(self, for_client: bool = False) -> JsonDict: + def as_json(self) -> JsonDict: """ Returns a JSON dictionary suitable for the room hierarchy endpoint. It returns the room summary including the stripped m.space.child events as a sub-key. - Args: - for_client: If true, any server-server only fields are stripped from - the result. - """ result = dict(self.room) - # Before returning to the client, remove the allowed_room_ids key, if it - # exists. - if for_client: - result.pop("allowed_room_ids", False) - result["children_state"] = self.children_state_events return result