summary refs log tree commit diff
path: root/synapse/handlers
diff options
context:
space:
mode:
authorAndrew Morgan <1342360+anoadragon453@users.noreply.github.com>2020-01-06 04:53:07 -0500
committerRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2020-01-06 09:53:07 +0000
commit01c3c6c9298d0bbdbbc6e829e9c9f1e1a52e8332 (patch)
tree90878a38ea76e38c522a00ad8709ae80d42bbda0 /synapse/handlers
parentAutomate generation of the sample and debian log configs (#6627) (diff)
downloadsynapse-01c3c6c9298d0bbdbbc6e829e9c9f1e1a52e8332.tar.xz
Fix power levels being incorrectly set in old and new rooms after a room upgrade (#6633)
Modify a copy of an upgraded room's PL before sending to the new room
Diffstat (limited to 'synapse/handlers')
-rw-r--r--synapse/handlers/room.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py
index 89c9118b26..4f489762fc 100644
--- a/synapse/handlers/room.py
+++ b/synapse/handlers/room.py
@@ -16,6 +16,7 @@
 # limitations under the License.
 
 """Contains functions for performing events on rooms."""
+import copy
 import itertools
 import logging
 import math
@@ -271,7 +272,7 @@ class RoomCreationHandler(BaseHandler):
             except AuthError as e:
                 logger.warning("Unable to update PLs in old room: %s", e)
 
-        logger.info("Setting correct PLs in new room")
+        logger.info("Setting correct PLs in new room to %s", old_room_pl_state.content)
         yield self.event_creation_handler.create_and_send_nonmember_event(
             requester,
             {
@@ -365,13 +366,15 @@ class RoomCreationHandler(BaseHandler):
         needed_power_level = max(state_default, ban, max(event_power_levels.values()))
 
         # Raise the requester's power level in the new room if necessary
-        current_power_level = power_levels["users"][requester.user.to_string()]
+        current_power_level = power_levels["users"][user_id]
         if current_power_level < needed_power_level:
-            # Assign this power level to the requester
-            power_levels["users"][requester.user.to_string()] = needed_power_level
+            # Perform a deepcopy in order to not modify the original power levels in a
+            # room, as its contents are preserved as the state for the old room later on
+            new_power_levels = copy.deepcopy(power_levels)
+            initial_state[(EventTypes.PowerLevels, "")] = new_power_levels
 
-        # Set the power levels to the modified state
-        initial_state[(EventTypes.PowerLevels, "")] = power_levels
+            # Assign this power level to the requester
+            new_power_levels["users"][user_id] = needed_power_level
 
         yield self._send_events_for_new_room(
             requester,
@@ -733,7 +736,7 @@ class RoomCreationHandler(BaseHandler):
         initial_state,
         creation_content,
         room_alias=None,
-        power_level_content_override=None,
+        power_level_content_override=None,  # Doesn't apply when initial state has power level state event content
         creator_join_profile=None,
     ):
         def create(etype, content, **kwargs):