search: Do not show inaccessible users in search suggestions.

We do not show inaccessible users in search suggestions.
This commit is contained in:
Sahil Batra 2023-12-01 19:35:08 +05:30 committed by Tim Abbott
parent 2da3bd2813
commit abf7b9225f
2 changed files with 39 additions and 1 deletions

View File

@ -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));

View File

@ -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: "user299@zulipdev.com",
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: "user299@zulipdev.com",
};
people.add_active_user(accessible_user);
suggestions = get_suggestions(query);
expected = [
"te",
"sender:bob@zulip.com",
"sender:ted@zulip.com",
"sender:user299@zulipdev.com",
"dm:bob@zulip.com",
"dm:ted@zulip.com",
"dm:user299@zulipdev.com",
"dm-including:bob@zulip.com",
"dm-including:ted@zulip.com",
"dm-including:user299@zulipdev.com",
];
assert.deepEqual(suggestions.strings, expected);
function is_person(q) {
return suggestions.lookup_table.get(q).is_person;
}