@@ -146,12 +146,24 @@ async def get_space_summary(
146146 rooms = [] # type: List[JsonDict]
147147 events = []
148148 for room in fed_rooms :
149- # Pull whether it is world readable from the returned information
150- # since we may not have the state of this room.
151- include_room = room .get ("world_readable" ) is True
152149 fed_room_id = room .get ("room_id" )
150+ if not fed_room_id :
151+ continue
152+
153+ # Check whether the room is world readable from the response.
154+ include_room = room .get ("world_readable" ) is True
155+
156+ # If the room is not world-readable, get the allowed spaces from
157+ # the response.
158+ allowed_spaces = room .get ("allowed_spaces" )
159+ if not include_room and allowed_spaces :
160+ include_room = await self ._event_auth_handler .user_in_rooms (
161+ allowed_spaces , requester
162+ )
153163
154- if not include_room and fed_room_id :
164+ # Finally, check ourselves if we can access the room (this will
165+ # fail if we don't have any state for this room).
166+ if not include_room :
155167 include_room = await self ._is_room_accessible (
156168 fed_room_id , requester , None
157169 )
@@ -199,6 +211,11 @@ async def get_space_summary(
199211 )
200212 processed_events .add (ev_key )
201213
214+ # Before returning to the client, remove the allowed_spaces key for any
215+ # rooms.
216+ for room in rooms_result :
217+ room .pop ("allowed_spaces" , None )
218+
202219 return {"rooms" : rooms_result , "events" : events_result }
203220
204221 async def federation_space_summary (
@@ -486,6 +503,14 @@ async def _build_room_entry(self, room_id: str) -> JsonDict:
486503 if not room_type :
487504 room_type = create_event .content .get (EventContentFields .MSC1772_ROOM_TYPE )
488505
506+ room_version = await self ._store .get_room_version (room_id )
507+ (
508+ allow_via_spaces ,
509+ allowed_spaces ,
510+ ) = await self ._event_auth_handler .get_allowed_spaces (
511+ current_state_ids , room_version
512+ )
513+
489514 entry = {
490515 "room_id" : stats ["room_id" ],
491516 "name" : stats ["name" ],
@@ -499,6 +524,7 @@ async def _build_room_entry(self, room_id: str) -> JsonDict:
499524 "guest_can_join" : stats ["guest_access" ] == "can_join" ,
500525 "creation_ts" : create_event .origin_server_ts ,
501526 "room_type" : room_type ,
527+ "allowed_spaces" : allowed_spaces if allow_via_spaces else None ,
502528 }
503529
504530 # Filter out Nones – rather omit the field altogether
0 commit comments