invitations: Avoid adding to notifications stream unconditionally.

Adding invited users to the notifications stream unconditionally isn't
a correct behaviour for guest users, where the previous behavior of
including the notifications stream no longer makes sense. Therefore,
while inviting a new user, the notifications stream is listed along
with other streams with a message "recieves notifications for new
streams" in order to distinguish it from other streams.

Fixes #13645.
This commit is contained in:
Hashir Sarwar
2020-01-18 21:54:25 +05:00
committed by Tim Abbott
parent 05f1c6983b
commit 13b3eb24b0
4 changed files with 14 additions and 37 deletions

View File

@@ -123,20 +123,20 @@ function generate_multiuse_invite() {
}
exports.get_invite_streams = function () {
const streams = _.filter(stream_data.get_invite_stream_data(), function (stream) {
const is_notifications_stream = stream.name === page_params.notifications_stream;
// You can't actually elect to invite someone to the
// notifications stream. We won't even show it as a choice unless
// it's the only stream you have, or if you've made it private.
return stream_data.subscribed_streams().length === 1 ||
!is_notifications_stream ||
is_notifications_stream && stream.is_invite_only;
});
const streams = stream_data.get_invite_stream_data();
function compare_streams(a, b) {
return a.name.localeCompare(b.name);
}
streams.sort(compare_streams);
return streams;
};
function update_subscription_checkboxes() {
const data = {streams: exports.get_invite_streams()};
const data = {
streams: exports.get_invite_streams(),
notifications_stream: page_params.notifications_stream,
};
const html = render_invite_subscription(data);
$('#streams_to_add').html(html);
}

View File

@@ -11,7 +11,11 @@
{{#if default_stream}}checked="checked"{{/if}} />
<span></span>
{{#if invite_only}}<i class="fa fa-lock" aria-hidden="true"></i>{{/if}}
{{#if (eq name ../notifications_stream)}}
#{{name}} <i>({{t 'receives new stream notifications' }})</i>
{{else}}
#{{name}}
{{/if}}
</label>
{{/each}}
</div>

View File

@@ -891,27 +891,6 @@ class InviteUserTest(InviteUserBase):
self.assertTrue(find_key_by_email(email2))
self.check_sent_emails([email, email2])
def test_successful_invite_user_with_notifications_stream(self) -> None:
"""
A call to /json/invites with valid parameters unconditionally
subscribes the invitee to the notifications stream if it exists and is
public.
"""
realm = get_realm('zulip')
notifications_stream = get_stream('Verona', realm)
realm.notifications_stream_id = notifications_stream.id
realm.save()
self.login(self.example_email("hamlet"))
invitee = 'alice-test@zulip.com'
self.assert_json_success(self.invite(invitee, ['Denmark']))
self.assertTrue(find_key_by_email(invitee))
self.check_sent_emails([invitee])
prereg_user = PreregistrationUser.objects.get(email=invitee)
stream_ids = [stream.id for stream in prereg_user.streams.all()]
self.assertTrue(notifications_stream.id in stream_ids)
def test_invite_user_signup_initial_history(self) -> None:
"""
Test that a new user invited to a stream receives some initial

View File

@@ -37,12 +37,6 @@ def invite_users_backend(request: HttpRequest, user_profile: UserProfile,
invitee_emails = get_invitee_emails_set(invitee_emails_raw)
# We unconditionally sub you to the notifications stream if it
# exists and is public.
notifications_stream = user_profile.realm.notifications_stream # type: Optional[Stream]
if notifications_stream and not notifications_stream.invite_only:
stream_ids.append(notifications_stream.id)
streams = [] # type: List[Stream]
for stream_id in stream_ids:
try: