Skip to content

Commit

Permalink
Implement allowed_room_ids for room summaries
Browse files Browse the repository at this point in the history
  • Loading branch information
deepbluev7 committed Jan 11, 2025
1 parent 204b663 commit 37f4253
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions synapse/handlers/room_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

This comment has been minimized.

Copy link
@richvdh

richvdh Jan 14, 2025

surely it is not correct that the following logic becomes conditional on self._msc3266_enabled ?

# 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)
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 37f4253

Please sign in to comment.