summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2021-05-20 18:21:08 +0100
committerAndrew Morgan <andrew@amorgan.xyz>2021-05-20 18:39:24 +0100
commit0c976cb026100f89bfbba2bf7e6a8e24225d5769 (patch)
treef28da38ed16f35cb32821d91ea0e114762f39870
parentModify callers to the appservice public list storage function (diff)
downloadsynapse-0c976cb026100f89bfbba2bf7e6a8e24225d5769.tar.xz
Add an Admin API that removes a room from both public and AS room lists
-rw-r--r--docs/admin_api/rooms.md15
-rw-r--r--synapse/rest/admin/__init__.py2
-rw-r--r--synapse/rest/admin/rooms.py44
3 files changed, 61 insertions, 0 deletions
diff --git a/docs/admin_api/rooms.md b/docs/admin_api/rooms.md
index bc737b30f5..3f4203c437 100644
--- a/docs/admin_api/rooms.md
+++ b/docs/admin_api/rooms.md
@@ -529,6 +529,21 @@ You will have to manually handle, if you so choose, the following:
 * Removal of the Content Violation room if desired.
 
 
+# Delist Room From Public Directory API
+
+Allows delisting a room from both the public room directory and any application service-specific
+room lists. The room will still exist, but not be publicly visible. Note that this **does not**
+prevent room owners or application services from adding the room to public room lists again
+afterwards.
+
+```
+    DELETE /_synapse/admin/v1/rooms/directory/<room_id_or_alias>
+```
+
+The room will be removed from both the public directory and any application service
+directories. The response body for a successful request is empty.
+
+
 # Make Room Admin API
 
 Grants another user the highest power available to a local user who is in the room.
diff --git a/synapse/rest/admin/__init__.py b/synapse/rest/admin/__init__.py
index 8457db1e22..5397ceffff 100644
--- a/synapse/rest/admin/__init__.py
+++ b/synapse/rest/admin/__init__.py
@@ -38,6 +38,7 @@ from synapse.rest.admin.media import ListMediaInRoom, register_servlets_for_medi
 from synapse.rest.admin.purge_room_servlet import PurgeRoomServlet
 from synapse.rest.admin.rooms import (
     DeleteRoomRestServlet,
+    DelistRoomFromDirectoryRestServlet,
     ForwardExtremitiesRestServlet,
     JoinRoomAliasServlet,
     ListRoomRestServlet,
@@ -214,6 +215,7 @@ def register_servlets(hs, http_server):
     Register all the admin servlets.
     """
     register_servlets_for_client_rest_resource(hs, http_server)
+    DelistRoomFromDirectoryRestServlet(hs).register(http_server)
     ListRoomRestServlet(hs).register(http_server)
     RoomStateRestServlet(hs).register(http_server)
     RoomRestServlet(hs).register(http_server)
diff --git a/synapse/rest/admin/rooms.py b/synapse/rest/admin/rooms.py
index cfe1bebb91..84b6537ffa 100644
--- a/synapse/rest/admin/rooms.py
+++ b/synapse/rest/admin/rooms.py
@@ -192,6 +192,50 @@ class DeleteRoomRestServlet(RestServlet):
         return (200, ret)
 
 
+class DelistRoomFromDirectoryRestServlet(ResolveRoomIdMixin, RestServlet):
+    """Modifies both the the public room and application service directory listings
+    for a room.
+    """
+
+    PATTERNS = admin_patterns("/rooms/directory/(?P<room_identifier>[^/]*)$")
+
+    def __init__(self, hs: "HomeServer"):
+        super().__init__(hs)
+        self.hs = hs
+        self.auth = hs.get_auth()
+        self.directory_handler = hs.get_directory_handler()
+
+    async def on_DELETE(
+        self, request: SynapseRequest, room_identifier: str
+    ) -> Tuple[int, JsonDict]:
+        """Removes a room from both the public and appservice room directories by its ID
+
+        Args:
+            request: The request.
+            room_identifier: The ID of the room to remove, or an alias leading to it.
+
+        Returns:
+            A tuple of status code, response JSON dict.
+        """
+        requester = await self.auth.get_user_by_req(request)
+        await assert_user_is_admin(self.auth, requester.user)
+
+        # Get the ID of the room if an alias was provided
+        room_id, _ = await self.resolve_room_id(room_identifier)
+
+        # Remove the room from the public room directory
+        await self.directory_handler.edit_published_room_list(
+            requester, room_id, "private"
+        )
+
+        # Remove the room from all application-service public room directories
+        await self.directory_handler.remove_room_from_published_appservice_room_list(
+            room_id
+        )
+
+        return 200, {}
+
+
 class ListRoomRestServlet(RestServlet):
     """
     List all rooms that are known to the homeserver. Results are returned