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.

refactor: Eliminate checks in build_stream_dict_for_sub.

Steve Howelld9740045a5aa
diff --git a/templates/zerver/api/changelog.md b/templates/zerver/api/changelog.md
index 48f7419f961..ff41e7bd347 100644
--- a/templates/zerver/api/changelog.md
+++ b/templates/zerver/api/changelog.md
@@ -10,6 +10,12 @@ below features are supported.
## Changes in Zulip 4.0
+**Feature level 37**
+
+* Consistently provide `subscribers` in stream data when
+ clients register for subscriptions with `include_subscribers`,
+ even if the user can't access subscribers.
+
**Feature level 36**
* [`POST /users`](/api/create-user): Restricted access to organization
diff --git a/version.py b/version.py
index 655d81fefa3..f4dd698314d 100644
--- a/version.py
+++ b/version.py
@@ -28,7 +28,7 @@ DESKTOP_WARNING_VERSION = "5.2.0"
#
# Changes should be accompanied by documentation explaining what the
# new level means in templates/zerver/api/changelog.md.
-API_FEATURE_LEVEL = 36
+API_FEATURE_LEVEL = 37
# Bump the minor PROVISION_VERSION to indicate that folks should provision
# only when going from an old version of the code to a newer version. Bump
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py
index 31cc0bf5f27..40e214c9e97 100644
--- a/zerver/lib/actions.py
+++ b/zerver/lib/actions.py
@@ -2666,7 +2666,9 @@ def validate_user_access_to_subscribers_helper(
if stream_dict["is_web_public"]:
return
- # Guest users can access subscribed public stream's subscribers
+ # With the exception of web public streams, a guest must
+ # be subscribed to a stream (even a public one) in order
+ # to see subscribers.
if user_profile.is_guest:
if check_user_subscribed(user_profile):
return
@@ -5056,15 +5058,6 @@ def build_stream_dict_for_sub(
result["email_address"] = encode_email_address_helper(
stream["name"], stream["email_token"], show_sender=True)
- # Important: don't show the subscribers if the stream is invite only
- # and this user isn't on it anymore (or a realm administrator).
- if stream["invite_only"] and not (sub["active"] or user.is_realm_admin):
- subscribers = None
-
- # Guest users lose access to subscribers when they are unsubscribed if the stream
- # is not web-public.
- if not sub["active"] and user.is_guest and not stream["is_web_public"]:
- subscribers = None
if subscribers is not None:
result["subscribers"] = subscribers
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index 4bed3f6a43e..07829a6627e 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -6226,6 +6226,12 @@ paths:
description: |
A list of user IDs of users who are subscribed
to the stream. Included only if `include_subscribers` is `true`.
+
+ If a user is not allowed to know the subscribers for
+ a stream, we will send an empty array. API authors
+ should use other data to determine whether users like
+ guest users are forbidden to know the subscribers.
+
description: |
Present if `subscription` is present in `fetch_event_types`.
diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py
index d62ca4a7a85..68afa89f253 100644
--- a/zerver/tests/test_subs.py
+++ b/zerver/tests/test_subs.py
@@ -4425,12 +4425,12 @@ class GetSubscribersTest(ZulipTestCase):
sub_data = gather_subscriptions_helper(non_admin_user)
unsubscribed_streams = sub_data[1]
self.assertEqual(len(unsubscribed_streams), 1)
- self.assertFalse('subscribers' in unsubscribed_streams[0])
+ self.assertEqual(unsubscribed_streams[0]['subscribers'], [])
sub_data = gather_subscriptions_helper(guest_user)
unsubscribed_streams = sub_data[1]
self.assertEqual(len(unsubscribed_streams), 1)
- self.assertFalse('subscribers' in unsubscribed_streams[0])
+ self.assertEqual(unsubscribed_streams[0]['subscribers'], [])
def test_gather_subscriptions_mit(self) -> None:
"""