-
Notifications
You must be signed in to change notification settings - Fork 11
chore: pending actions UI #704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,90 @@ | ||||||||||||||||||||||||||
| import type { WorkspaceEngine } from "@ctrlplane/workspace-engine-sdk"; | ||||||||||||||||||||||||||
| import { z } from "zod"; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import { getClientFor } from "@ctrlplane/workspace-engine-sdk"; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import { protectedProcedure, router } from "../trpc.js"; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const getOneReleaseTarget = async ( | ||||||||||||||||||||||||||
| workspaceId: string, | ||||||||||||||||||||||||||
| environmentId: string, | ||||||||||||||||||||||||||
| deploymentId: string, | ||||||||||||||||||||||||||
| ) => { | ||||||||||||||||||||||||||
| const response = await getClientFor(workspaceId).GET( | ||||||||||||||||||||||||||
| "/v1/workspaces/{workspaceId}/environments/{environmentId}/release-targets", | ||||||||||||||||||||||||||
| { params: { path: { workspaceId, environmentId } } }, | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
| return (response.data?.items ?? []).find( | ||||||||||||||||||||||||||
| (target) => target.deployment.id === deploymentId, | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const getDeploymentVersion = async ( | ||||||||||||||||||||||||||
| workspaceId: string, | ||||||||||||||||||||||||||
| deploymentVersionId: string, | ||||||||||||||||||||||||||
| ) => { | ||||||||||||||||||||||||||
| const response = await getClientFor(workspaceId).GET( | ||||||||||||||||||||||||||
| "/v1/workspaces/{workspaceId}/deploymentversions/{deploymentVersionId}", | ||||||||||||||||||||||||||
| { params: { path: { workspaceId, deploymentVersionId } } }, | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
| if (response.data == null) throw new Error("Deployment version not found"); | ||||||||||||||||||||||||||
| return response.data; | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const getPolicyResults = async ( | ||||||||||||||||||||||||||
| workspaceId: string, | ||||||||||||||||||||||||||
| releaseTarget: WorkspaceEngine["schemas"]["ReleaseTargetWithState"], | ||||||||||||||||||||||||||
| version: WorkspaceEngine["schemas"]["DeploymentVersion"], | ||||||||||||||||||||||||||
| ) => { | ||||||||||||||||||||||||||
| const decision = await getClientFor(workspaceId).POST( | ||||||||||||||||||||||||||
| "/v1/workspaces/{workspaceId}/release-targets/evaluate", | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| params: { path: { workspaceId } }, | ||||||||||||||||||||||||||
| body: { | ||||||||||||||||||||||||||
| releaseTarget: { | ||||||||||||||||||||||||||
| deploymentId: releaseTarget.deployment.id, | ||||||||||||||||||||||||||
| environmentId: releaseTarget.environment.id, | ||||||||||||||||||||||||||
| resourceId: releaseTarget.resource.id, | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| version, | ||||||||||||||||||||||||||
|
Comment on lines
+44
to
+49
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Evaluate payload uses wrong fields; sends undefined IDs. Build the releaseTarget for evaluation from - releaseTarget: {
- deploymentId: releaseTarget.deployment.id,
- environmentId: releaseTarget.environment.id,
- resourceId: releaseTarget.resource.id,
- },
+ releaseTarget: {
+ deploymentId: releaseTarget.releaseTarget.deploymentId,
+ environmentId: releaseTarget.releaseTarget.environmentId,
+ resourceId: releaseTarget.releaseTarget.resourceId,
+ },📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
| return decision.data?.versionDecision?.policyResults ?? []; | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const getEnvironmentScopedResults = ( | ||||||||||||||||||||||||||
| policyResults: WorkspaceEngine["schemas"]["DeployDecision"]["policyResults"], | ||||||||||||||||||||||||||
| ) => | ||||||||||||||||||||||||||
| policyResults.filter((result) => | ||||||||||||||||||||||||||
| result.ruleResults.some( | ||||||||||||||||||||||||||
| (rule) => rule.actionType === "approval" && !rule.allowed, | ||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| export const decisionsRouter = router({ | ||||||||||||||||||||||||||
| environmentVersion: protectedProcedure | ||||||||||||||||||||||||||
| .input( | ||||||||||||||||||||||||||
| z.object({ | ||||||||||||||||||||||||||
| workspaceId: z.uuid(), | ||||||||||||||||||||||||||
| environmentId: z.uuid(), | ||||||||||||||||||||||||||
| versionId: z.uuid(), | ||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| .query(async ({ input }) => { | ||||||||||||||||||||||||||
| const { workspaceId, environmentId, versionId } = input; | ||||||||||||||||||||||||||
| const version = await getDeploymentVersion(workspaceId, versionId); | ||||||||||||||||||||||||||
| const releaseTarget = await getOneReleaseTarget( | ||||||||||||||||||||||||||
| workspaceId, | ||||||||||||||||||||||||||
| environmentId, | ||||||||||||||||||||||||||
| version.deploymentId, | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
| if (releaseTarget == null) return []; | ||||||||||||||||||||||||||
| const policyResults = await getPolicyResults( | ||||||||||||||||||||||||||
| workspaceId, | ||||||||||||||||||||||||||
| releaseTarget, | ||||||||||||||||||||||||||
| version, | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
| return getEnvironmentScopedResults(policyResults); | ||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import type { WorkspaceEngine } from "@ctrlplane/workspace-engine-sdk"; | ||
| import { z } from "zod"; | ||
|
|
||
| import { Event, sendGoEvent } from "@ctrlplane/events"; | ||
|
|
||
| import { protectedProcedure, router } from "../trpc.js"; | ||
|
|
||
| export const deploymentVersionsRouter = router({ | ||
| approve: protectedProcedure | ||
| .input( | ||
| z.object({ | ||
| workspaceId: z.string().uuid(), | ||
| deploymentVersionId: z.string(), | ||
| environmentId: z.string(), | ||
| status: z.enum(["approved", "rejected"]).default("approved"), | ||
| }), | ||
| ) | ||
|
Comment on lines
+11
to
+17
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Authorization gap: don’t trust client‑supplied A malicious client could emit approvals to another workspace. Derive the workspace from server‑side state (e.g., fetch the version and use its workspace; or use a - .input(
+ .input(
z.object({
- workspaceId: z.string().uuid(),
- deploymentVersionId: z.string(),
- environmentId: z.string(),
+ // Remove workspaceId from client input
+ deploymentVersionId: z.string().uuid(),
+ environmentId: z.string().uuid(),
status: z.enum(["approved", "rejected"]).default("approved"),
}),
)
- .mutation(async ({ ctx, input }) => {
+ .mutation(async ({ ctx, input }) => {
const userId = ctx.session.user.id;
+ // Derive workspaceId securely (examples; pick one that fits your stack)
+ // const workspaceId = ctx.workspace.id;
+ // or: const { workspaceId } = await getDeploymentVersion(input.deploymentVersionId);
const record: WorkspaceEngine["schemas"]["UserApprovalRecord"] = {
userId,
versionId: input.deploymentVersionId,
environmentId: input.environmentId,
status: input.status,
createdAt: new Date().toISOString(),
};
- await sendGoEvent({
- workspaceId: input.workspaceId,
+ await sendGoEvent({
+ workspaceId, // derived server-side
eventType: Event.UserApprovalRecordCreated,
timestamp: Date.now(),
data: record,
});Also applies to: 29-34 🤖 Prompt for AI Agents |
||
| .mutation(async ({ ctx, input }) => { | ||
| const userId = ctx.session.user.id; | ||
|
|
||
| const record: WorkspaceEngine["schemas"]["UserApprovalRecord"] = { | ||
| userId, | ||
| versionId: input.deploymentVersionId, | ||
| environmentId: input.environmentId, | ||
| status: input.status, | ||
| createdAt: new Date().toISOString(), | ||
| }; | ||
|
|
||
| await sendGoEvent({ | ||
| workspaceId: input.workspaceId, | ||
| eventType: Event.UserApprovalRecordCreated, | ||
| timestamp: Date.now(), | ||
| data: record, | ||
| }); | ||
|
|
||
| return record; | ||
| }), | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Wrong property path; likely never matches any release target.
ReleaseTargetWithState elsewhere in the app exposes IDs under
releaseTarget.{deploymentId, environmentId, resourceId}. Matching ontarget.deployment.idwill fail.Apply:
📝 Committable suggestion
🤖 Prompt for AI Agents