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

Commit

Permalink
restrict PLs in old room
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Oct 25, 2018
1 parent 3a263bf commit e6babc2
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,49 @@ def upgrade_room(self, requester, old_room_id, new_version):
requester, tombstone_event, tombstone_context,
)

# XXX send a power_levels in the old room, if possible
# ... 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, ),
)

if old_room_pl_state is None:
logger.warning(
"Not supported: upgrading a room with no PL event. Not setting PLs "
"in old room.",
)
else:
pl_content = dict(old_room_pl_state.content)
users_default = int(pl_content.get("users_default", 0))
restricted_level = max(users_default + 1, 50)

updated = False
for v in ("invite", "events_default"):
current = int(pl_content.get(v, 0))
if current < restricted_level:
logger.debug(
"Setting level for %s in %s to %i (was %i)",
v, old_room_id, restricted_level, current,
)
pl_content[v] = restricted_level
updated = True
else:
logger.debug(
"Not setting level for %s (already %i)",
v, current,
)

if updated:
yield self.event_creation_handler.create_and_send_nonmember_event(
requester, {
"type": EventTypes.PowerLevels,
"state_key": '',
"room_id": old_room_id,
"sender": user_id,
"content": pl_content,
}, ratelimit=False,
)

defer.returnValue(new_room_id)

Expand Down

0 comments on commit e6babc2

Please sign in to comment.