-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy path@.runs.$runParam.ts
More file actions
67 lines (58 loc) · 1.52 KB
/
@.runs.$runParam.ts
File metadata and controls
67 lines (58 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { redirect, type LoaderFunctionArgs } from "@remix-run/server-runtime";
import { z } from "zod";
import { prisma } from "~/db.server";
import { redirectWithErrorMessage } from "~/models/message.server";
import { requireUser } from "~/services/session.server";
import { impersonate, rootPath, v3RunPath } from "~/utils/pathBuilder";
const ParamsSchema = z.object({
runParam: z.string(),
});
export async function loader({ params, request }: LoaderFunctionArgs) {
const user = await requireUser(request);
const { runParam } = ParamsSchema.parse(params);
const isAdmin = user.admin || user.isImpersonating;
if (!isAdmin) {
return redirectWithErrorMessage(
rootPath(),
request,
"You're not an admin and cannot impersonate",
{
ephemeral: false,
}
);
}
const run = await prisma.taskRun.findFirst({
where: {
friendlyId: runParam,
},
select: {
runtimeEnvironment: {
select: {
slug: true,
},
},
project: {
select: {
slug: true,
organization: {
select: {
slug: true,
},
},
},
},
},
});
if (!run) {
return redirectWithErrorMessage(rootPath(), request, "Run doesn't exist", {
ephemeral: false,
});
}
const path = v3RunPath(
{ slug: run.project.organization.slug },
{ slug: run.project.slug },
{ slug: run.runtimeEnvironment.slug },
{ friendlyId: runParam }
);
return redirect(impersonate(path));
}