summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--synapse/handlers/room.py16
-rw-r--r--synapse/rest/client/v2_alpha/room_upgrade_rest_servlet.py21
2 files changed, 25 insertions, 12 deletions
diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py
index d016f0e8b8..145b5b19ee 100644
--- a/synapse/handlers/room.py
+++ b/synapse/handlers/room.py
@@ -136,19 +136,21 @@ class RoomCreationHandler(BaseHandler):
                 requester, tombstone_event, tombstone_context,
             )
 
-            # ... and restrict the PLs in the old room, if possible.
-            old_room_pl_state = yield self.state_handler.get_current_state(
-                old_room_id,
-                event_type=EventTypes.PowerLevels,
-                latest_event_ids=(tombstone_event.event_id, ),
-            )
+            old_room_state = yield tombstone_context.get_current_state_ids(self.store)
+            old_room_pl_event_id = old_room_state.get((EventTypes.PowerLevels, ""))
 
-            if old_room_pl_state is None:
+            if old_room_pl_event_id is None:
                 logger.warning(
                     "Not supported: upgrading a room with no PL event. Not setting PLs "
                     "in old room.",
                 )
             else:
+                # we try to stop regular users from speaking by setting the PL required
+                # to send regular events and invites to 'Moderator' level. That's normally
+                # 50, but if the default PL in a room is 50 or more, then we set the
+                # required PL above that.
+
+                old_room_pl_state = yield self.store.get_event(old_room_pl_event_id)
                 pl_content = dict(old_room_pl_state.content)
                 users_default = int(pl_content.get("users_default", 0))
                 restricted_level = max(users_default + 1, 50)
diff --git a/synapse/rest/client/v2_alpha/room_upgrade_rest_servlet.py b/synapse/rest/client/v2_alpha/room_upgrade_rest_servlet.py
index 1b195f90c4..e6356101fd 100644
--- a/synapse/rest/client/v2_alpha/room_upgrade_rest_servlet.py
+++ b/synapse/rest/client/v2_alpha/room_upgrade_rest_servlet.py
@@ -31,6 +31,22 @@ logger = logging.getLogger(__name__)
 
 
 class RoomUpgradeRestServlet(RestServlet):
+    """Handler for room uprade requests.
+
+    Handles requests of the form:
+
+        POST /_matrix/client/r0/rooms/$roomid/upgrade HTTP/1.1
+        Content-Type: application/json
+
+        {
+            "new_version": "2",
+        }
+
+    Creates a new room and shuts down the old one. Returns the ID of the new room.
+
+    Args:
+        hs (synapse.server.HomeServer):
+    """
     PATTERNS = client_v2_patterns(
         # /rooms/$roomid/upgrade
         "/rooms/(?P<room_id>[^/]*)/upgrade$",
@@ -38,11 +54,6 @@ class RoomUpgradeRestServlet(RestServlet):
     )
 
     def __init__(self, hs):
-        """
-
-        Args:
-            hs (synapse.server.HomeServer):
-        """
         super(RoomUpgradeRestServlet, self).__init__()
         self._hs = hs
         self._room_creation_handler = hs.get_room_creation_handler()