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

Conversation

anoadragon453
Copy link
Member

@anoadragon453 anoadragon453 commented Jan 5, 2020

Fixes #6632

Sytests: matrix-org/sytest#777

Fixes a bug introduced in #6237 where in which a moderator in a room upgrades the room, the following oddities occur:

  • The Mod in the old room gets upgraded to an Admin (but only from the perspective of the server upgrading the room).
  • The Mod in the new room isn't being downgraded back to a Mod again, but is left as an Admin. (They need to be an Admin initially to send required room state, but should be downgraded back to their original power level immediately afterwards).

Turns out the problem was due to modifying initial_state, which was a dictionary representing the state of the old room. This modified object continues to persist however, and later on in _update_upgraded_room_pls, when we attempt to send a power level event to mute users in the old room, we end up grabbing initial_state again, which contains the Mod as an Admin instead. At this point, the Mod is set to an Admin in the old room.

Additionally, the way we downgrade the Mod back from an Admin to a Mod in the new room, is by simply applying the old room's power levels once again. But, since we're using the modified power levels object, which had the Mod as an Admin, the Mod remains an Admin in the new room.

Performing a deepcopy instead solves both of these problems.

@anoadragon453 anoadragon453 requested a review from a team January 5, 2020 07:06
@anoadragon453 anoadragon453 self-assigned this Jan 5, 2020
power_levels["users"][requester.user.to_string()] = needed_power_level
# Perform a deepcopy of the dict in order to not modify initial_state, as its
# contents are preserved as the state for the old room later on
initial_state = copy.deepcopy(initial_state)
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to copy the entire state rather than just the power levels event?

(it might also be preferable just to copy the bits we know we want from the PL body)

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to only deepcopy the power levels state. Let me know what you think.

@babolivier
Copy link
Contributor

Can we also have a test case for this? This way we ensure the fix works as intended and doesn't break in the future.

@Mikaela
Copy link
Contributor

Mikaela commented Jan 5, 2020

I am not sure this is a good idea, because this is currently the only method to get control of IRC rooms that are managed entirely by e.g. matrix-appservice-irc, matrix-org/matrix-appservice-irc#408.

Also if PL100 was required for upgrading rooms, only the appservice would be able to do that and I am not certain it's a good idea.

@tulir
Copy link
Member

tulir commented Jan 5, 2020

@Mikaela you can still manually upgrade rooms and set whatever power levels you like when creating the new room: https://gist.github.com/turt2live/a99c8e794d6115d4ddfaadb72aabf063

@anoadragon453
Copy link
Member Author

Can we also have a test case for this? This way we ensure the fix works as intended and doesn't break in the future.

Added tests.

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

lgtm otherwise

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)

@richvdh richvdh merged commit 01c3c6c into develop Jan 6, 2020
@anoadragon453 anoadragon453 deleted the anoa/fix_room_upgrade_pls branch January 6, 2020 14:39
babolivier pushed a commit that referenced this pull request Sep 1, 2021
…oom upgrade (#6633)

* commit '01c3c6c92':
  Fix power levels being incorrectly set in old and new rooms after a room upgrade (#6633)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants