⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(workflow-rule): only accept event types the integrations fire
Justin Willhiteac018f253424
diff --git a/apps/api/src/workflow-rule/response.ts b/apps/api/src/workflow-rule/response.tsindex 3a5f6bb48..4def92b63 100644--- a/apps/api/src/workflow-rule/response.ts+++ b/apps/api/src/workflow-rule/response.ts@@ -9,7 +9,7 @@ export const workflowRuleSchema = z}),eventType: z.string().openapi({description:- "The provider event that triggers the move, e.g. `pull_request.opened`.",+ "The Kaneo event that triggers the move: `branch_push`, `pr_opened`, `pr_merged`, `issue_opened`, `issue_closed` or `issue_reopened`.",}),columnId: z.string().openapi({description: "The column tasks are moved to when the event fires.",diff --git a/apps/api/src/workflow-rule/schema.ts b/apps/api/src/workflow-rule/schema.tsindex b315f8141..1b3729352 100644--- a/apps/api/src/workflow-rule/schema.ts+++ b/apps/api/src/workflow-rule/schema.ts@@ -4,8 +4,17 @@ export const projectIdParam = z.object({ projectId: z.string() });export const workflowRuleParam = z.object({ id: z.string() });+const workflowEventTypes = [+ "branch_push",+ "pr_opened",+ "pr_merged",+ "issue_opened",+ "issue_closed",+ "issue_reopened",+] as const;+export const upsertWorkflowRuleBody = z.object({integrationType: z.string(),- eventType: z.string(),+ eventType: z.enum(workflowEventTypes),columnId: z.string(),});diff --git a/apps/docs/openapi.json b/apps/docs/openapi.jsonindex c19555281..cd42a791a 100644--- a/apps/docs/openapi.json+++ b/apps/docs/openapi.json@@ -4179,7 +4179,7 @@},"eventType": {"type": "string",- "description": "The provider event that triggers the move, e.g. `pull_request.opened`."+ "description": "The Kaneo event that triggers the move: `branch_push`, `pr_opened`, `pr_merged`, `issue_opened`, `issue_closed` or `issue_reopened`."},"columnId": {"type": "string",@@ -20783,7 +20783,15 @@"type": "string"},"eventType": {- "type": "string"+ "type": "string",+ "enum": [+ "branch_push",+ "pr_opened",+ "pr_merged",+ "issue_opened",+ "issue_closed",+ "issue_reopened"+ ]},"columnId": {"type": "string"diff --git a/apps/web/src/fetchers/workflow-rule/upsert-workflow-rule.ts b/apps/web/src/fetchers/workflow-rule/upsert-workflow-rule.tsindex d6d1142f2..5e7b00998 100644--- a/apps/web/src/fetchers/workflow-rule/upsert-workflow-rule.ts+++ b/apps/web/src/fetchers/workflow-rule/upsert-workflow-rule.ts@@ -1,10 +1,12 @@import { client } from "@kaneo/libs";-+import type { InferRequestType } from "hono/client";import { HttpError } from "@/lib/http-error";async function upsertWorkflowRule(projectId: string,- data: { integrationType: string; eventType: string; columnId: string },+ data: InferRequestType<+ (typeof client)["workflow-rule"][":projectId"]["$put"]+ >["json"],) {const response = await client["workflow-rule"][":projectId"].$put({param: { projectId },diff --git a/apps/web/src/hooks/mutations/workflow-rule/use-upsert-workflow-rule.ts b/apps/web/src/hooks/mutations/workflow-rule/use-upsert-workflow-rule.tsindex c30956b68..e6a0de76a 100644--- a/apps/web/src/hooks/mutations/workflow-rule/use-upsert-workflow-rule.ts+++ b/apps/web/src/hooks/mutations/workflow-rule/use-upsert-workflow-rule.ts@@ -10,7 +10,7 @@ export function useUpsertWorkflowRule() {data,}: {projectId: string;- data: { integrationType: string; eventType: string; columnId: string };+ data: Parameters<typeof upsertWorkflowRule>[1];}) => upsertWorkflowRule(projectId, data),onSuccess: (_, variables) => {queryClient.invalidateQueries({diff --git a/tests/api-integration/workflow-rule-event-type.test.ts b/tests/api-integration/workflow-rule-event-type.test.tsnew file mode 100644index 000000000..5892dd595--- /dev/null+++ b/tests/api-integration/workflow-rule-event-type.test.ts@@ -0,0 +1,65 @@+import { eq } from "drizzle-orm";+import { beforeEach, describe, expect, it } from "vite-plus/test";+import db, { schema } from "../../apps/api/src/database";+import { mockAuthenticatedSession } from "./helpers/auth";+import { resetTestDatabase } from "./helpers/database";+import {+ createProjectFixture,+ createWorkspaceMember,+} from "./helpers/fixtures";+import { projectAccessApi } from "./helpers/project-access/project-access-api";++beforeEach(resetTestDatabase);++async function ownerProject() {+ const owner = await createWorkspaceMember({ role: "owner" });+ const fixture = await createProjectFixture({+ workspaceId: owner.workspace.id,+ });+ mockAuthenticatedSession(owner.user);+ return fixture;+}++function putRule(projectId: string, eventType: string, columnId: string) {+ return projectAccessApi()(`/workflow-rule/${projectId}`, {+ method: "PUT",+ body: {+ integrationType: "github",+ eventType,+ columnId,+ },+ });+}++describe("workflow rule event types", () => {+ it("rejects a provider event name and stores nothing", async () => {+ const { project, columns } = await ownerProject();++ const response = await putRule(+ project.id,+ "pull_request.opened",+ columns.inProgress.id,+ );++ expect(response.status).toBe(400);+ const rows = await db+ .select()+ .from(schema.workflowRuleTable)+ .where(eq(schema.workflowRuleTable.projectId, project.id));+ expect(rows).toHaveLength(0);+ });++ it("accepts a Kaneo event type", async () => {+ const { project, columns } = await ownerProject();++ const response = await putRule(+ project.id,+ "pr_opened",+ columns.inProgress.id,+ );++ expect(response.status).toBe(200);+ const body = (await response.json()) as { eventType: string };+ expect(body.eventType).toBe("pr_opened");+ });+});