From 741d19c0e0b1a012810b856d37f6ae6de82ba160 Mon Sep 17 00:00:00 2001 From: Mikael Moilanen Date: Fri, 24 Nov 2023 15:13:19 +0200 Subject: [PATCH 1/2] Remove ext users from user selectors --- backend/src/components/user/index.ts | 9 +++++++++ backend/src/router/user.ts | 5 ++++- frontend/src/components/forms/UserSelect.tsx | 2 +- frontend/src/views/Project/Projects.tsx | 4 +++- frontend/src/views/WorkTable/ProjectObjectUsers.tsx | 2 +- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/backend/src/components/user/index.ts b/backend/src/components/user/index.ts index b2d9be37..49f77e5c 100644 --- a/backend/src/components/user/index.ts +++ b/backend/src/components/user/index.ts @@ -14,6 +14,15 @@ export async function getAllUsers() { return users; } +export async function getAllNonExtUsers() { + const users = await getPool().many(sql.type(userSchema)` + SELECT id, email, name FROM app.user + WHERE email NOT LIKE '%@ext.tampere.fi%' + ORDER BY name ASC + `); + return users; +} + export async function getUser(id: string) { return await getPool().one(sql.type(userSchema)` ${userSelectFragment} diff --git a/backend/src/router/user.ts b/backend/src/router/user.ts index a07eb39e..c42df5e8 100644 --- a/backend/src/router/user.ts +++ b/backend/src/router/user.ts @@ -1,4 +1,4 @@ -import { getAllUsers } from '@backend/components/user'; +import { getAllNonExtUsers, getAllUsers } from '@backend/components/user'; import { TRPC } from '@backend/router'; export const createUserRouter = (t: TRPC) => @@ -6,4 +6,7 @@ export const createUserRouter = (t: TRPC) => getAll: t.procedure.query(async () => { return await getAllUsers(); }), + getAllNonExt: t.procedure.query(async () => { + return await getAllNonExtUsers(); + }), }); diff --git a/frontend/src/components/forms/UserSelect.tsx b/frontend/src/components/forms/UserSelect.tsx index e18b7465..5869d880 100644 --- a/frontend/src/components/forms/UserSelect.tsx +++ b/frontend/src/components/forms/UserSelect.tsx @@ -27,7 +27,7 @@ type Props = { export function UserSelect(props: Props) { const { id, readOnly, onBlur, multiple, value, onChange, maxTags } = props; - const users = trpc.user.getAll.useQuery(); + const users = trpc.user.getAllNonExt.useQuery(); function getUser(userId: string) { return users.data?.find((user) => user.id === userId); diff --git a/frontend/src/views/Project/Projects.tsx b/frontend/src/views/Project/Projects.tsx index 8157a991..ff2ed44c 100644 --- a/frontend/src/views/Project/Projects.tsx +++ b/frontend/src/views/Project/Projects.tsx @@ -42,7 +42,9 @@ function Toolbar() { const newProjectMenuAnchor = useRef(null); return ( - {tr('pages.projectsTitle')} + + {tr('pages.projectsTitle')} +