mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 16:37:23 +00:00
stream settings: Send all private streams subs to realm admins on load.
Tweaked by tabbott to simplify the conditionals in actions.py. Fixes #8695.
This commit is contained in:
@@ -3911,8 +3911,8 @@ def gather_subscriptions_helper(user_profile: UserProfile,
|
|||||||
subscribers = subscriber_map[stream["id"]] # type: Optional[List[int]]
|
subscribers = subscriber_map[stream["id"]] # type: Optional[List[int]]
|
||||||
|
|
||||||
# Important: don't show the subscribers if the stream is invite only
|
# Important: don't show the subscribers if the stream is invite only
|
||||||
# and this user isn't on it anymore.
|
# and this user isn't on it anymore (or a realm administrator).
|
||||||
if stream["invite_only"] and not sub["active"]:
|
if stream["invite_only"] and not (sub["active"] or user_profile.is_realm_admin):
|
||||||
subscribers = None
|
subscribers = None
|
||||||
|
|
||||||
stream_dict = {'name': stream["name"],
|
stream_dict = {'name': stream["name"],
|
||||||
@@ -3957,7 +3957,7 @@ def gather_subscriptions_helper(user_profile: UserProfile,
|
|||||||
stream["date_created"],
|
stream["date_created"],
|
||||||
recent_traffic),
|
recent_traffic),
|
||||||
'description': stream['description']}
|
'description': stream['description']}
|
||||||
if is_public:
|
if is_public or user_profile.is_realm_admin:
|
||||||
subscribers = subscriber_map[stream["id"]]
|
subscribers = subscriber_map[stream["id"]]
|
||||||
if subscribers is not None:
|
if subscribers is not None:
|
||||||
stream_dict['subscribers'] = subscribers
|
stream_dict['subscribers'] = subscribers
|
||||||
|
|||||||
@@ -2731,8 +2731,10 @@ class GetSubscribersTest(ZulipTestCase):
|
|||||||
self.assertFalse('invite_only' in name)
|
self.assertFalse('invite_only' in name)
|
||||||
self.assertTrue(len(stream_dict["subscribers"]) == len(users_to_subscribe))
|
self.assertTrue(len(stream_dict["subscribers"]) == len(users_to_subscribe))
|
||||||
|
|
||||||
|
# Send private stream subscribers to all realm admins.
|
||||||
def test_admin_case() -> None:
|
def test_admin_case() -> None:
|
||||||
self.user_profile.is_realm_admin = True
|
self.user_profile.is_realm_admin = True
|
||||||
|
# Test realm admins can get never subscribed private stream's subscribers.
|
||||||
never_subscribed = get_never_subscribed()
|
never_subscribed = get_never_subscribed()
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@@ -2740,14 +2742,35 @@ class GetSubscribersTest(ZulipTestCase):
|
|||||||
len(public_streams) + len(private_streams)
|
len(public_streams) + len(private_streams)
|
||||||
)
|
)
|
||||||
for stream_dict in never_subscribed:
|
for stream_dict in never_subscribed:
|
||||||
name = stream_dict['name']
|
|
||||||
if 'invite_only' in name:
|
|
||||||
self.assertFalse('subscribers' in stream_dict)
|
|
||||||
else:
|
|
||||||
self.assertTrue(len(stream_dict["subscribers"]) == len(users_to_subscribe))
|
self.assertTrue(len(stream_dict["subscribers"]) == len(users_to_subscribe))
|
||||||
|
|
||||||
test_admin_case()
|
test_admin_case()
|
||||||
|
|
||||||
|
def test_previously_subscribed_private_streams(self) -> None:
|
||||||
|
admin_user = self.example_user("iago")
|
||||||
|
non_admin_user = self.example_user("cordelia")
|
||||||
|
stream_name = "private_stream"
|
||||||
|
|
||||||
|
self.make_stream(stream_name, realm=get_realm("zulip"), invite_only=True)
|
||||||
|
self.subscribe(admin_user, stream_name)
|
||||||
|
self.subscribe(non_admin_user, stream_name)
|
||||||
|
self.subscribe(self.example_user("othello"), stream_name)
|
||||||
|
|
||||||
|
self.unsubscribe(admin_user, stream_name)
|
||||||
|
self.unsubscribe(non_admin_user, stream_name)
|
||||||
|
|
||||||
|
# Test non admin user shouldn't get previously subscribed private stream's subscribers.
|
||||||
|
sub_data = gather_subscriptions_helper(admin_user)
|
||||||
|
unsubscribed_streams = sub_data[1]
|
||||||
|
self.assertEqual(len(unsubscribed_streams), 1)
|
||||||
|
self.assertEqual(len(unsubscribed_streams[0]["subscribers"]), 1)
|
||||||
|
|
||||||
|
# Test admin users can get previously subscribed private stream's subscribers.
|
||||||
|
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)
|
||||||
|
|
||||||
def test_gather_subscriptions_mit(self) -> None:
|
def test_gather_subscriptions_mit(self) -> None:
|
||||||
"""
|
"""
|
||||||
gather_subscriptions returns correct results with only 3 queries
|
gather_subscriptions returns correct results with only 3 queries
|
||||||
|
|||||||
Reference in New Issue
Block a user