Skip to content

Commit dbca394

Browse files
committed
refactor(webapp): depend on the host RBAC controller surface
The API key policy methods are optional on the plugin-facing controller contract, so `Pick` over it yields optional members that these call sites would have to guard. Both already receive the LazyController singleton, which has substituted its fail-closed defaults, so point them at HostRbacController and keep the call sites guard-free.
1 parent 7cfeb4e commit dbca394

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

apps/webapp/app/models/api-key.server.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import type { PrismaClient, RuntimeEnvironment } from "@trigger.dev/database";
2-
import type { RoleBaseAccessController } from "@trigger.dev/rbac";
2+
// HostRbacController, not RoleBaseAccessController: the policy methods are
3+
// optional on the plugin-facing contract, and `rbac` (LazyController) has
4+
// already substituted the fail-closed defaults for any an installed plugin
5+
// omits. Depending on the host surface keeps this call site guard-free.
6+
import type { HostRbacController } from "@trigger.dev/rbac";
37
import { trail } from "agentcrumbs"; // @crumbs
48
import { customAlphabet } from "nanoid";
59
import { prisma } from "~/db.server";
@@ -128,7 +132,7 @@ export async function createEnvironmentApiKey(
128132
rbacController = rbac,
129133
}: {
130134
prismaClient?: Pick<PrismaClient, "runtimeEnvironment" | "taskIdentifier" | "apiKey">;
131-
rbacController?: Pick<RoleBaseAccessController, "prepareApiKeyPolicy">;
135+
rbacController?: Pick<HostRbacController, "prepareApiKeyPolicy">;
132136
} = {}
133137
) {
134138
const environment = await prismaClient.runtimeEnvironment.findFirst({

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { type RuntimeEnvironment } from "@trigger.dev/database";
2-
import { scopesGrantFullAccess, type RoleBaseAccessController } from "@trigger.dev/rbac";
2+
// HostRbacController, not RoleBaseAccessController: the policy methods are
3+
// optional on the plugin-facing contract, and `rbac` (LazyController) has
4+
// already substituted the fail-closed defaults for any an installed plugin
5+
// omits. Depending on the host surface keeps these call sites guard-free.
6+
import { scopesGrantFullAccess, type HostRbacController } from "@trigger.dev/rbac";
37
import { type PrismaReplicaClient, $replica } from "~/db.server";
48
import { type Project } from "~/models/project.server";
59
import { type User } from "~/models/user.server";
610
import { rbac } from "~/services/rbac.server";
711
import { obfuscateApiKey } from "~/utils/apiKeys";
812

9-
type ApiKeyPolicyPresenter = Pick<
10-
RoleBaseAccessController,
11-
"apiKeyPresets" | "describeApiKeyPolicy"
12-
>;
13+
type ApiKeyPolicyPresenter = Pick<HostRbacController, "apiKeyPresets" | "describeApiKeyPolicy">;
1314

1415
export class ApiKeysPresenter {
1516
// Read-only presenter for a dashboard page — all queries below are reads, so

0 commit comments

Comments
 (0)