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.

stream: Do not send redundant events to users with metadata access.

Shubham Padia3893dcfcb8f7
diff --git a/zerver/actions/streams.py b/zerver/actions/streams.py
index 15f5a9155cf..5bcf9b162cf 100644
--- a/zerver/actions/streams.py
+++ b/zerver/actions/streams.py
@@ -519,7 +519,14 @@ def send_stream_creation_events_for_previously_inaccessible_streams(
# they can manage the new stream.
# Realm admins already have all created private streams.
realm_admin_ids = {user.id for user in realm.get_admin_users_and_bots()}
- notify_user_ids = list(stream_users_ids - realm_admin_ids)
+ user_ids_with_metadata_access_via_permission_groups = (
+ get_user_ids_with_metadata_access_via_permission_groups(stream)
+ )
+ notify_user_ids = list(
+ stream_users_ids
+ - realm_admin_ids
+ - user_ids_with_metadata_access_via_permission_groups
+ )
elif not stream.is_web_public:
# Guese users need a `create` notification for
# public streams as well because they need the stream
@@ -1278,8 +1285,15 @@ def do_change_stream_permission(
old_can_access_stream_metadata_user_ids = set(stream_subscriber_user_ids) | {
user.id for user in stream.realm.get_admin_users_and_bots()
}
+ user_ids_with_metadata_access_via_permission_groups = (
+ get_user_ids_with_metadata_access_via_permission_groups(stream)
+ )
non_guest_user_ids = set(active_non_guest_user_ids(stream.realm_id))
- notify_stream_creation_ids = non_guest_user_ids - old_can_access_stream_metadata_user_ids
+ notify_stream_creation_ids = (
+ non_guest_user_ids
+ - old_can_access_stream_metadata_user_ids
+ - user_ids_with_metadata_access_via_permission_groups
+ )
recent_traffic = get_streams_traffic({stream.id}, realm)
setting_groups_dict = get_group_setting_value_dict_for_streams([stream])
@@ -1293,7 +1307,11 @@ def do_change_stream_permission(
old_subscribers_access_user_ids = set(stream_subscriber_user_ids) | {
user.id for user in stream.realm.get_admin_users_and_bots()
}
- peer_notify_user_ids = non_guest_user_ids - old_subscribers_access_user_ids
+ peer_notify_user_ids = (
+ non_guest_user_ids
+ - old_subscribers_access_user_ids
+ - user_ids_with_metadata_access_via_permission_groups
+ )
peer_add_event = dict(
type="subscription",
op="peer_add",
diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py
index 381456fc4cb..f2f3919f5c8 100644
--- a/zerver/tests/test_subs.py
+++ b/zerver/tests/test_subs.py
@@ -6081,7 +6081,7 @@ class SubscriptionAPITest(ZulipTestCase):
# Verify that peer_event events are never sent in Zephyr
# realm. This does generate stream creation events from
# send_stream_creation_events_for_previously_inaccessible_streams.
- with self.assert_database_query_count(num_streams + 15):
+ with self.assert_database_query_count(num_streams * 2 + 15):
with self.capture_send_event_calls(expected_num_events=num_streams + 1) as events:
self.subscribe_via_post(
mit_user,
@@ -6548,7 +6548,7 @@ class SubscriptionAPITest(ZulipTestCase):
)
# Test creating private stream.
- with self.assert_database_query_count(48):
+ with self.assert_database_query_count(49):
self.subscribe_via_post(
self.test_user,
[new_streams[1]],