Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

search: Do not show inaccessible users in search suggestions.

Sahil Batraabf7b9225fbb
diff --git a/web/src/people.ts b/web/src/people.ts
index 82155e255a0..2706fcf0755 100644
--- a/web/src/people.ts
+++ b/web/src/people.ts
@@ -987,6 +987,10 @@ export function is_current_user_only_owner(): boolean {
export function filter_all_persons(pred: (person: User) => boolean): User[] {
const ret = [];
for (const person of people_by_user_id_dict.values()) {
+ if (person.is_inaccessible_user) {
+ continue;
+ }
+
if (pred(person)) {
ret.push(person);
}
@@ -1162,7 +1166,7 @@ export function get_active_message_people(): User[] {
export function get_people_for_search_bar(query: string): User[] {
const pred = build_person_matcher(query);
- const message_people = get_message_people();
+ const message_people = get_message_people().filter((user) => !user.is_inaccessible_user);
const small_results = message_people.filter((item) => pred(item));
diff --git a/web/tests/search_suggestion.test.js b/web/tests/search_suggestion.test.js
index 8f610ca5dc5..c1203fbb04d 100644
--- a/web/tests/search_suggestion.test.js
+++ b/web/tests/search_suggestion.test.js
@@ -864,6 +864,18 @@ test("people_suggestions", ({override, mock_template}) => {
people.add_active_user(bob);
people.add_active_user(alice);
+ // Add an inaccessible user to verify that it is not included in
+ // suggestions.
+ const inaccessible_user = {
+ user_id: 299,
+ // All inaccessible users are named as "Unknown user", but we name
+ // it differently here so that the name matches the search query.
+ full_name: "Test unknown user",
+ email: "[email protected]",
+ is_inaccessible_user: true,
+ };
+ people._add_user(inaccessible_user);
+
let suggestions = get_suggestions(query);
let expected = [
@@ -878,6 +890,28 @@ test("people_suggestions", ({override, mock_template}) => {
assert.deepEqual(suggestions.strings, expected);
+ const accessible_user = {
+ user_id: 299,
+ full_name: "Test unknown user",
+ email: "[email protected]",
+ };
+ people.add_active_user(accessible_user);
+ suggestions = get_suggestions(query);
+
+ expected = [
+ "te",
+ "sender:[email protected]",
+ "sender:[email protected]",
+ "sender:[email protected]",
+ "dm-including:[email protected]",
+ "dm-including:[email protected]",
+ "dm-including:[email protected]",
+ ];
+ assert.deepEqual(suggestions.strings, expected);
+
function is_person(q) {
return suggestions.lookup_table.get(q).is_person;
}