Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix power levels being incorrectly set in old and new rooms after a room upgrade #6633

Merged
merged 5 commits into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/6633.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug where a moderator upgraded a room and became an admin in the new room.
16 changes: 10 additions & 6 deletions synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# limitations under the License.

"""Contains functions for performing events on rooms."""
import copy
import itertools
import logging
import math
Expand Down Expand Up @@ -271,7 +272,7 @@ def _update_upgraded_room_pls(
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,
{
Expand Down Expand Up @@ -367,11 +368,14 @@ def clone_existing_room(
# Raise the requester's power level in the new room if necessary
current_power_level = power_levels["users"][requester.user.to_string()]
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
existing_power_levels = initial_state[(EventTypes.PowerLevels, "")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we've already got this, in power_levels (line 359)

new_power_levels = copy.deepcopy(existing_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"][requester.user.to_string()] = needed_power_level

yield self._send_events_for_new_room(
requester,
Expand Down Expand Up @@ -733,7 +737,7 @@ def _send_events_for_new_room(
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):
Expand Down