From 9caab0c364e4c79c76cc0816a598ad6174da364b Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Thu, 14 Feb 2019 13:43:50 +0000 Subject: [PATCH 1/5] Transfer bans on room upgrade --- synapse/handlers/room.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index f9af1f004..924880d52 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -285,6 +285,7 @@ class RoomCreationHandler(BaseHandler): (EventTypes.RoomAvatar, ""), (EventTypes.Encryption, ""), (EventTypes.ServerACL, ""), + (EventTypes.Member, None), ) old_room_state_ids = yield self.store.get_filtered_current_state_ids( @@ -296,6 +297,19 @@ class RoomCreationHandler(BaseHandler): for k, old_event_id in iteritems(old_room_state_ids): old_event = old_room_state_events.get(old_event_id) if old_event: + + # Only transfer ban membership events + if ("membership" in old_event.content and + old_event.content["membership"] == "ban"): + yield self.room_member_handler.update_membership( + requester, + UserID.from_string(old_event['state_key']), + room_id, + "ban", + ratelimit=False, + content=old_event.content, + ) + initial_state[k] = old_event.content yield self._send_events_for_new_room( From 7033b05cada17a67057643608977236066f65d6a Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Mon, 18 Feb 2019 13:40:17 +0000 Subject: [PATCH 2/5] Add changelog --- changelog.d/4642.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/4642.bugfix diff --git a/changelog.d/4642.bugfix b/changelog.d/4642.bugfix new file mode 100644 index 000000000..bfbf95bcb --- /dev/null +++ b/changelog.d/4642.bugfix @@ -0,0 +1 @@ +Transfer bans on room upgrade. \ No newline at end of file From 915421065b6738c78779d40994cb2dd33d618b9b Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Mon, 18 Feb 2019 14:02:09 +0000 Subject: [PATCH 3/5] Membership events are done later --- synapse/handlers/room.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 924880d52..2d24c115b 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -294,21 +294,14 @@ class RoomCreationHandler(BaseHandler): # map from event_id to BaseEvent old_room_state_events = yield self.store.get_events(old_room_state_ids.values()) + member_events = [] for k, old_event_id in iteritems(old_room_state_ids): old_event = old_room_state_events.get(old_event_id) if old_event: - - # Only transfer ban membership events - if ("membership" in old_event.content and - old_event.content["membership"] == "ban"): - yield self.room_member_handler.update_membership( - requester, - UserID.from_string(old_event['state_key']), - room_id, - "ban", - ratelimit=False, - content=old_event.content, - ) + # Do membership events later + if ("membership" in old_event.content): + member_events.append(old_event) + continue initial_state[k] = old_event.content @@ -325,6 +318,21 @@ class RoomCreationHandler(BaseHandler): creation_content=creation_content, ) + # Transfer membership events + for old_event in member_events: + # Only transfer ban events + logger.info("Event type: " + str(old_event.content)) + if ("membership" in old_event.content and + old_event.content["membership"] == "ban"): + yield self.room_member_handler.update_membership( + requester, + UserID.from_string(old_event['state_key']), + new_room_id, + "ban", + ratelimit=False, + content=old_event.content, + ) + # XXX invites/joins # XXX 3pid invites From f8b9ca53cedced14c5687581d981b5473bb7054d Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Mon, 18 Feb 2019 16:56:34 +0000 Subject: [PATCH 4/5] Move member event processing and changelog fix --- changelog.d/{4642.bugfix => 4642.feature} | 0 synapse/handlers/room.py | 16 +++++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) rename changelog.d/{4642.bugfix => 4642.feature} (100%) diff --git a/changelog.d/4642.bugfix b/changelog.d/4642.feature similarity index 100% rename from changelog.d/4642.bugfix rename to changelog.d/4642.feature diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 2d24c115b..0676e7f62 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -285,7 +285,6 @@ class RoomCreationHandler(BaseHandler): (EventTypes.RoomAvatar, ""), (EventTypes.Encryption, ""), (EventTypes.ServerACL, ""), - (EventTypes.Member, None), ) old_room_state_ids = yield self.store.get_filtered_current_state_ids( @@ -294,15 +293,9 @@ class RoomCreationHandler(BaseHandler): # map from event_id to BaseEvent old_room_state_events = yield self.store.get_events(old_room_state_ids.values()) - member_events = [] for k, old_event_id in iteritems(old_room_state_ids): old_event = old_room_state_events.get(old_event_id) if old_event: - # Do membership events later - if ("membership" in old_event.content): - member_events.append(old_event) - continue - initial_state[k] = old_event.content yield self._send_events_for_new_room( @@ -319,9 +312,14 @@ class RoomCreationHandler(BaseHandler): ) # Transfer membership events - for old_event in member_events: + old_room_member_state_ids = yield self.store.get_filtered_current_state_ids( + old_room_id, StateFilter.from_types([(EventTypes.Member, None)]), + ) + + # map from event_id to BaseEvent + old_room_member_state_events = yield self.store.get_events(old_room_member_state_ids.values()) + for k, old_event in iteritems(old_room_member_state_events): # Only transfer ban events - logger.info("Event type: " + str(old_event.content)) if ("membership" in old_event.content and old_event.content["membership"] == "ban"): yield self.room_member_handler.update_membership( From 34ac75ce2c576f32a58fb7070fd52279cba70515 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Mon, 18 Feb 2019 18:23:37 +0000 Subject: [PATCH 5/5] lint --- synapse/handlers/room.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 0676e7f62..67b15697f 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -317,7 +317,9 @@ class RoomCreationHandler(BaseHandler): ) # map from event_id to BaseEvent - old_room_member_state_events = yield self.store.get_events(old_room_member_state_ids.values()) + old_room_member_state_events = yield self.store.get_events( + old_room_member_state_ids.values(), + ) for k, old_event in iteritems(old_room_member_state_events): # Only transfer ban events if ("membership" in old_event.content and