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.

actions: Modify validate_user_access_to_subscribers.

Clara Dantas523bb30f33a2
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py
index 65ca306a853..4b4bcd744b6 100644
--- a/zerver/lib/actions.py
+++ b/zerver/lib/actions.py
@@ -2541,6 +2541,7 @@ def validate_user_access_to_subscribers(user_profile: Optional[UserProfile],
validate_user_access_to_subscribers_helper(
user_profile,
{"realm_id": stream.realm_id,
+ "is_web_public": stream.is_web_public,
"invite_only": stream.invite_only},
# We use a lambda here so that we only compute whether the
# user is subscribed if we have to
@@ -2576,6 +2577,11 @@ def validate_user_access_to_subscribers_helper(
if user_profile.realm_id != stream_dict["realm_id"]:
raise ValidationError("Requesting user not in given realm")
+ # Even guest users can access subscribers to web-public streams,
+ # since they can freely become subscribers to these streams.
+ if stream_dict["is_web_public"]:
+ return
+
# Guest users can access subscribed public stream's subscribers
if user_profile.is_guest:
if check_user_subscribed(user_profile):
diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py
index edf3fdcf161..d4eab5418cb 100644
--- a/zerver/tests/test_subs.py
+++ b/zerver/tests/test_subs.py
@@ -3967,6 +3967,14 @@ class GetSubscribersTest(ZulipTestCase):
self.assertTrue(stream_dict["stream_id"] not in sub_ids)
self.assertTrue(stream_dict["stream_id"] not in unsub_ids)
+ # The Rome stream has is_web_public=True, with default
+ # subscribers not setup by this test, so we do the
+ # following check only for the streams we created.
+ if stream_dict["name"] in web_public_streams:
+ self.assertEqual(
+ len(stream_dict["subscribers"]),
+ len(users_to_subscribe))
+
test_guest_user_case()
def test_gather_subscribed_streams_for_guest_user(self) -> None:
@@ -4135,6 +4143,26 @@ class GetSubscribersTest(ZulipTestCase):
subscribers.append(subscriber)
self.assertEqual(set(subscribers), set(expected_subscribers))
+ def test_json_get_subscribers_for_guest_user(self) -> None:
+ """
+ Guest users should have access to subscribers of web-public streams, even
+ if they aren't subscribed or have never subscribed to that stream.
+ """
+ guest_user = self.example_user("polonius")
+ _, _, never_subscribed = gather_subscriptions_helper(guest_user, True)
+ # A guest user can only see never subscribed streams that are web-public.
+ # For Polonius, the only web public stream that he is not subscribed at
+ # this point is Rome.
+ self.assertTrue(len(never_subscribed) == 1)
+
+ web_public_stream_id = never_subscribed[0]['stream_id']
+ result = self.client_get(f"/json/streams/{web_public_stream_id}/members")
+ self.assert_json_success(result)
+ result_dict = result.json()
+ self.assertIn('subscribers', result_dict)
+ self.assertIsInstance(result_dict['subscribers'], list)
+ self.assertTrue(len(result_dict['subscribers']) > 0)
+
def test_nonsubscriber_private_stream(self) -> None:
"""
A non-subscriber non realm admin user to a private stream can't query that stream's membership.