Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix: preserve bulk task validation responses

ShiroKSHa2a767252492
diff --git a/apps/api/src/utils/workspace-access-middleware.ts b/apps/api/src/utils/workspace-access-middleware.ts
index 186e5c34f..631ead501 100644
--- a/apps/api/src/utils/workspace-access-middleware.ts
+++ b/apps/api/src/utils/workspace-access-middleware.ts
@@ -90,7 +90,15 @@ export function workspaceAccessMiddleware(
const workspaceIds = [
...new Set(tasks.map((task) => task.workspaceId)),
];
- workspaceId = workspaceIds.length === 1 ? workspaceIds[0] : null;
+ if (workspaceIds.length === 0) {
+ throw new HTTPException(404, { message: "No tasks found" });
+ }
+ if (workspaceIds.length > 1) {
+ throw new HTTPException(400, {
+ message: "All tasks must belong to the same workspace",
+ });
+ }
+ workspaceId = workspaceIds[0];
}
}
}
diff --git a/tests/api-integration/workspace-rbac.test.ts b/tests/api-integration/workspace-rbac.test.ts
index 513d94ca3..77abb15fa 100644
--- a/tests/api-integration/workspace-rbac.test.ts
+++ b/tests/api-integration/workspace-rbac.test.ts
@@ -1,5 +1,5 @@
import { randomUUID } from "node:crypto";
-import { and, eq } from "drizzle-orm";
+import { and, eq, inArray } from "drizzle-orm";
import { beforeEach, describe, expect, it } from "vitest";
import db, { schema } from "../../apps/api/src/database";
import { createApp } from "../../apps/api/src/index";
@@ -277,6 +277,62 @@ describe("API integration: workspace RBAC enforcement", () => {
expect(persisted?.priority).toBe("high");
});
+ it("preserves the not-found response for unknown tasks", async () => {
+ const member = await createWorkspaceMember({ role: "member" });
+
+ mockAuthenticatedSession(member.user);
+ const { app } = createApp();
+
+ const response = await app.request("/api/task/bulk", {
+ method: "PATCH",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({
+ taskIds: [randomUUID()],
+ operation: "updatePriority",
+ value: "high",
+ }),
+ });
+ expect(response.status).toBe(404);
+ });
+
+ it("rejects bulk mutations that span workspaces", async () => {
+ const member = await createWorkspaceMember({ role: "member" });
+ const foreign = await createWorkspaceMember({ role: "admin" });
+ const { project, columns } = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ });
+ const { project: foreignProject, columns: foreignColumns } =
+ await createProjectFixture({ workspaceId: foreign.workspace.id });
+ const task = await seedTask(project.id, columns.todo.id);
+ const foreignTask = await seedTask(
+ foreignProject.id,
+ foreignColumns.todo.id,
+ );
+
+ mockAuthenticatedSession(member.user);
+ const { app } = createApp();
+
+ const response = await app.request("/api/task/bulk", {
+ method: "PATCH",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({
+ taskIds: [task.id, foreignTask.id],
+ operation: "updatePriority",
+ value: "high",
+ }),
+ });
+ expect(response.status).toBe(400);
+
+ const persistedTasks = await db
+ .select({ priority: schema.taskTable.priority })
+ .from(schema.taskTable)
+ .where(inArray(schema.taskTable.id, [task.id, foreignTask.id]));
+ expect(persistedTasks).toHaveLength(2);
+ expect(persistedTasks.every((task) => task.priority === "medium")).toBe(
+ true,
+ );
+ });
+
it("blocks a member from deleting a task in bulk", async () => {
const member = await createWorkspaceMember({ role: "member" });
const { project, columns } = await createProjectFixture({