FIX: Use specified limit option in user search (#20020)
This commit is contained in:
parent
798b4bb604
commit
2c9d76e510
|
@ -150,41 +150,38 @@ function organizeResults(r, options) {
|
|||
return r;
|
||||
}
|
||||
|
||||
let exclude = options.exclude || [],
|
||||
limit = options.limit || 5,
|
||||
const exclude = options.exclude || [];
|
||||
|
||||
const results = [],
|
||||
users = [],
|
||||
emails = [],
|
||||
groups = [],
|
||||
results = [];
|
||||
groups = [];
|
||||
|
||||
if (r.users) {
|
||||
r.users.every(function (u) {
|
||||
if (!exclude.includes(u.username)) {
|
||||
users.push(u);
|
||||
results.push(u);
|
||||
r.users.forEach((user) => {
|
||||
if (results.length < options.limit && !exclude.includes(user.username)) {
|
||||
results.push(user);
|
||||
users.push(user);
|
||||
}
|
||||
return results.length <= limit;
|
||||
});
|
||||
}
|
||||
|
||||
if (options.allowEmails && emailValid(options.term)) {
|
||||
let e = { username: options.term };
|
||||
emails = [e];
|
||||
results.push(e);
|
||||
const result = { username: options.term };
|
||||
results.push(result);
|
||||
emails.push(result);
|
||||
}
|
||||
|
||||
if (r.groups) {
|
||||
r.groups.every(function (g) {
|
||||
r.groups.forEach((group) => {
|
||||
if (
|
||||
options.term.toLowerCase() === g.name.toLowerCase() ||
|
||||
results.length < limit
|
||||
(options.term.toLowerCase() === group.name.toLowerCase() ||
|
||||
results.length < options.limit) &&
|
||||
!exclude.includes(group.name)
|
||||
) {
|
||||
if (!exclude.includes(g.name)) {
|
||||
groups.push(g);
|
||||
results.push(g);
|
||||
}
|
||||
results.push(group);
|
||||
groups.push(group);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -277,7 +274,7 @@ export default function userSearch(options) {
|
|||
limit,
|
||||
function (r) {
|
||||
cancel(clearPromise);
|
||||
resolve(organizeResults(r, options));
|
||||
resolve(organizeResults(r, { ...options, limit }));
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -174,4 +174,9 @@ module("Unit | Utility | user-search", function (hooks) {
|
|||
});
|
||||
assert.strictEqual(results.length, 1);
|
||||
});
|
||||
|
||||
test("it uses limit option", async function (assert) {
|
||||
const results = await userSearch({ term: "te", limit: 2 });
|
||||
assert.strictEqual(results.length, 2);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue