mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
fix: Include results from users with accents in users.list query
This commit is contained in:
@@ -513,8 +513,6 @@ router.post(
|
||||
});
|
||||
authorize(actor, "read", document);
|
||||
|
||||
let users: User[] = [];
|
||||
let total = 0;
|
||||
let where: WhereOptions<User> = {
|
||||
teamId: document.teamId,
|
||||
suspendedAt: {
|
||||
@@ -553,15 +551,21 @@ router.post(
|
||||
...where,
|
||||
[Op.and]: [
|
||||
Sequelize.literal(
|
||||
`unaccent(LOWER(name)) like unaccent(LOWER('%${query}%'))`
|
||||
`unaccent(LOWER(name)) like unaccent(LOWER(:query))`
|
||||
),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
[users, total] = await Promise.all([
|
||||
User.findAll({ where, offset, limit }),
|
||||
User.count({ where }),
|
||||
const replacements = { query: `%${query}%` };
|
||||
|
||||
const [users, total] = await Promise.all([
|
||||
User.findAll({ where, replacements, offset, limit }),
|
||||
User.count({
|
||||
where,
|
||||
// @ts-expect-error Types are incorrect for count
|
||||
replacements,
|
||||
}),
|
||||
]);
|
||||
|
||||
ctx.body = {
|
||||
|
||||
@@ -20,7 +20,7 @@ afterAll(() => {
|
||||
describe("#users.list", () => {
|
||||
it("should allow filtering by user name", async () => {
|
||||
const user = await buildUser({
|
||||
name: "Tester",
|
||||
name: "Tèster",
|
||||
});
|
||||
// suspended user should not be returned
|
||||
await buildUser({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Router from "koa-router";
|
||||
import { Op, WhereOptions } from "sequelize";
|
||||
import { Op, Sequelize, WhereOptions } from "sequelize";
|
||||
import { UserPreference, UserRole } from "@shared/types";
|
||||
import { UserRoleHelper } from "@shared/utils/UserRoleHelper";
|
||||
import { UserValidation } from "@shared/validations";
|
||||
@@ -124,9 +124,11 @@ router.post(
|
||||
if (query) {
|
||||
where = {
|
||||
...where,
|
||||
name: {
|
||||
[Op.iLike]: `%${query}%`,
|
||||
},
|
||||
[Op.and]: [
|
||||
Sequelize.literal(
|
||||
`unaccent(LOWER(name)) like unaccent(LOWER(:query))`
|
||||
),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -144,15 +146,20 @@ router.post(
|
||||
};
|
||||
}
|
||||
|
||||
const replacements = { query: `%${query}%` };
|
||||
|
||||
const [users, total] = await Promise.all([
|
||||
User.findAll({
|
||||
where,
|
||||
replacements,
|
||||
order: [[sort, direction]],
|
||||
offset: ctx.state.pagination.offset,
|
||||
limit: ctx.state.pagination.limit,
|
||||
}),
|
||||
User.count({
|
||||
where,
|
||||
// @ts-expect-error Types are incorrect for count
|
||||
replacements,
|
||||
}),
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user