summary refs log tree commit diff
path: root/synapse/rest
diff options
context:
space:
mode:
authorDaniel Wagner-Hall <daniel@matrix.org>2016-02-12 16:17:24 +0000
committerDaniel Wagner-Hall <daniel@matrix.org>2016-02-12 16:17:24 +0000
commit4de08a4672c62eebda2ad3ee89643c2c32242cbf (patch)
tree1fc9e3c4ba992e6c35efb68dc9a62a7fa021295a /synapse/rest
parentMerge pull request #575 from matrix-org/daniel/roomcleanup (diff)
downloadsynapse-4de08a4672c62eebda2ad3ee89643c2c32242cbf.tar.xz
Revert "Merge two of the room join codepaths"
This reverts commit cf81375b94c4763766440471e632fc4b103450ab.

It subtly violates a guest joining auth check
Diffstat (limited to 'synapse/rest')
-rw-r--r--synapse/rest/client/v1/room.py68
1 files changed, 55 insertions, 13 deletions
diff --git a/synapse/rest/client/v1/room.py b/synapse/rest/client/v1/room.py
index 1dd33b0a56..81bfe377bd 100644
--- a/synapse/rest/client/v1/room.py
+++ b/synapse/rest/client/v1/room.py
@@ -216,7 +216,11 @@ class RoomSendEventRestServlet(ClientV1RestServlet):
 
 # TODO: Needs unit testing for room ID + alias joins
 class JoinRoomAliasServlet(ClientV1RestServlet):
-    PATTERNS = client_path_patterns("/join/(?P<room_identifier>[^/]*)$")
+
+    def register(self, http_server):
+        # /join/$room_identifier[/$txn_id]
+        PATTERNS = ("/join/(?P<room_identifier>[^/]*)")
+        register_txn_path(self, PATTERNS, http_server)
 
     @defer.inlineCallbacks
     def on_POST(self, request, room_identifier, txn_id=None):
@@ -225,22 +229,60 @@ class JoinRoomAliasServlet(ClientV1RestServlet):
             allow_guest=True,
         )
 
-        handler = self.handlers.room_member_handler
+        # the identifier could be a room alias or a room id. Try one then the
+        # other if it fails to parse, without swallowing other valid
+        # SynapseErrors.
 
-        room_id = None
-        hosts = []
-        if RoomAlias.is_valid(room_identifier):
-            room_alias = RoomAlias.from_string(room_identifier)
-            room_id, hosts = yield handler.lookup_room_alias(room_alias)
-        else:
-            room_id = RoomID.from_string(room_identifier).to_string()
+        identifier = None
+        is_room_alias = False
+        try:
+            identifier = RoomAlias.from_string(room_identifier)
+            is_room_alias = True
+        except SynapseError:
+            identifier = RoomID.from_string(room_identifier)
 
         # TODO: Support for specifying the home server to join with?
 
-        yield handler.do_join(
-            requester, room_id, hosts=hosts
-        )
-        defer.returnValue((200, {"room_id": room_id}))
+        if is_room_alias:
+            handler = self.handlers.room_member_handler
+            ret_dict = yield handler.join_room_alias(
+                requester.user,
+                identifier,
+            )
+            defer.returnValue((200, ret_dict))
+        else:  # room id
+            msg_handler = self.handlers.message_handler
+            content = {"membership": Membership.JOIN}
+            if requester.is_guest:
+                content["kind"] = "guest"
+            yield msg_handler.create_and_send_event(
+                {
+                    "type": EventTypes.Member,
+                    "content": content,
+                    "room_id": identifier.to_string(),
+                    "sender": requester.user.to_string(),
+                    "state_key": requester.user.to_string(),
+                },
+                token_id=requester.access_token_id,
+                txn_id=txn_id,
+                is_guest=requester.is_guest,
+            )
+
+            defer.returnValue((200, {"room_id": identifier.to_string()}))
+
+    @defer.inlineCallbacks
+    def on_PUT(self, request, room_identifier, txn_id):
+        try:
+            defer.returnValue(
+                self.txns.get_client_transaction(request, txn_id)
+            )
+        except KeyError:
+            pass
+
+        response = yield self.on_POST(request, room_identifier, txn_id)
+
+        self.txns.store_client_transaction(request, txn_id, response)
+        defer.returnValue(response)
 
 
 # TODO: Needs unit testing