Skip to content

Commit 2103a73

Browse files
committed
Added allowedMasterQueues
1 parent 3526337 commit 2103a73

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class RegionsPresenter extends BasePresenter {
2222
id: true,
2323
organizationId: true,
2424
defaultWorkerGroupId: true,
25+
allowedMasterQueues: true,
2526
},
2627
where: {
2728
slug: projectSlug,
@@ -57,9 +58,15 @@ export class RegionsPresenter extends BasePresenter {
5758
location: true,
5859
staticIPs: true,
5960
},
60-
where: {
61-
hidden: false,
62-
},
61+
where:
62+
// Hide hidden unless they're allowed to use them
63+
project.allowedMasterQueues.length > 0
64+
? {
65+
masterQueue: { in: project.allowedMasterQueues },
66+
}
67+
: {
68+
hidden: false,
69+
},
6370
orderBy: {
6471
name: "asc",
6572
},

apps/webapp/app/v3/services/setDefaultRegion.server.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,30 @@ export class SetDefaultRegionService extends BaseService {
55
const workerGroup = await this._prisma.workerInstanceGroup.findFirst({
66
where: {
77
id: regionId,
8-
hidden: false,
98
},
109
});
1110

1211
if (!workerGroup) {
13-
throw new ServiceValidationError("Region not found or is hidden");
12+
throw new ServiceValidationError("Region not found");
13+
}
14+
15+
const project = await this._prisma.project.findFirst({
16+
where: {
17+
id: projectId,
18+
},
19+
});
20+
21+
if (!project) {
22+
throw new ServiceValidationError("Project not found");
23+
}
24+
25+
// If their project is restricted, only allow them to set default regions that are allowed
26+
if (project.allowedMasterQueues.length > 0) {
27+
if (!project.allowedMasterQueues.includes(workerGroup.masterQueue)) {
28+
throw new ServiceValidationError("You're not allowed to set this region as default");
29+
}
30+
} else if (workerGroup.hidden) {
31+
throw new ServiceValidationError("This region is not available to you");
1432
}
1533

1634
await this._prisma.project.update({
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "Project" ADD COLUMN "allowedMasterQueues" TEXT[] DEFAULT ARRAY[]::TEXT[];

internal-packages/database/prisma/schema.prisma

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ model Project {
335335
defaultWorkerGroup WorkerInstanceGroup? @relation("ProjectDefaultWorkerGroup", fields: [defaultWorkerGroupId], references: [id])
336336
defaultWorkerGroupId String?
337337
338+
/// The master queues they are allowed to use (impacts what they can set as default and trigger runs with)
339+
allowedMasterQueues String[] @default([])
340+
338341
environments RuntimeEnvironment[]
339342
backgroundWorkers BackgroundWorker[]
340343
backgroundWorkerTasks BackgroundWorkerTask[]

0 commit comments

Comments
 (0)