Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ext users from user selectors #859

Merged
merged 2 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions backend/src/components/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
5 changes: 4 additions & 1 deletion backend/src/router/user.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { getAllUsers } from '@backend/components/user';
import { getAllNonExtUsers, getAllUsers } from '@backend/components/user';
import { TRPC } from '@backend/router';

export const createUserRouter = (t: TRPC) =>
t.router({
getAll: t.procedure.query(async () => {
return await getAllUsers();
}),
getAllNonExt: t.procedure.query(async () => {
return await getAllNonExtUsers();
}),
});
2 changes: 1 addition & 1 deletion frontend/src/components/forms/UserSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/views/Project/Projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ function Toolbar() {
const newProjectMenuAnchor = useRef<HTMLButtonElement>(null);
return (
<Box css={toolbarContainerStyle}>
<Typography variant="h4">{tr('pages.projectsTitle')}</Typography>
<Typography variant="h4" component="h1">
{tr('pages.projectsTitle')}
</Typography>
<div>
<Button
ref={newProjectMenuAnchor}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/WorkTable/ProjectObjectUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function ProjectObjectUsers({ value }: { value: Value }) {
export function ProjectObjectUserEdit({ value, onChange }: Props) {
const tr = useTranslations();
const anchorElRef = useRef<HTMLDivElement>(null);
const users = trpc.user.getAll.useQuery();
const users = trpc.user.getAllNonExt.useQuery();
const [open, setOpen] = useState(false);

useEffect(() => {
Expand Down