API : allow filter user list via emails (#6031)
This commit is contained in:
@@ -25,6 +25,8 @@ export const UsersListSchema = z.object({
|
|||||||
|
|
||||||
ids: z.array(z.string().uuid()).optional(),
|
ids: z.array(z.string().uuid()).optional(),
|
||||||
|
|
||||||
|
emails: z.array(z.string().email()).optional(),
|
||||||
|
|
||||||
query: z.string().optional(),
|
query: z.string().optional(),
|
||||||
|
|
||||||
filter: z
|
filter: z
|
||||||
|
|||||||
@@ -150,6 +150,23 @@ describe("#users.list", () => {
|
|||||||
expect(body.data[0].id).toEqual(user.id);
|
expect(body.data[0].id).toEqual(user.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should allow filtering by email", async () => {
|
||||||
|
const team = await buildTeam();
|
||||||
|
const admin = await buildAdmin({ teamId: team.id });
|
||||||
|
const user = await buildUser({ teamId: team.id });
|
||||||
|
|
||||||
|
const res = await server.post("/api/users.list", {
|
||||||
|
body: {
|
||||||
|
token: admin.getJwtToken(),
|
||||||
|
emails: [user.email],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const body = await res.json();
|
||||||
|
expect(res.status).toEqual(200);
|
||||||
|
expect(body.data.length).toEqual(1);
|
||||||
|
expect(body.data[0].id).toEqual(user.id);
|
||||||
|
});
|
||||||
|
|
||||||
it("should require admin for detailed info", async () => {
|
it("should require admin for detailed info", async () => {
|
||||||
const team = await buildTeam();
|
const team = await buildTeam();
|
||||||
await buildAdmin({ teamId: team.id });
|
await buildAdmin({ teamId: team.id });
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ router.post(
|
|||||||
pagination(),
|
pagination(),
|
||||||
validate(T.UsersListSchema),
|
validate(T.UsersListSchema),
|
||||||
async (ctx: APIContext<T.UsersListReq>) => {
|
async (ctx: APIContext<T.UsersListReq>) => {
|
||||||
const { sort, direction, query, filter, ids } = ctx.input.body;
|
const { sort, direction, query, filter, ids, emails } = ctx.input.body;
|
||||||
|
|
||||||
const actor = ctx.state.auth.user;
|
const actor = ctx.state.auth.user;
|
||||||
let where: WhereOptions<User> = {
|
let where: WhereOptions<User> = {
|
||||||
@@ -129,6 +129,13 @@ router.post(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (emails) {
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
email: emails,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const [users, total] = await Promise.all([
|
const [users, total] = await Promise.all([
|
||||||
User.findAll({
|
User.findAll({
|
||||||
where,
|
where,
|
||||||
|
|||||||
Reference in New Issue
Block a user