From 280068e28c22c3a24937c1ef079eeb3a67ba356c Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Fri, 22 Feb 2019 15:43:11 +0000 Subject: [PATCH] Don't restrict non-fed rooms over client APIs --- synapse/federation/transport/server.py | 3 ++- synapse/groups/groups_server.py | 4 ++-- synapse/handlers/room_list.py | 29 ++++++++++++++++---------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/synapse/federation/transport/server.py b/synapse/federation/transport/server.py index 7288d49074..6d4a26f595 100644 --- a/synapse/federation/transport/server.py +++ b/synapse/federation/transport/server.py @@ -697,7 +697,8 @@ class PublicRoomList(BaseFederationServlet): data = yield self.handler.get_local_public_room_list( limit, since_token, - network_tuple=network_tuple + network_tuple=network_tuple, + from_federation=True, ) defer.returnValue((200, data)) diff --git a/synapse/groups/groups_server.py b/synapse/groups/groups_server.py index 633c865ed8..691752a30c 100644 --- a/synapse/groups/groups_server.py +++ b/synapse/groups/groups_server.py @@ -113,7 +113,7 @@ class GroupsServerHandler(object): room_id = room_entry["room_id"] joined_users = yield self.store.get_users_in_room(room_id) entry = yield self.room_list_handler.generate_room_entry( - room_id, len(joined_users), + room_id, True, len(joined_users), with_alias=False, allow_private=True, ) entry = dict(entry) # so we don't change whats cached @@ -544,7 +544,7 @@ class GroupsServerHandler(object): joined_users = yield self.store.get_users_in_room(room_id) entry = yield self.room_list_handler.generate_room_entry( - room_id, len(joined_users), + room_id, True, len(joined_users), with_alias=False, allow_private=True, ) diff --git a/synapse/handlers/room_list.py b/synapse/handlers/room_list.py index 47aeeb1d88..bde9ec744f 100644 --- a/synapse/handlers/room_list.py +++ b/synapse/handlers/room_list.py @@ -51,7 +51,8 @@ class RoomListHandler(BaseHandler): def get_local_public_room_list(self, limit=None, since_token=None, search_filter=None, - network_tuple=EMPTY_THIRD_PARTY_ID,): + network_tuple=EMPTY_THIRD_PARTY_ID, + from_federation=False): """Generate a local public room list. There are multiple different lists: the main one plus one per third @@ -82,13 +83,15 @@ class RoomListHandler(BaseHandler): return self.response_cache.wrap( key, self._get_public_room_list, - limit, since_token, network_tuple=network_tuple, + limit, since_token, + network_tuple=network_tuple, from_federation=from_federation, ) @defer.inlineCallbacks def _get_public_room_list(self, limit=None, since_token=None, search_filter=None, - network_tuple=EMPTY_THIRD_PARTY_ID,): + network_tuple=EMPTY_THIRD_PARTY_ID, + from_federation=False,): if since_token and since_token != "END": since_token = RoomListNextBatch.from_token(since_token) else: @@ -208,7 +211,8 @@ class RoomListHandler(BaseHandler): yield concurrently_execute( lambda r: self._append_room_entry_to_chunk( r, rooms_to_num_joined[r], - chunk, limit, search_filter + chunk, limit, search_filter, + from_federation=from_federation, ), batch, 5, ) @@ -279,7 +283,7 @@ class RoomListHandler(BaseHandler): @defer.inlineCallbacks def _append_room_entry_to_chunk(self, room_id, num_joined_users, chunk, limit, - search_filter): + search_filter, from_federation=False): """Generate the entry for a room in the public room list and append it to the `chunk` if it matches the search filter """ @@ -287,16 +291,19 @@ class RoomListHandler(BaseHandler): # We've already got enough, so lets just drop it. return - result = yield self.generate_room_entry(room_id, num_joined_users, - allow_federated=self.config.allow_non_federated_in_public_rooms) + if from_federation: + result = yield self.generate_room_entry(room_id, + self.config.allow_non_federated_in_public_rooms, + num_joined_users) + else: + result = yield self.generate_room_entry(room_id, True, num_joined_users) if result and _matches_room_entry(result, search_filter): chunk.append(result) - @cachedInlineCallbacks(num_args=1, cache_context=True) - def generate_room_entry(self, room_id, num_joined_users, cache_context, - with_alias=True, allow_private=False, - allow_federated=True): + @cachedInlineCallbacks(num_args=2, cache_context=True) + def generate_room_entry(self, room_id, allow_federated, num_joined_users, + cache_context, with_alias=True, allow_private=False): """Returns the entry for a room """ result = {