Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
users: Send peer_add subscription events on reactivating users.
Sahil Batra9b8713fc1e5e
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.pyindex c053910dca0..c58578a9635 100644--- a/zerver/lib/actions.py+++ b/zerver/lib/actions.py@@ -813,6 +813,29 @@ def do_reactivate_user(user_profile: UserProfile, *, acting_user: Optional[UserPif user_profile.is_bot:notify_created_bot(user_profile)+ subscribed_recipient_ids = Subscription.objects.filter(+ user_profile_id=user_profile.id, active=True, recipient__type=Recipient.STREAM+ ).values_list("recipient__type_id", flat=True)+ subscribed_streams = Stream.objects.filter(id__in=subscribed_recipient_ids, deactivated=False)+ subscriber_peer_info = bulk_get_subscriber_peer_info(+ realm=user_profile.realm,+ streams=subscribed_streams,+ )++ altered_user_dict: Dict[int, Set[int]] = defaultdict(set)+ for stream in subscribed_streams:+ altered_user_dict[stream.id] = {user_profile.id}++ stream_dict = {stream.id: stream for stream in subscribed_streams}++ send_peer_subscriber_events(+ op="peer_add",+ realm=user_profile.realm,+ altered_user_dict=altered_user_dict,+ stream_dict=stream_dict,+ private_peer_dict=subscriber_peer_info.private_peer_dict,+ )+def active_humans_in_realm(realm: Realm) -> Sequence[UserProfile]:return UserProfile.objects.filter(realm=realm, is_active=True, is_bot=False)diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.pyindex d8f6c400f6e..3e1cb0589c0 100644--- a/zerver/tests/test_events.py+++ b/zerver/tests/test_events.py@@ -1848,10 +1848,23 @@ class NormalActionsTest(BaseAction):def test_do_reactivate_user(self) -> None:bot = self.create_bot("test")+ self.subscribe(bot, "Denmark")+ self.make_stream("Test private stream", invite_only=True)+ self.subscribe(bot, "Test private stream")do_deactivate_user(bot, acting_user=None)action = lambda: do_reactivate_user(bot, acting_user=None)- events = self.verify_action(action, num_events=2)+ events = self.verify_action(action, num_events=3)+ check_realm_bot_add("events[1]", events[1])+ check_subscription_peer_add("events[2]", events[2])++ # Test 'peer_add' event for private stream is received only if user is subscribed to it.+ do_deactivate_user(bot, acting_user=None)+ self.subscribe(self.example_user("hamlet"), "Test private stream")+ action = lambda: do_reactivate_user(bot, acting_user=None)+ events = self.verify_action(action, num_events=4)check_realm_bot_add("events[1]", events[1])+ check_subscription_peer_add("events[2]", events[2])+ check_subscription_peer_add("events[3]", events[3])def test_do_deactivate_realm(self) -> None:realm = self.user_profile.realm