Skip to content

Commit 31261db

Browse files
committed
refactor: Remove earlier handling of personal API tokens
As the API tokens won't be personal tokens anymore, remove the logic to add and edit them. Signed-off-by: Johanna Lamppu <johanna.lamppu@doubleopen.org>
1 parent 952fc39 commit 31261db

13 files changed

Lines changed: 7 additions & 629 deletions

File tree

apps/api/src/helpers/keycloak_queries.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ export const createUser = async (data: {
155155
value: string;
156156
temporary: boolean;
157157
}[];
158-
attributes: {
159-
dosApiToken: string;
160-
};
161158
enabled?: boolean;
162159
firstName?: string;
163160
lastName?: string;
@@ -221,7 +218,7 @@ export const createUser = async (data: {
221218
}
222219
}
223220

224-
const user = (await getUsers(data.username, undefined, true))[0];
221+
const user = (await getUsers(data.username, true))[0];
225222

226223
if (!user) {
227224
throw new CustomError("Failed to create user. User not found", 500);
@@ -407,7 +404,6 @@ export const addRealmRolesToUser = async (
407404

408405
export const getUsers = async (
409406
username?: string,
410-
dosApiToken?: string,
411407
exact?: boolean,
412408
): Promise<User[]> => {
413409
let retries = 3;
@@ -423,7 +419,6 @@ export const getUsers = async (
423419
queries: {
424420
username: username,
425421
exact: exact,
426-
q: dosApiToken ? "dosApiToken:" + dosApiToken : undefined,
427422
},
428423
headers: {
429424
Authorization: "Bearer " + token.access_token,
@@ -477,9 +472,6 @@ export const updateUser = async (
477472
temporary: boolean;
478473
}[];
479474
realmRoles?: string[];
480-
attributes?: {
481-
dosApiToken?: string;
482-
};
483475
enabled?: boolean;
484476
firstName?: string;
485477
lastName?: string;

apps/api/src/routes/admin_router.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//
33
// SPDX-License-Identifier: MIT
44

5-
import crypto from "crypto";
65
import { zodiosRouter } from "@zodios/express";
76
import { Prisma } from "database";
87
import { adminAPI } from "validation-helpers";
@@ -38,8 +37,6 @@ adminRouter.post(
3837
const role = req.body.role ? req.body.role : "USER";
3938
const realmRoles =
4039
role === "USER" ? ["app-user"] : ["app-user", "app-admin"];
41-
const dosApiToken =
42-
req.body.dosApiToken || crypto.randomBytes(16).toString("hex");
4340

4441
const newUser = await createUser({
4542
username,
@@ -53,9 +50,6 @@ adminRouter.post(
5350
: true,
5451
},
5552
],
56-
attributes: {
57-
dosApiToken: dosApiToken,
58-
},
5953
enabled: true,
6054
firstName: req.body.firstName,
6155
lastName: req.body.lastName,
@@ -68,7 +62,6 @@ adminRouter.post(
6862
res.status(200).send({
6963
id: newUser.id,
7064
username: newUser.username,
71-
dosApiToken: dosApiToken,
7265
realmRoles: realmRoles,
7366
firstName: newUser.firstName,
7467
lastName: newUser.lastName,

apps/api/src/routes/user_router.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//
33
// SPDX-License-Identifier: MIT
44

5-
import crypto from "crypto";
65
import { zodiosRouter } from "@zodios/express";
76
import { Package, Prisma } from "database";
87
import { getPresignedGetUrl } from "s3-helpers";
@@ -58,31 +57,11 @@ userRouter.put("/user", async (req, res) => {
5857
}
5958
});
6059

61-
userRouter.put("/token", async (req, res) => {
62-
try {
63-
const token = crypto.randomBytes(16).toString("hex");
64-
65-
// Update user token
66-
await updateUser(req.kauth.grant.access_token.content.sub, {
67-
username: req.kauth.grant.access_token.content.preferred_username,
68-
email: req.kauth.grant.access_token.content.email,
69-
firstName: req.kauth.grant.access_token.content.given_name,
70-
lastName: req.kauth.grant.access_token.content.family_name,
71-
attributes: { dosApiToken: token },
72-
});
73-
74-
res.status(200).json({ token: token });
75-
} catch (error) {
76-
console.log("Error: ", error);
77-
res.status(500).json({ message: "Internal server error" });
78-
}
79-
});
80-
8160
const getUserIdArray = async (username: string, usernameStrict?: boolean) => {
8261
let userIds: string[] = [];
8362

8463
if (usernameStrict) {
85-
const matchingUsers = await getUsers(username, undefined, true);
64+
const matchingUsers = await getUsers(username, true);
8665
if (matchingUsers.length === 1) userIds = [matchingUsers[0].id];
8766
else if (matchingUsers.length > 1)
8867
throw new CustomError(

apps/clearance_ui/src/components/navigation/UserMenuItem.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// SPDX-License-Identifier: MIT
44

55
import { useQueryClient } from "@tanstack/react-query";
6-
import { KeyRound, LogOut, UserRound, UsersRound } from "lucide-react";
6+
import { LogOut, UserRound, UsersRound } from "lucide-react";
77
import { signIn, signOut } from "next-auth/react";
88
import Link from "next/link";
99
import { GrLogin } from "react-icons/gr";
@@ -85,15 +85,6 @@ const UserMenuItem = ({ className }: UserMenuItemProps) => {
8585
<span>Profile</span>
8686
</Link>
8787
</DropdownMenuItem>
88-
<DropdownMenuItem>
89-
<Link
90-
href="/settings?section=tokens"
91-
className="w-full"
92-
>
93-
<KeyRound className="mr-2 inline-block h-4 w-4" />
94-
<span>Tokens</span>
95-
</Link>
96-
</DropdownMenuItem>
9788
</DropdownMenuGroup>
9889
{user.permissions &&
9990
hasPermission(user.permissions, "Users", "POST") && (

apps/clearance_ui/src/components/user_management/AddUserForm.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ const addUserFormSchema = z.object({
4444
firstName: z.string().optional(),
4545
lastName: z.string().optional(),
4646
email: z.string().email().optional(),
47-
dosApiToken: z.string().optional(),
4847
});
4948

5049
type AddUserDataType = z.infer<typeof addUserFormSchema>;
@@ -56,7 +55,6 @@ type AddUserFormProps = {
5655
username: string;
5756
password: string;
5857
realmRoles: string[];
59-
dosApiToken?: string;
6058
firstName?: string;
6159
lastName?: string;
6260
email?: string;
@@ -79,7 +77,6 @@ const AddUserForm = ({ onNewUserCreated }: AddUserFormProps) => {
7977
username: data.username,
8078
password: form.getValues("password"),
8179
realmRoles: data.realmRoles,
82-
dosApiToken: data.dosApiToken,
8380
firstName: data.firstName,
8481
lastName: data.lastName,
8582
email: data.email,

apps/clearance_ui/src/components/user_management/TokenDialog.tsx

Lines changed: 0 additions & 106 deletions
This file was deleted.

apps/clearance_ui/src/pages/settings/index.tsx

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import { Loader2 } from "lucide-react";
66
import { useUser } from "@/hooks/useUser";
77
import MultiSection from "@/components/common/MultiSection";
8-
import TokenDialog from "@/components/user_management/TokenDialog";
98
import UserDataForm from "@/components/user_management/UserDataForm";
109

1110
export default function Settings() {
@@ -17,22 +16,6 @@ export default function Settings() {
1716
return <UserDataForm />;
1817
}
1918

20-
function Tokens() {
21-
return (
22-
<>
23-
<p className="pt-4">
24-
Here you can create a token you will need for running ORT
25-
with DOS Scanner, or to use the scanner via the API.
26-
</p>
27-
<p className="pt-4 pb-8">
28-
Please note that your previous token will be invalidated
29-
when you create a new one.
30-
</p>
31-
<TokenDialog />
32-
</>
33-
);
34-
}
35-
3619
return (
3720
<>
3821
{user ? (
@@ -46,12 +29,6 @@ export default function Settings() {
4629
href: "/settings?section=profile",
4730
content: Profile,
4831
},
49-
{
50-
title: "Tokens",
51-
tag: "tokens",
52-
href: "/settings?section=tokens",
53-
content: Tokens,
54-
},
5532
]}
5633
/>
5734
) : (

0 commit comments

Comments
 (0)