mirror of https://github.com/zulip/zulip.git
search: Do not show inaccessible users in search suggestions.
We do not show inaccessible users in search suggestions.
This commit is contained in:
parent
2da3bd2813
commit
abf7b9225f
|
@ -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));
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue