From 69ec96b63e593f03b2ec52c5b7af31af75a165e4 Mon Sep 17 00:00:00 2001 From: Pragati Agrawal Date: Tue, 23 Apr 2019 21:32:06 +0530 Subject: [PATCH] search suggestion: Hide email under hidden email-address-visibility cases. This commit hides the email address from the search bar for the email hidden cases. --- .../node_tests/search_suggestion.js | 73 +++++++++++++------ .../node_tests/search_suggestion_legacy.js | 3 + static/js/search_suggestion.js | 5 +- 3 files changed, 56 insertions(+), 25 deletions(-) diff --git a/frontend_tests/node_tests/search_suggestion.js b/frontend_tests/node_tests/search_suggestion.js index 2cbd27fcfc..cc63d780da 100644 --- a/frontend_tests/node_tests/search_suggestion.js +++ b/frontend_tests/node_tests/search_suggestion.js @@ -19,6 +19,7 @@ var bob = { user_id: 42, }; +const noop = () => {}; function init() { people.init(); @@ -28,6 +29,9 @@ function init() { init(); set_global('narrow', {}); +set_global('settings_org', { + show_email: () => true, +}); topic_data.reset(); @@ -946,44 +950,39 @@ run_test('stream_completion', () => { assert.deepEqual(suggestions.strings, expected); }); -run_test('people_suggestions', () => { - var query = 'te'; +function people_suggestion_setup() { + global.stream_data.subscribed_streams = noop; + global.narrow_state.stream = noop; - global.stream_data.subscribed_streams = function () { - return []; - }; - - global.narrow_state.stream = function () { - return; - }; - - var ted = { + const ted = { email: 'ted@zulip.com', user_id: 201, full_name: 'Ted Smith', }; + people.add(ted); - var bob = { + const bob = { email: 'bob@zulip.com', user_id: 202, full_name: 'Bob Térry', }; - var alice = { + people.add(bob); + const alice = { email: 'alice@zulip.com', user_id: 203, full_name: 'Alice Ignore', }; - people.add(ted); - people.add(bob); people.add(alice); - topic_data.reset(); +} - var suggestions = search.get_suggestions('', query); - - var expected = [ +run_test('people_suggestions', () => { + people_suggestion_setup(); + let query = 'te'; + let suggestions = search.get_suggestions('', query); + let expected = [ "te", "sender:bob@zulip.com", "sender:ted@zulip.com", @@ -994,16 +993,15 @@ run_test('people_suggestions', () => { ]; assert.deepEqual(suggestions.strings, expected); - function describe(q) { - return suggestions.lookup_table[q].description; - } + + const describe = (q) => suggestions.lookup_table[q].description; + assert.equal(describe('pm-with:ted@zulip.com'), "Private messages with Ted Smith <ted@zulip.com>"); assert.equal(describe('sender:ted@zulip.com'), "Sent by Ted Smith <ted@zulip.com>"); suggestions = search.get_suggestions('', 'Ted '); // note space - expected = [ "Ted", "sender:ted@zulip.com", @@ -1014,7 +1012,7 @@ run_test('people_suggestions', () => { assert.deepEqual(suggestions.strings, expected); query = 'sender:ted sm'; - var base_query = ''; + let base_query = ''; expected = [ 'sender:ted+sm', 'sender:ted@zulip.com', @@ -1047,6 +1045,33 @@ run_test('people_suggestions', () => { assert.deepEqual(suggestions.strings, expected); }); +run_test('people_suggestion (Admin only email visibility)', () => { + /* Suggestions when realm_email_address_visibility is set to admin + only */ + people_suggestion_setup(); + const query = 'te'; + settings_org.show_email = () => false; + const suggestions = search.get_suggestions('', query); + const expected = [ + "te", + "sender:bob@zulip.com", + "sender:ted@zulip.com", + "pm-with:bob@zulip.com", // bob térry + "pm-with:ted@zulip.com", + "group-pm-with:bob@zulip.com", + "group-pm-with:ted@zulip.com", + ]; + + assert.deepEqual(suggestions.strings, expected); + + const describe = (q) => suggestions.lookup_table[q].description; + + assert.equal(describe('pm-with:ted@zulip.com'), + 'Private messages with Ted Smith'); + assert.equal(describe('sender:ted@zulip.com'), + 'Sent by Ted Smith'); +}); + run_test('operator_suggestions', () => { // Completed operator should return nothing var query = 'stream:'; diff --git a/frontend_tests/node_tests/search_suggestion_legacy.js b/frontend_tests/node_tests/search_suggestion_legacy.js index 3903d5da94..9c98066855 100644 --- a/frontend_tests/node_tests/search_suggestion_legacy.js +++ b/frontend_tests/node_tests/search_suggestion_legacy.js @@ -28,6 +28,9 @@ function init() { init(); set_global('narrow', {}); +set_global('settings_org', { + show_email: () => true, +}); topic_data.reset(); diff --git a/static/js/search_suggestion.js b/static/js/search_suggestion.js index 1ef1dac271..bbc4cd8159 100644 --- a/static/js/search_suggestion.js +++ b/static/js/search_suggestion.js @@ -8,7 +8,10 @@ function stream_matches_query(stream_name, q) { function highlight_person(query, person) { var hilite = typeahead_helper.highlight_query_in_phrase; - return hilite(query, person.full_name) + " <" + hilite(query, person.email) + ">"; + if (settings_org.show_email()) { + return hilite(query, person.full_name) + " <" + hilite(query, person.email) + ">"; + } + return hilite(query, person.full_name); } function match_criteria(operators, criteria) {