streams: Hide unsubscribed streams in settings to guest users.

This commit is contained in:
Yashashvi Dave 2019-05-08 12:27:23 +05:30 committed by Tim Abbott
parent 80ceb1a46d
commit 2598db4a77
3 changed files with 18 additions and 0 deletions

View File

@ -1,6 +1,7 @@
set_global('page_params', {
is_admin: false,
realm_users: [],
is_guest: false,
});
set_global('$', function () {
@ -427,6 +428,15 @@ run_test('stream_settings', () => {
assert.equal(sub.invite_only, false);
assert.equal(sub.history_public_to_subscribers, false);
assert.equal(sub.is_announcement_only, false);
// For guest user only retrieve subscribed streams
sub_rows = stream_data.get_updated_unsorted_subs();
assert.equal(sub_rows.length, 3);
global.page_params.is_guest = true;
sub_rows = stream_data.get_updated_unsorted_subs();
assert.equal(sub_rows[0].name, 'c');
assert.equal(sub_rows[1].name, 'a');
assert.equal(sub_rows.length, 2);
});
run_test('default_stream_names', () => {

View File

@ -5,6 +5,7 @@ set_global('ui', {});
zrequire('util');
zrequire('stream_data');
zrequire('search_util');
set_global('page_params', {});
global.patch_builtin('window', {
location: {

View File

@ -194,6 +194,13 @@ exports.get_updated_unsorted_subs = function () {
exports.update_calculated_fields(sub);
});
// We don't display unsubscribed streams to guest users.
if (page_params.is_guest) {
all_subs = _.reject(all_subs, function (sub) {
return !sub.subscribed;
});
}
return all_subs;
};