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 live resources across concurrent moves and cleanup

Tin71e2a3e0aa36
diff --git a/apps/api/src/task/controllers/move-task.ts b/apps/api/src/task/controllers/move-task.ts
index cef6b89aa..962887194 100644
--- a/apps/api/src/task/controllers/move-task.ts
+++ b/apps/api/src/task/controllers/move-task.ts
@@ -1,10 +1,11 @@
-import { and, asc, eq, isNotNull } from "drizzle-orm";
+import { and, asc, eq, notInArray } from "drizzle-orm";
import { HTTPException } from "hono/http-exception";
import db from "../../database";
import {
assetTable,
columnTable,
externalLinkTable,
+ integrationTable,
projectTable,
taskTable,
} from "../../database/schema";
@@ -166,7 +167,13 @@ async function moveTask({
.where(
and(
eq(externalLinkTable.taskId, taskId),
- isNotNull(externalLinkTable.integrationId),
+ notInArray(
+ externalLinkTable.integrationId,
+ tx
+ .select({ id: integrationTable.id })
+ .from(integrationTable)
+ .where(eq(integrationTable.projectId, destinationProjectId)),
+ ),
),
);
diff --git a/tests/api-integration/integration-task-ownership.test.ts b/tests/api-integration/integration-task-ownership.test.ts
index efd76cd97..191d92b4b 100644
--- a/tests/api-integration/integration-task-ownership.test.ts
+++ b/tests/api-integration/integration-task-ownership.test.ts
@@ -357,3 +357,27 @@ it("reports a concurrent move as a conflict without deleting links", async () =>
).rejects.toMatchObject({ status: 409 });
expect(await db.query.externalLinkTable.findMany()).toHaveLength(1);
});
+
+it("preserves legacy links belonging to the destination integration when moving back", async () => {
+ const f = await setup();
+ const [destinationIntegration] = await db
+ .insert(schema.integrationTable)
+ .values({ projectId: f.destination.id, type: "gitea", config: "{}" })
+ .returning();
+ const [compatible] = await db
+ .insert(schema.externalLinkTable)
+ .values({
+ taskId: f.task.id,
+ integrationId: destinationIntegration.id,
+ resourceType: "issue",
+ externalId: "legacy",
+ url: "https://gitea.example/legacy",
+ })
+ .returning();
+ await moveTask({
+ taskId: f.task.id,
+ destinationProjectId: f.destination.id,
+ userId: f.source.user.id,
+ });
+ expect(await db.query.externalLinkTable.findMany()).toEqual([compatible]);
+});