typeahead: Update for email_address_visibility settings.

This commit changes the code to show user according to emails based
on email_address_visibilty_values and the type of user.

1. email_address_visibility = admins,members and guests

   Typeaheads are shown according to original emails.

2. email_address_visibility = admins only

   Typeaheads are shown according to original email to admins which
   were previously shown according to system-generated email of
   form "user10@zulipdev.com".

   For non-admins, typeaheads are not shown according to emails as
   they are not visible in the typeahead itself to non-admins.

3. email_address_visibility = nobody

   Typeaheads are not shown according to emails for all type of users.
This commit is contained in:
sahil839
2020-04-06 17:00:40 +05:30
committed by Tim Abbott
parent 821059814e
commit 578ccea220
5 changed files with 47 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ zrequire('compose_pm_pill');
zrequire('composebox_typeahead');
zrequire('recent_senders');
zrequire('settings_org');
const settings_config = zrequire('settings_config');
set_global('md5', function (s) {
return 'md5-' + s;
});
@@ -695,6 +696,15 @@ run_test('initialize', () => {
assert.equal(matcher(query, othello), false);
assert.equal(matcher(query, cordelia), false);
query = 'oth';
page_params.realm_email_address_visibility =
settings_config.email_address_visibility_values.admins_only.code;
page_params.is_admin = false;
assert.equal(matcher(query, deactivated_user), false);
page_params.is_admin = true;
assert.equal(matcher(query, deactivated_user), true);
function sorter(query, people) {
return typeahead_helper.sort_recipients(
people,

View File

@@ -9,6 +9,7 @@ const noop = function () {};
const pills = {
pill: {},
};
const settings_config = zrequire('settings_config');
let create_item_handler;
@@ -119,6 +120,10 @@ run_test('populate_user_groups', () => {
return [realm_user_group];
};
people.get_visible_email = function () {
return bob.email;
};
let templates_render_called = false;
const fake_rendered_temp = $.create('fake_admin_user_group_list_template_rendered');
global.stub_templates(function (template, args) {
@@ -199,6 +204,10 @@ run_test('populate_user_groups', () => {
query: 'ali',
};
const fake_context_for_email = {
query: 'am',
};
(function test_source() {
const result = config.source.call(fake_context, iago);
const emails = result.map(user => user.email).sort();
@@ -213,6 +222,16 @@ run_test('populate_user_groups', () => {
result = config.matcher.call(fake_context, alice);
assert(result);
page_params.realm_email_address_visibility =
settings_config.email_address_visibility_values.admins_only.code;
page_params.is_admin = false;
result = config.matcher.call(fake_context_for_email, bob);
assert(!result);
page_params.is_admin = true;
result = config.matcher.call(fake_context_for_email, bob);
assert(result);
}());
(function test_sorter() {