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: address verified concurrency and migration review findings

Tinca29c96133f5
diff --git a/apps/api/src/task/controllers/move-task.ts b/apps/api/src/task/controllers/move-task.ts
index b38184c5d..cef6b89aa 100644
--- a/apps/api/src/task/controllers/move-task.ts
+++ b/apps/api/src/task/controllers/move-task.ts
@@ -156,8 +156,8 @@ async function moveTask({
.returning();
if (!updatedTask) {
- throw new HTTPException(500, {
- message: "Failed to move task",
+ throw new HTTPException(409, {
+ message: "Task was moved concurrently, please try again",
});
}
diff --git a/apps/api/src/task/index.ts b/apps/api/src/task/index.ts
index 53c2e04e9..cf40bbd3f 100644
--- a/apps/api/src/task/index.ts
+++ b/apps/api/src/task/index.ts
@@ -274,6 +274,7 @@ const moveTaskRoute = createRoute({
"No workspace access, or missing task:update permission",
),
404: errorResponse("Task or destination project not found"),
+ 409: errorResponse("Task or project moved concurrently; retry the move"),
},
});
diff --git a/apps/docs/openapi.json b/apps/docs/openapi.json
index b263bb917..7bd1e145f 100644
--- a/apps/docs/openapi.json
+++ b/apps/docs/openapi.json
@@ -9168,6 +9168,16 @@
}
}
}
+ },
+ "409": {
+ "description": "Task or project moved concurrently; retry the move",
+ "content": {
+ "text/plain": {
+ "schema": {
+ "type": "string"
+ }
+ }
+ }
}
}
}
diff --git a/apps/web/src/hooks/mutations/project/use-move-project.ts b/apps/web/src/hooks/mutations/project/use-move-project.ts
index aec9fe177..ea4283503 100644
--- a/apps/web/src/hooks/mutations/project/use-move-project.ts
+++ b/apps/web/src/hooks/mutations/project/use-move-project.ts
@@ -12,6 +12,7 @@ function useMoveProject() {
onSuccess: async (_data, { id }) => {
await Promise.all([
queryClient.invalidateQueries({ queryKey: ["projects"] }),
+ queryClient.invalidateQueries({ queryKey: ["external-links"] }),
queryClient.invalidateQueries({ queryKey: ["tasks", id] }),
]);
},
diff --git a/apps/web/src/hooks/use-project-websocket.ts b/apps/web/src/hooks/use-project-websocket.ts
index 57b73e88e..b6355f9a2 100644
--- a/apps/web/src/hooks/use-project-websocket.ts
+++ b/apps/web/src/hooks/use-project-websocket.ts
@@ -69,6 +69,7 @@ export function useProjectWebSocket(projectId: string) {
["tasks", projectId],
["task"],
["task-relations"],
+ ["external-links"],
]) {
queryClient.invalidateQueries({ queryKey });
}
diff --git a/tests/api-integration/integration-task-ownership.test.ts b/tests/api-integration/integration-task-ownership.test.ts
index 9d8f6fb2c..efd76cd97 100644
--- a/tests/api-integration/integration-task-ownership.test.ts
+++ b/tests/api-integration/integration-task-ownership.test.ts
@@ -1,6 +1,13 @@
import { eq } from "drizzle-orm";
-import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
-import db, { schema } from "../../apps/api/src/database";
+import {
+ afterEach,
+ beforeEach,
+ describe,
+ expect,
+ it,
+ vi,
+} from "vite-plus/test";
+import db, { getDatabase, schema } from "../../apps/api/src/database";
import { importGiteaIssues } from "../../apps/api/src/gitea-integration/controllers/import-gitea-issues";
import { importGitlabIssues } from "../../apps/api/src/gitlab-integration/controllers/import-gitlab-issues";
import { handleGiteaIssueEdited } from "../../apps/api/src/plugins/gitea/webhooks/issue-edited";
@@ -327,3 +334,26 @@ describe("integration task ownership", () => {
).toEqual([]);
});
});
+
+afterEach(() => vi.restoreAllMocks());
+it("reports a concurrent move as a conflict without deleting links", async () => {
+ const f = await setup();
+ const transaction = db.transaction.bind(db);
+ vi.spyOn(getDatabase(), "transaction").mockImplementationOnce(
+ async (apply, config) => {
+ await db
+ .update(schema.taskTable)
+ .set({ projectId: f.destination.id })
+ .where(eq(schema.taskTable.id, f.task.id));
+ return transaction(apply, config);
+ },
+ );
+ await expect(
+ moveTask({
+ taskId: f.task.id,
+ destinationProjectId: f.destination.id,
+ userId: f.source.user.id,
+ }),
+ ).rejects.toMatchObject({ status: 409 });
+ expect(await db.query.externalLinkTable.findMany()).toHaveLength(1);
+});