summary refs log tree commit diff
diff options
context:
space:
mode:
authorSean Quah <seanq@element.io>2021-11-18 15:40:29 +0000
committerSean Quah <seanq@element.io>2021-11-18 15:42:56 +0000
commit8627a456e314d4777d8dcbeb7da1fb3624ebfdf2 (patch)
treea44c32e932897b9a19bf68a069e5cf2c3411d0d0
parentConvert strings in `synapse.api.constants` to enums or `Final` (diff)
downloadsynapse-8627a456e314d4777d8dcbeb7da1fb3624ebfdf2.tar.xz
Refer to "spaces" instead of "rooms"
-rw-r--r--synapse/handlers/space_hierarchy.py (renamed from synapse/handlers/room_hierarchy.py)23
-rw-r--r--synapse/rest/admin/__init__.py4
-rw-r--r--synapse/rest/admin/space.py (renamed from synapse/rest/admin/room_hierarchy.py)6
-rw-r--r--synapse/server.py6
-rw-r--r--tests/handlers/test_space_hierarchy.py (renamed from tests/handlers/test_room_hierarchy.py)14
-rw-r--r--tests/rest/admin/test_space.py (renamed from tests/rest/admin/test_room_hierarchy.py)2
6 files changed, 29 insertions, 26 deletions
diff --git a/synapse/handlers/room_hierarchy.py b/synapse/handlers/space_hierarchy.py
index 54cdc130bd..619059b55e 100644
--- a/synapse/handlers/room_hierarchy.py
+++ b/synapse/handlers/space_hierarchy.py
@@ -37,7 +37,7 @@ if TYPE_CHECKING:
 logger = logging.getLogger(__name__)
 
 
-class RoomHierarchyHandler:
+class SpaceHierarchyHandler:
     """Provides methods for walking over space hierarchies.
 
     Also see `RoomSummaryHandler`, which has similar functionality.
@@ -49,7 +49,7 @@ class RoomHierarchyHandler:
 
         self._server_name = hs.hostname
 
-    async def get_room_descendants(
+    async def get_space_descendants(
         self, space_id: str, via: Optional[Iterable[str]] = None
     ) -> Tuple[Sequence[Tuple[str, Iterable[str]]], Sequence[str]]:
         """Gets the children of a space, recursively.
@@ -75,6 +75,7 @@ class RoomHierarchyHandler:
         todo: List[Tuple[str, Iterable[str], Mapping[str, Optional[JsonDict]]]] = [
             (space_id, via, {})
         ]
+        # [(room ID, via)]
         descendants: List[Tuple[str, Iterable[str]]] = []
 
         seen = {space_id}
@@ -89,7 +90,9 @@ class RoomHierarchyHandler:
                     is_in_room,
                     children,
                     federation_room_chunks,
-                ) = await self._get_room_children(space_id, via, federation_room_chunks)
+                ) = await self._get_space_children(
+                    space_id, via, federation_room_chunks
+                )
             except SynapseError:
                 # Could not list children over federation
                 inaccessible_room_ids.append(space_id)
@@ -103,7 +106,7 @@ class RoomHierarchyHandler:
 
                 # Queue up the child for processing.
                 # The child may not actually be a space, but that's checked by
-                # `_get_room_children`.
+                # `_get_space_children`.
                 todo.append((child_room_id, child_via, federation_room_chunks))
 
             # Children were retrieved over federation, which is not guaranteed to be
@@ -113,7 +116,7 @@ class RoomHierarchyHandler:
 
         return descendants, inaccessible_room_ids
 
-    async def _get_room_children(
+    async def _get_space_children(
         self,
         space_id: str,
         via: Optional[Iterable[str]] = None,
@@ -127,7 +130,7 @@ class RoomHierarchyHandler:
             space_id: The room ID of the space.
             via: A list of servers which may know about the space.
             federation_room_chunks: A cache of room chunks previously returned by
-               `_get_room_children` that may be used to skip federation requests for
+               `_get_space_children` that may be used to skip federation requests for
                inaccessible or non-space rooms.
 
         Returns:
@@ -156,7 +159,7 @@ class RoomHierarchyHandler:
 
         is_in_room = await self._store.is_host_joined(space_id, self._server_name)
         if is_in_room:
-            children = await self._get_room_children_local(space_id)
+            children = await self._get_space_children_local(space_id)
             return True, children, {}
         else:
             # Check the room chunks previously returned over federation to see if we
@@ -175,10 +178,10 @@ class RoomHierarchyHandler:
                     # `space_id` is not a space according to federation.
                     return False, [], {}
 
-            children, room_chunks = await self._get_room_children_remote(space_id, via)
+            children, room_chunks = await self._get_space_children_remote(space_id, via)
             return False, children, room_chunks
 
-    async def _get_room_children_local(
+    async def _get_space_children_local(
         self, space_id: str
     ) -> Sequence[Tuple[str, Iterable[str]]]:
         """Gets the direct children of a space that the local homeserver is in.
@@ -225,7 +228,7 @@ class RoomHierarchyHandler:
         child_events.sort(key=child_events_comparison_key)
         return [(event.state_key, event.content["via"]) for event in child_events]
 
-    async def _get_room_children_remote(
+    async def _get_space_children_remote(
         self, space_id: str, via: Iterable[str]
     ) -> Tuple[Sequence[Tuple[str, Iterable[str]]], Mapping[str, Optional[JsonDict]]]:
         """Gets the direct children of a space over federation.
diff --git a/synapse/rest/admin/__init__.py b/synapse/rest/admin/__init__.py
index b7bc36c17a..36cfd1e4e2 100644
--- a/synapse/rest/admin/__init__.py
+++ b/synapse/rest/admin/__init__.py
@@ -45,7 +45,6 @@ from synapse.rest.admin.registration_tokens import (
     NewRegistrationTokenRestServlet,
     RegistrationTokenRestServlet,
 )
-from synapse.rest.admin.room_hierarchy import RemoveHierarchyMemberRestServlet
 from synapse.rest.admin.rooms import (
     DeleteRoomStatusByDeleteIdRestServlet,
     DeleteRoomStatusByRoomIdRestServlet,
@@ -60,6 +59,7 @@ from synapse.rest.admin.rooms import (
     RoomStateRestServlet,
 )
 from synapse.rest.admin.server_notice_servlet import SendServerNoticeServlet
+from synapse.rest.admin.space import RemoveSpaceMemberRestServlet
 from synapse.rest.admin.statistics import UserMediaStatisticsRestServlet
 from synapse.rest.admin.username_available import UsernameAvailableRestServlet
 from synapse.rest.admin.users import (
@@ -254,7 +254,7 @@ def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None:
     ListRegistrationTokensRestServlet(hs).register(http_server)
     NewRegistrationTokenRestServlet(hs).register(http_server)
     RegistrationTokenRestServlet(hs).register(http_server)
-    RemoveHierarchyMemberRestServlet(hs).register(http_server)
+    RemoveSpaceMemberRestServlet(hs).register(http_server)
 
     # Some servlets only get registered for the main process.
     if hs.config.worker.worker_app is None:
diff --git a/synapse/rest/admin/room_hierarchy.py b/synapse/rest/admin/space.py
index 16bd902b5a..952240d01f 100644
--- a/synapse/rest/admin/room_hierarchy.py
+++ b/synapse/rest/admin/space.py
@@ -28,7 +28,7 @@ if TYPE_CHECKING:
 logger = logging.getLogger(__name__)
 
 
-class RemoveHierarchyMemberRestServlet(ResolveRoomIdMixin, RestServlet):
+class RemoveSpaceMemberRestServlet(ResolveRoomIdMixin, RestServlet):
     """
     Puppets a local user to remove them from all rooms in a space.
     """
@@ -43,7 +43,7 @@ class RemoveHierarchyMemberRestServlet(ResolveRoomIdMixin, RestServlet):
         self._auth = hs.get_auth()
         self._store = hs.get_datastore()
         self._room_member_handler = hs.get_room_member_handler()
-        self._room_hierarchy_handler = hs.get_room_hierarchy_handler()
+        self._space_hierarchy_handler = hs.get_space_hierarchy_handler()
 
     async def on_DELETE(
         self, request: SynapseRequest, space_id: str, user_id: str
@@ -87,7 +87,7 @@ class RemoveHierarchyMemberRestServlet(ResolveRoomIdMixin, RestServlet):
         (
             descendants,
             inaccessible_room_ids,
-        ) = await self._room_hierarchy_handler.get_room_descendants(space_id)
+        ) = await self._space_hierarchy_handler.get_space_descendants(space_id)
         space_room_ids = {space_id}
         space_room_ids.update(room_id for room_id, _ in descendants)
 
diff --git a/synapse/server.py b/synapse/server.py
index cd8f260c70..9b7dba013c 100644
--- a/synapse/server.py
+++ b/synapse/server.py
@@ -99,7 +99,6 @@ from synapse.handlers.room import (
     RoomShutdownHandler,
 )
 from synapse.handlers.room_batch import RoomBatchHandler
-from synapse.handlers.room_hierarchy import RoomHierarchyHandler
 from synapse.handlers.room_list import RoomListHandler
 from synapse.handlers.room_member import RoomMemberHandler, RoomMemberMasterHandler
 from synapse.handlers.room_member_worker import RoomMemberWorkerHandler
@@ -107,6 +106,7 @@ from synapse.handlers.room_summary import RoomSummaryHandler
 from synapse.handlers.search import SearchHandler
 from synapse.handlers.send_email import SendEmailHandler
 from synapse.handlers.set_password import SetPasswordHandler
+from synapse.handlers.space_hierarchy import SpaceHierarchyHandler
 from synapse.handlers.sso import SsoHandler
 from synapse.handlers.stats import StatsHandler
 from synapse.handlers.sync import SyncHandler
@@ -792,8 +792,8 @@ class HomeServer(metaclass=abc.ABCMeta):
         return AccountDataHandler(self)
 
     @cache_in_self
-    def get_room_hierarchy_handler(self) -> RoomHierarchyHandler:
-        return RoomHierarchyHandler(self)
+    def get_space_hierarchy_handler(self) -> SpaceHierarchyHandler:
+        return SpaceHierarchyHandler(self)
 
     @cache_in_self
     def get_room_summary_handler(self) -> RoomSummaryHandler:
diff --git a/tests/handlers/test_room_hierarchy.py b/tests/handlers/test_space_hierarchy.py
index 31adcd60ff..8e46b2c93e 100644
--- a/tests/handlers/test_room_hierarchy.py
+++ b/tests/handlers/test_space_hierarchy.py
@@ -23,7 +23,7 @@ from synapse.types import JsonDict
 from tests import unittest
 
 
-class RoomDescendantsTestCase(unittest.HomeserverTestCase):
+class SpaceDescendantsTestCase(unittest.HomeserverTestCase):
     """Tests iteration over the descendants of a space."""
 
     servlets = [
@@ -34,7 +34,7 @@ class RoomDescendantsTestCase(unittest.HomeserverTestCase):
 
     def prepare(self, reactor, clock, hs: HomeServer):
         self.hs = hs
-        self.handler = self.hs.get_room_hierarchy_handler()
+        self.handler = self.hs.get_space_hierarchy_handler()
 
         # Create a user.
         self.user = self.register_user("user", "pass")
@@ -87,7 +87,7 @@ class RoomDescendantsTestCase(unittest.HomeserverTestCase):
         space_id = self._create_space()
 
         descendants, inaccessible_room_ids = self.get_success(
-            self.handler.get_room_descendants(space_id)
+            self.handler.get_space_descendants(space_id)
         )
 
         self.assertEqual(descendants, [(space_id, [])])
@@ -98,7 +98,7 @@ class RoomDescendantsTestCase(unittest.HomeserverTestCase):
         space_id = f"!invalid:{self.hs.hostname}"
 
         descendants, inaccessible_room_ids = self.get_success(
-            self.handler.get_room_descendants(space_id)
+            self.handler.get_space_descendants(space_id)
         )
 
         self.assertEqual(descendants, [(space_id, [])])
@@ -111,7 +111,7 @@ class RoomDescendantsTestCase(unittest.HomeserverTestCase):
         self._add_child(space_id, room_id)
 
         descendants, inaccessible_room_ids = self.get_success(
-            self.handler.get_room_descendants(space_id)
+            self.handler.get_space_descendants(space_id)
         )
 
         self.assertEqual(descendants, [(space_id, []), (room_id, [self.hs.hostname])])
@@ -128,7 +128,7 @@ class RoomDescendantsTestCase(unittest.HomeserverTestCase):
         self._add_child(subspace_id, space_id)
 
         descendants, inaccessible_room_ids = self.get_success(
-            self.handler.get_room_descendants(space_id)
+            self.handler.get_space_descendants(space_id)
         )
 
         self.assertEqual(
@@ -158,7 +158,7 @@ class RoomDescendantsTestCase(unittest.HomeserverTestCase):
         self._add_child(subspace_id, room_id, order="3")
 
         descendants, inaccessible_room_ids = self.get_success(
-            self.handler.get_room_descendants(space_id)
+            self.handler.get_space_descendants(space_id)
         )
 
         self.assertEqual(
diff --git a/tests/rest/admin/test_room_hierarchy.py b/tests/rest/admin/test_space.py
index 3d2ac01370..59c6c3b284 100644
--- a/tests/rest/admin/test_room_hierarchy.py
+++ b/tests/rest/admin/test_space.py
@@ -32,7 +32,7 @@ from synapse.types import JsonDict
 from tests import unittest
 
 
-class RemoveHierarchyMemberTestCase(unittest.HomeserverTestCase):
+class RemoveSpaceMemberTestCase(unittest.HomeserverTestCase):
     """Tests removal of a user from a space."""
 
     servlets = [