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:
YJDave
2018-03-16 16:58:19 +05:30
committed by Tim Abbott
parent 72a440a86d
commit 0281079a39
2 changed files with 31 additions and 8 deletions

View File

@@ -3911,8 +3911,8 @@ def gather_subscriptions_helper(user_profile: UserProfile,
subscribers = subscriber_map[stream["id"]] # type: Optional[List[int]]
# Important: don't show the subscribers if the stream is invite only
# and this user isn't on it anymore.
if stream["invite_only"] and not sub["active"]:
# and this user isn't on it anymore (or a realm administrator).
if stream["invite_only"] and not (sub["active"] or user_profile.is_realm_admin):
subscribers = None
stream_dict = {'name': stream["name"],
@@ -3957,7 +3957,7 @@ def gather_subscriptions_helper(user_profile: UserProfile,
stream["date_created"],
recent_traffic),
'description': stream['description']}
if is_public:
if is_public or user_profile.is_realm_admin:
subscribers = subscriber_map[stream["id"]]
if subscribers is not None:
stream_dict['subscribers'] = subscribers

View File

@@ -2731,8 +2731,10 @@ class GetSubscribersTest(ZulipTestCase):
self.assertFalse('invite_only' in name)
self.assertTrue(len(stream_dict["subscribers"]) == len(users_to_subscribe))
# Send private stream subscribers to all realm admins.
def test_admin_case() -> None:
self.user_profile.is_realm_admin = True
# Test realm admins can get never subscribed private stream's subscribers.
never_subscribed = get_never_subscribed()
self.assertEqual(
@@ -2740,14 +2742,35 @@ class GetSubscribersTest(ZulipTestCase):
len(public_streams) + len(private_streams)
)
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()
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:
"""
gather_subscriptions returns correct results with only 3 queries