apply_events: Update state["subscribers"] upon "remove user" event.

Event of type "realm_user", op "remove", emitted by do_deactivate_user
should remove the user id from subscriptions in the state. We weren't
catching this bug, because test_do_deactivate_bot uses a newly created
bot, so no stream subscriptions are affected. The bug shows up if
deactivating e.g. cordelia - thus we want to have two tests instead,
one for testing bot deactivation and one for user deactivation.
This commit is contained in:
Mateusz Mandera
2022-01-14 22:50:27 +01:00
committed by Tim Abbott
parent dd1c9c45c7
commit 74d2aea76a
2 changed files with 12 additions and 1 deletions

View File

@@ -746,6 +746,11 @@ def apply_event(
state["raw_users"][person_user_id] = person
elif event["op"] == "remove":
state["raw_users"][person_user_id]["is_active"] = False
if include_subscribers:
for sub in state["subscriptions"]:
sub["subscribers"] = [
user_id for user_id in sub["subscribers"] if user_id != person_user_id
]
elif event["op"] == "update":
is_me = person_user_id == user_profile.id