From e90b6e77df7ab861a93383ae0fc48593a53a5b32 Mon Sep 17 00:00:00 2001 From: Eric Allam Date: Fri, 4 Jul 2025 14:36:08 +0100 Subject: [PATCH] Properly scope the batch list to the selected environment Prevents showing batch runs from environments that are not in the selected environment --- .../v3/BatchListPresenter.server.ts | 23 ++++--------------- .../route.tsx | 2 +- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/apps/webapp/app/presenters/v3/BatchListPresenter.server.ts b/apps/webapp/app/presenters/v3/BatchListPresenter.server.ts index c223b2de803..a42f0aba077 100644 --- a/apps/webapp/app/presenters/v3/BatchListPresenter.server.ts +++ b/apps/webapp/app/presenters/v3/BatchListPresenter.server.ts @@ -9,10 +9,10 @@ import { timeFilters } from "~/components/runs/v3/SharedFilters"; export type BatchListOptions = { userId?: string; projectId: string; + environmentId: string; //filters friendlyId?: string; statuses?: BatchTaskRunStatus[]; - environments?: string[]; period?: string; from?: number; to?: number; @@ -34,7 +34,7 @@ export class BatchListPresenter extends BasePresenter { projectId, friendlyId, statuses, - environments, + environmentId, period, from, to, @@ -81,16 +81,6 @@ export class BatchListPresenter extends BasePresenter { }, }); - let environmentIds = project.environments.map((e) => e.id); - if (environments && environments.length > 0) { - //if environments are passed in, we only include them if they're in the project - environmentIds = environments.filter((e) => project.environments.some((pe) => pe.id === e)); - } - - if (environmentIds.length === 0) { - throw new Error("No matching environments found for the project"); - } - const periodMs = time.period ? parse(time.period) : undefined; //get the batches @@ -120,8 +110,8 @@ export class BatchListPresenter extends BasePresenter { FROM ${sqlDatabaseSchema}."BatchTaskRun" b WHERE - -- environments - b."runtimeEnvironmentId" IN (${Prisma.join(environmentIds)}) + -- environment + b."runtimeEnvironmentId" = ${environmentId} -- cursor ${ cursor @@ -186,9 +176,7 @@ WHERE if (!hasAnyBatches) { const firstBatch = await this._replica.batchTaskRun.findFirst({ where: { - runtimeEnvironmentId: { - in: environmentIds, - }, + runtimeEnvironmentId: environmentId, }, }); @@ -233,7 +221,6 @@ WHERE filters: { friendlyId, statuses: statuses || [], - environments: environments || [], }, hasFilters, hasAnyBatches, diff --git a/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.batches/route.tsx b/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.batches/route.tsx index 50c7b9a33dc..a78f3d2affc 100644 --- a/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.batches/route.tsx +++ b/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.batches/route.tsx @@ -78,7 +78,6 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => { const s = { cursor: url.searchParams.get("cursor") ?? undefined, direction: url.searchParams.get("direction") ?? undefined, - environments: [environment.id], statuses: url.searchParams.getAll("statuses"), period: url.searchParams.get("period") ?? undefined, from: url.searchParams.get("from") ?? undefined, @@ -93,6 +92,7 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => { projectId: project.id, ...filters, friendlyId: filters.id, + environmentId: environment.id, }); return typedjson(list);