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: Notify users with metadata access on unarchiving stream.

Shubham Padia48eec43f4854
diff --git a/api_docs/changelog.md b/api_docs/changelog.md
index cbaf9089183..eeabaf29fcf 100644
--- a/api_docs/changelog.md
+++ b/api_docs/changelog.md
@@ -35,6 +35,11 @@ format used by the Zulip server that they are interacting with.
only metadata access without having content access to it. They
cannot add subscribers to the channel or change it's privacy setting
without having content access to it.
+* [`GET /events`](/api/get-events): All users with metadata access to
+ a channel are now notified when a relevant stream event occurs.
+ Previously, non-admin users who were channel admins or users
+ belonging to `can_add_subscribers_group` were not notified of events
+ for a private channel they were not subscribed to.
**Feature level 348**
diff --git a/zerver/actions/streams.py b/zerver/actions/streams.py
index 178d40af56a..9d9085e3cb4 100644
--- a/zerver/actions/streams.py
+++ b/zerver/actions/streams.py
@@ -43,6 +43,7 @@ from zerver.lib.streams import (
get_occupied_streams,
get_stream_permission_policy_name,
get_stream_post_policy_value_based_on_group_setting,
+ get_user_ids_with_metadata_access_via_permission_groups,
render_stream_description,
send_stream_creation_event,
send_stream_deletion_event,
@@ -269,15 +270,17 @@ def do_unarchive_stream(stream: Stream, new_name: str, *, acting_user: UserProfi
recent_traffic = get_streams_traffic({stream.id}, realm)
- subscribed_users = {sub.user_profile for sub in stream_subscribers}
- admin_users_and_bots = set(realm.get_admin_users_and_bots())
+ subscribed_user_ids = {sub.user_profile.id for sub in stream_subscribers}
+ admin_user_and_bot_ids = {user.id for user in realm.get_admin_users_and_bots()}
- notify_users = admin_users_and_bots | subscribed_users
+ notify_user_ids = list(
+ admin_user_and_bot_ids
+ | subscribed_user_ids
+ | get_user_ids_with_metadata_access_via_permission_groups(stream)
+ )
setting_groups_dict = get_group_setting_value_dict_for_streams([stream])
- send_stream_creation_event(
- realm, stream, [user.id for user in notify_users], recent_traffic, setting_groups_dict
- )
+ send_stream_creation_event(realm, stream, notify_user_ids, recent_traffic, setting_groups_dict)
sender = get_system_bot(settings.NOTIFICATION_BOT, stream.realm_id)
with override_language(stream.realm.default_language):
diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py
index bf8eb82973e..514e37bc9ff 100644
--- a/zerver/tests/test_subs.py
+++ b/zerver/tests/test_subs.py
@@ -1847,12 +1847,24 @@ class StreamAdminTest(ZulipTestCase):
iago = self.example_user("iago")
hamlet = self.example_user("hamlet")
cordelia = self.example_user("cordelia")
+ aaron = self.example_user("aaron")
+ shiva = self.example_user("shiva")
stream = self.make_stream("new_stream", is_web_public=True)
was_invite_only = stream.invite_only
was_web_public = stream.is_web_public
was_history_public = stream.history_public_to_subscribers
+ aaron_group = self.create_or_update_anonymous_group_for_setting([aaron], [])
+ do_change_stream_group_based_setting(
+ stream, "can_administer_channel_group", aaron_group, acting_user=aaron
+ )
+
+ shiva_group = self.create_or_update_anonymous_group_for_setting([shiva], [])
+ do_change_stream_group_based_setting(
+ stream, "can_add_subscribers_group", shiva_group, acting_user=shiva
+ )
+
self.subscribe(hamlet, stream.name)
self.subscribe(cordelia, stream.name)
do_deactivate_stream(stream, acting_user=None)
@@ -1863,7 +1875,10 @@ class StreamAdminTest(ZulipTestCase):
self.assertEqual(events[0]["event"]["op"], "create")
self.assertEqual(events[0]["event"]["streams"][0]["name"], "new_stream")
self.assertEqual(events[0]["event"]["streams"][0]["stream_id"], stream.id)
- self.assertEqual(set(events[0]["users"]), {hamlet.id, cordelia.id, iago.id, desdemona.id})
+ self.assertEqual(
+ set(events[0]["users"]),
+ {hamlet.id, cordelia.id, iago.id, desdemona.id, aaron.id, shiva.id},
+ )
stream = Stream.objects.get(id=stream.id)
self.assertFalse(stream.deactivated)