summary refs log tree commit diff
path: root/synapse/rest/client/v1/directory.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-03-22 11:57:39 +0000
committerErik Johnston <erik@matrix.org>2016-03-22 11:57:39 +0000
commitd6ac7525380076cbae33b631d58725758f97e459 (patch)
tree722d4483ab0e70a3242f2d53a6c4f9ee9e728a34 /synapse/rest/client/v1/directory.py
parentMerge pull request #658 from matrix-org/markjh/cleanup (diff)
parentDoc string (diff)
downloadsynapse-d6ac7525380076cbae33b631d58725758f97e459.tar.xz
Merge pull request #657 from matrix-org/erikj/roomlist
Add published room list edit API
Diffstat (limited to 'synapse/rest/client/v1/directory.py')
-rw-r--r--synapse/rest/client/v1/directory.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/synapse/rest/client/v1/directory.py b/synapse/rest/client/v1/directory.py
index 59a23d6cb6..8ac09419dc 100644
--- a/synapse/rest/client/v1/directory.py
+++ b/synapse/rest/client/v1/directory.py
@@ -30,6 +30,7 @@ logger = logging.getLogger(__name__)
 
 def register_servlets(hs, http_server):
     ClientDirectoryServer(hs).register(http_server)
+    ClientDirectoryListServer(hs).register(http_server)
 
 
 class ClientDirectoryServer(ClientV1RestServlet):
@@ -137,3 +138,44 @@ class ClientDirectoryServer(ClientV1RestServlet):
         )
 
         defer.returnValue((200, {}))
+
+
+class ClientDirectoryListServer(ClientV1RestServlet):
+    PATTERNS = client_path_patterns("/directory/list/room/(?P<room_id>[^/]*)$")
+
+    def __init__(self, hs):
+        super(ClientDirectoryListServer, self).__init__(hs)
+        self.store = hs.get_datastore()
+
+    @defer.inlineCallbacks
+    def on_GET(self, request, room_id):
+        room = yield self.store.get_room(room_id)
+        if room is None:
+            raise SynapseError(400, "Unknown room")
+
+        defer.returnValue((200, {
+            "visibility": "public" if room["is_public"] else "private"
+        }))
+
+    @defer.inlineCallbacks
+    def on_PUT(self, request, room_id):
+        requester = yield self.auth.get_user_by_req(request)
+
+        content = parse_json_object_from_request(request)
+        visibility = content.get("visibility", "public")
+
+        yield self.handlers.directory_handler.edit_published_room_list(
+            requester, room_id, visibility,
+        )
+
+        defer.returnValue((200, {}))
+
+    @defer.inlineCallbacks
+    def on_DELETE(self, request, room_id):
+        requester = yield self.auth.get_user_by_req(request)
+
+        yield self.handlers.directory_handler.edit_published_room_list(
+            requester, room_id, "private",
+        )
+
+        defer.returnValue((200, {}))