Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

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

Mateusz Mandera74d2aea76aee
diff --git a/zerver/lib/events.py b/zerver/lib/events.py
index 513a5e3247c..f999981533a 100644
--- a/zerver/lib/events.py
+++ b/zerver/lib/events.py
@@ -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
diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py
index 3e1cb0589c0..c79a405b1e0 100644
--- a/zerver/tests/test_events.py
+++ b/zerver/tests/test_events.py
@@ -1839,13 +1839,19 @@ class NormalActionsTest(BaseAction):
events = self.verify_action(action)
check_realm_bot_update("events[0]", events[0], "services")
- def test_do_deactivate_user(self) -> None:
+ def test_do_deactivate_bot(self) -> None:
bot = self.create_bot("test")
action = lambda: do_deactivate_user(bot, acting_user=None)
events = self.verify_action(action, num_events=2)
check_realm_user_remove("events[0]", events[0])
check_realm_bot_remove("events[1]", events[1])
+ def test_do_deactivate_user(self) -> None:
+ user_profile = self.example_user("cordelia")
+ action = lambda: do_deactivate_user(user_profile, acting_user=None)
+ events = self.verify_action(action, num_events=1)
+ check_realm_user_remove("events[0]", events[0])
+
def test_do_reactivate_user(self) -> None:
bot = self.create_bot("test")
self.subscribe(bot, "Denmark")