Skip to content

Commit

Permalink
typeahead helper: Hide email under hidden email-address-visibility ca…
Browse files Browse the repository at this point in the history
…ses.

In email hidden case (that is when `email_address_visibilty` is set to
everyone), for "non admins", this commit hides emails from:
- compose box user typeahead.
- PM user typeahead
In email hidden case, for admins, email is shown in user typeaheads.
  • Loading branch information
pragatiagrawal31 authored and timabbott committed May 20, 2019
1 parent cdc5009 commit 8eac739
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
9 changes: 5 additions & 4 deletions frontend_tests/node_tests/composebox_typeahead.js
Expand Up @@ -14,6 +14,7 @@ zrequire('user_pill');
zrequire('compose_pm_pill');
zrequire('composebox_typeahead');
zrequire('recent_senders');
zrequire('settings_org');
set_global('md5', function (s) {
return 'md5-' + s;
});
Expand Down Expand Up @@ -613,17 +614,17 @@ run_test('initialize', () => {
// corresponding parts in bold.
options.query = 'oth';
actual_value = options.highlighter(othello);
expected_value = ' <img class="typeahead-image" src="https://secure.gravatar.com/avatar/md5-othello@zulip.com?d&#x3D;identicon&amp;s&#x3D;50" />\n<strong>Othello, the Moor of Venice</strong>&nbsp;&nbsp;\n<small class="autocomplete_secondary">othello@zulip.com</small>\n';
expected_value = ' <img class="typeahead-image" src="https://secure.gravatar.com/avatar/md5-othello@zulip.com?d&#x3D;identicon&amp;s&#x3D;50" />\n<strong>Othello, the Moor of Venice</strong>';
assert.equal(actual_value, expected_value);

options.query = 'Lear';
actual_value = options.highlighter(cordelia);
expected_value = ' <img class="typeahead-image" src="https://secure.gravatar.com/avatar/md5-cordelia@zulip.com?d&#x3D;identicon&amp;s&#x3D;50" />\n<strong>Cordelia Lear</strong>&nbsp;&nbsp;\n<small class="autocomplete_secondary">cordelia@zulip.com</small>\n';
expected_value = ' <img class="typeahead-image" src="https://secure.gravatar.com/avatar/md5-cordelia@zulip.com?d&#x3D;identicon&amp;s&#x3D;50" />\n<strong>Cordelia Lear</strong>';
assert.equal(actual_value, expected_value);

options.query = 'othello@zulip.com, co';
actual_value = options.highlighter(cordelia);
expected_value = ' <img class="typeahead-image" src="https://secure.gravatar.com/avatar/md5-cordelia@zulip.com?d&#x3D;identicon&amp;s&#x3D;50" />\n<strong>Cordelia Lear</strong>&nbsp;&nbsp;\n<small class="autocomplete_secondary">cordelia@zulip.com</small>\n';
expected_value = ' <img class="typeahead-image" src="https://secure.gravatar.com/avatar/md5-cordelia@zulip.com?d&#x3D;identicon&amp;s&#x3D;50" />\n<strong>Cordelia Lear</strong>';
assert.equal(actual_value, expected_value);

// options.matcher()
Expand Down Expand Up @@ -776,7 +777,7 @@ run_test('initialize', () => {
// content_highlighter.
fake_this = { completing: 'mention', token: 'othello' };
actual_value = options.highlighter.call(fake_this, othello);
expected_value = ' <img class="typeahead-image" src="https://secure.gravatar.com/avatar/md5-othello@zulip.com?d&#x3D;identicon&amp;s&#x3D;50" />\n<strong>Othello, the Moor of Venice</strong>&nbsp;&nbsp;\n<small class="autocomplete_secondary">othello@zulip.com</small>\n';
expected_value = ' <img class="typeahead-image" src="https://secure.gravatar.com/avatar/md5-othello@zulip.com?d&#x3D;identicon&amp;s&#x3D;50" />\n<strong>Othello, the Moor of Venice</strong>';
assert.equal(actual_value, expected_value);

fake_this = { completing: 'mention', token: 'hamletcharacters' };
Expand Down
18 changes: 18 additions & 0 deletions frontend_tests/node_tests/typeahead_helper.js
@@ -1,3 +1,4 @@
set_global('i18n', global.stub_i18n);
set_global('page_params', {realm_is_zephyr_mirror_realm: false});
set_global('templates', {});
set_global('md5', function (s) {
Expand All @@ -14,6 +15,7 @@ zrequire('stream_data');
zrequire('narrow');
zrequire('hash_util');
zrequire('marked', 'third/marked/lib/marked');
zrequire('settings_org');
var th = zrequire('typeahead_helper');

stream_data.create_streams([
Expand Down Expand Up @@ -399,7 +401,23 @@ run_test('highlight_with_escaping', () => {
assert.equal(result, expected);
});

run_test('render_person when emails hidden', () => {
// Test render_person with regular person, under hidden email visiblity case
settings_org.show_email = () => false;
var rendered = false;
global.templates.render = function (template_name, args) {
assert.equal(template_name, 'typeahead_list_item');
assert.equal(args.primary, matches[2].full_name);
assert.equal(args.secondary, undefined);
rendered = true;
return 'typeahead-item-stub';
};
assert.equal(th.render_person(matches[2]), 'typeahead-item-stub');
assert(rendered);
});

run_test('render_person', () => {
settings_org.show_email = () => true;
// Test render_person with regular person
var rendered = false;
global.templates.render = function (template_name, args) {
Expand Down
10 changes: 6 additions & 4 deletions static/js/typeahead_helper.js
Expand Up @@ -91,15 +91,17 @@ exports.render_person = function (person) {
if (html === undefined) {
var avatar_url = people.small_avatar_url_for_person(person);

html = exports.render_typeahead_item({
var typeahead_arguments = {
primary: person.full_name,
secondary: person.email,
img_src: avatar_url,
is_person: true,
});
};
if (settings_org.show_email()) {
typeahead_arguments.secondary = person.email;
}
html = exports.render_typeahead_item(typeahead_arguments);
rendered.persons.set(person.user_id, html);
}

return html;
};

Expand Down

0 comments on commit 8eac739

Please sign in to comment.