Skip to content

Commit 4ede32c

Browse files
committed
Impersonate a run automatically
Using /runs/run_abcdef automatically impersonates if an admin is logged in
1 parent 719a44d commit 4ede32c

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

apps/webapp/app/routes/runs.$runParam.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { z } from "zod";
33
import { prisma } from "~/db.server";
44
import { redirectWithErrorMessage } from "~/models/message.server";
55
import { requireUser } from "~/services/session.server";
6-
import { rootPath, v3RunPath } from "~/utils/pathBuilder";
6+
import { impersonate, rootPath, v3RunPath } from "~/utils/pathBuilder";
77

88
const ParamsSchema = z.object({
99
runParam: z.string(),
@@ -14,18 +14,22 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
1414

1515
const { runParam } = ParamsSchema.parse(params);
1616

17+
const isAdmin = user.admin || user.isImpersonating;
18+
1719
const run = await prisma.taskRun.findFirst({
1820
where: {
1921
friendlyId: runParam,
20-
project: {
21-
organization: {
22-
members: {
23-
some: {
24-
userId: user.id,
22+
...(!isAdmin && {
23+
project: {
24+
organization: {
25+
members: {
26+
some: {
27+
userId: user.id,
28+
},
2529
},
2630
},
2731
},
28-
},
32+
}),
2933
},
3034
select: {
3135
runtimeEnvironment: {
@@ -57,12 +61,12 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
5761
);
5862
}
5963

60-
return redirect(
61-
v3RunPath(
62-
{ slug: run.project.organization.slug },
63-
{ slug: run.project.slug },
64-
{ slug: run.runtimeEnvironment.slug },
65-
{ friendlyId: runParam }
66-
)
64+
const path = v3RunPath(
65+
{ slug: run.project.organization.slug },
66+
{ slug: run.project.slug },
67+
{ slug: run.runtimeEnvironment.slug },
68+
{ friendlyId: runParam }
6769
);
70+
71+
return redirect(isAdmin ? impersonate(path) : path);
6872
}

apps/webapp/app/utils/pathBuilder.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ export function rootPath() {
5656
return `/`;
5757
}
5858

59+
/** Given a path, it makes it an impersonation path */
60+
export function impersonate(path: string) {
61+
return `/@${path}`;
62+
}
63+
5964
export function accountPath() {
6065
return `/account`;
6166
}

0 commit comments

Comments
 (0)