diff options
author | David Robertson <davidr@element.io> | 2022-05-07 13:37:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-07 13:37:29 +0100 |
commit | 051a1c3f220938a0ea1a5b328c268bdb3d1ad592 (patch) | |
tree | d5764fcd4e42ad0497d757f53afbd22c27cbd082 /synapse/handlers/room.py | |
parent | Prevent memory leak from reoccurring when presence is disabled. (#12656) (diff) | |
download | synapse-051a1c3f220938a0ea1a5b328c268bdb3d1ad592.tar.xz |
Convert stringy power levels to integers on room upgrade (#12657)
Diffstat (limited to 'synapse/handlers/room.py')
-rw-r--r-- | synapse/handlers/room.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index b31f00b517..604eb6ec15 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -57,7 +57,7 @@ from synapse.api.filtering import Filter from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, RoomVersion from synapse.event_auth import validate_event_for_room_version from synapse.events import EventBase -from synapse.events.utils import copy_power_levels_contents +from synapse.events.utils import copy_and_fixup_power_levels_contents from synapse.federation.federation_client import InvalidResponseError from synapse.handlers.federation import get_domains_from_state from synapse.handlers.relations import BundledAggregations @@ -337,13 +337,13 @@ class RoomCreationHandler: # 50, but if the default PL in a room is 50 or more, then we set the # required PL above that. - pl_content = dict(old_room_pl_state.content) - users_default = int(pl_content.get("users_default", 0)) + pl_content = copy_and_fixup_power_levels_contents(old_room_pl_state.content) + users_default: int = pl_content.get("users_default", 0) # type: ignore[assignment] restricted_level = max(users_default + 1, 50) updated = False for v in ("invite", "events_default"): - current = int(pl_content.get(v, 0)) + current: int = pl_content.get(v, 0) # type: ignore[assignment] if current < restricted_level: logger.debug( "Setting level for %s in %s to %i (was %i)", @@ -380,7 +380,9 @@ class RoomCreationHandler: "state_key": "", "room_id": new_room_id, "sender": requester.user.to_string(), - "content": old_room_pl_state.content, + "content": copy_and_fixup_power_levels_contents( + old_room_pl_state.content + ), }, ratelimit=False, ) @@ -471,7 +473,7 @@ class RoomCreationHandler: # dict so we can't just copy.deepcopy it. initial_state[ (EventTypes.PowerLevels, "") - ] = power_levels = copy_power_levels_contents( + ] = power_levels = copy_and_fixup_power_levels_contents( initial_state[(EventTypes.PowerLevels, "")] ) |