Skip to content

Commit 47e583c

Browse files
authored
Properly scope the batch list to the selected environment (#2236)
Prevents showing batch runs from environments that are not in the selected environment
1 parent 1019c9c commit 47e583c

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

apps/webapp/app/presenters/v3/BatchListPresenter.server.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import { timeFilters } from "~/components/runs/v3/SharedFilters";
99
export type BatchListOptions = {
1010
userId?: string;
1111
projectId: string;
12+
environmentId: string;
1213
//filters
1314
friendlyId?: string;
1415
statuses?: BatchTaskRunStatus[];
15-
environments?: string[];
1616
period?: string;
1717
from?: number;
1818
to?: number;
@@ -34,7 +34,7 @@ export class BatchListPresenter extends BasePresenter {
3434
projectId,
3535
friendlyId,
3636
statuses,
37-
environments,
37+
environmentId,
3838
period,
3939
from,
4040
to,
@@ -81,16 +81,6 @@ export class BatchListPresenter extends BasePresenter {
8181
},
8282
});
8383

84-
let environmentIds = project.environments.map((e) => e.id);
85-
if (environments && environments.length > 0) {
86-
//if environments are passed in, we only include them if they're in the project
87-
environmentIds = environments.filter((e) => project.environments.some((pe) => pe.id === e));
88-
}
89-
90-
if (environmentIds.length === 0) {
91-
throw new Error("No matching environments found for the project");
92-
}
93-
9484
const periodMs = time.period ? parse(time.period) : undefined;
9585

9686
//get the batches
@@ -120,8 +110,8 @@ export class BatchListPresenter extends BasePresenter {
120110
FROM
121111
${sqlDatabaseSchema}."BatchTaskRun" b
122112
WHERE
123-
-- environments
124-
b."runtimeEnvironmentId" IN (${Prisma.join(environmentIds)})
113+
-- environment
114+
b."runtimeEnvironmentId" = ${environmentId}
125115
-- cursor
126116
${
127117
cursor
@@ -186,9 +176,7 @@ WHERE
186176
if (!hasAnyBatches) {
187177
const firstBatch = await this._replica.batchTaskRun.findFirst({
188178
where: {
189-
runtimeEnvironmentId: {
190-
in: environmentIds,
191-
},
179+
runtimeEnvironmentId: environmentId,
192180
},
193181
});
194182

@@ -233,7 +221,6 @@ WHERE
233221
filters: {
234222
friendlyId,
235223
statuses: statuses || [],
236-
environments: environments || [],
237224
},
238225
hasFilters,
239226
hasAnyBatches,

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.batches/route.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
7878
const s = {
7979
cursor: url.searchParams.get("cursor") ?? undefined,
8080
direction: url.searchParams.get("direction") ?? undefined,
81-
environments: [environment.id],
8281
statuses: url.searchParams.getAll("statuses"),
8382
period: url.searchParams.get("period") ?? undefined,
8483
from: url.searchParams.get("from") ?? undefined,
@@ -93,6 +92,7 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
9392
projectId: project.id,
9493
...filters,
9594
friendlyId: filters.id,
95+
environmentId: environment.id,
9696
});
9797

9898
return typedjson(list);

0 commit comments

Comments
 (0)