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: resolve personal-work completion by column reference

Tin7f8e52ccfd32
diff --git a/apps/api/src/activity/controllers/get-workspace-activities.ts b/apps/api/src/activity/controllers/get-workspace-activities.ts
index 7f5f8f0c4..87ca6a9a1 100644
--- a/apps/api/src/activity/controllers/get-workspace-activities.ts
+++ b/apps/api/src/activity/controllers/get-workspace-activities.ts
@@ -1,4 +1,4 @@
-import { and, asc, desc, eq, gte, inArray, isNull, sql } from "drizzle-orm";
+import { and, desc, eq, gte, inArray, isNull, sql } from "drizzle-orm";
import db from "../../database";
import {
activityTable,
@@ -94,20 +94,18 @@ async function getWorkspaceActivities(workspaceId: string) {
inArray(columnTable.slug, statusSlugs),
),
)
- .orderBy(
- asc(columnTable.position),
- asc(columnTable.createdAt),
- asc(columnTable.id),
- )
: [];
return rows.map(({ content, ...row }) => {
const data =
row.type === "status_changed" ? statusData(row.eventData) : null;
- const nameOf = (slug: unknown) =>
- columns.find(
+ const nameOf = (slug: unknown) => {
+ const matching = columns.filter(
(column) => column.projectId === row.projectId && column.slug === slug,
- )?.name;
+ );
+ // Historical events only store slugs. Duplicates cannot identify a column.
+ return matching.length === 1 ? matching[0]?.name : undefined;
+ };
return {
...row,
eventData: data
diff --git a/apps/api/src/task/controllers/get-assigned-tasks.ts b/apps/api/src/task/controllers/get-assigned-tasks.ts
index 6ffc90f22..930003a7f 100644
--- a/apps/api/src/task/controllers/get-assigned-tasks.ts
+++ b/apps/api/src/task/controllers/get-assigned-tasks.ts
@@ -39,7 +39,11 @@ async function getAssignedTasks(
isNull(projectTable.archivedAt),
eq(taskTable.userId, userId),
ne(taskTable.status, "archived"),
- sql`not ${taskIsCompleted}`,
+ sql`not coalesce((
+ select ${columnTable.isFinal} from ${columnTable}
+ where ${columnTable.id} = ${taskTable.columnId}
+ and ${columnTable.projectId} = ${taskTable.projectId}
+ ), ${taskIsCompleted})`,
);
const totalsQuery = db
diff --git a/tests/api-integration/assigned-tasks.test.ts b/tests/api-integration/assigned-tasks.test.ts
index a350241e2..a849a4286 100644
--- a/tests/api-integration/assigned-tasks.test.ts
+++ b/tests/api-integration/assigned-tasks.test.ts
@@ -156,17 +156,21 @@ describe("API integration: assigned tasks", () => {
});
});
- it("returns each task once when existing columns share a slug", async () => {
+ it("uses column references when duplicate slugs include final columns", async () => {
const member = await createWorkspaceMember();
const { project, columns } = await createProjectFixture({
workspaceId: member.workspace.id,
});
- await db.insert(schema.columnTable).values({
- projectId: project.id,
- name: "Duplicate to-do",
- slug: columns.todo.slug,
- position: -1,
- });
+ const [finalColumn] = await db
+ .insert(schema.columnTable)
+ .values({
+ projectId: project.id,
+ name: "Duplicate to-do",
+ slug: columns.todo.slug,
+ position: -1,
+ isFinal: true,
+ })
+ .returning();
const [task] = await db
.insert(schema.taskTable)
.values({
@@ -177,8 +181,29 @@ describe("API integration: assigned tasks", () => {
userId: member.user.id,
})
.returning();
+ await db.insert(schema.taskTable).values([
+ {
+ projectId: project.id,
+ title: "In the final duplicate",
+ status: columns.todo.slug,
+ columnId: finalColumn.id,
+ userId: member.user.id,
+ number: 2,
+ },
+ {
+ projectId: project.id,
+ title: "Legacy ambiguous status",
+ status: columns.todo.slug,
+ userId: member.user.id,
+ number: 3,
+ },
+ ]);
mockAuthenticatedSession(member.user);
const { app } = createApp();
+ const countResponse = await app.request(
+ `/api/task/assigned?workspaceId=${member.workspace.id}&countOnly=true`,
+ );
+ expect(await countResponse.json()).toEqual({ tasks: [], total: 1 });
const response = await app.request(
`/api/task/assigned?workspaceId=${member.workspace.id}`,
);
diff --git a/tests/api-integration/workspace-activity.test.ts b/tests/api-integration/workspace-activity.test.ts
index 901881063..7b978caf8 100644
--- a/tests/api-integration/workspace-activity.test.ts
+++ b/tests/api-integration/workspace-activity.test.ts
@@ -197,4 +197,45 @@ describe("API integration: workspace activity", () => {
expect(invalid.status).toBe(400);
}
});
+ it("does not guess a historical column name when its status slug is ambiguous", async () => {
+ const member = await createWorkspaceMember();
+ const { project, columns } = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ });
+ await db.insert(schema.columnTable).values({
+ projectId: project.id,
+ slug: columns.todo.slug,
+ name: "Other queue",
+ position: -1,
+ });
+ const [task] = await db
+ .insert(schema.taskTable)
+ .values({
+ projectId: project.id,
+ title: "Historical status",
+ status: "in-progress",
+ columnId: columns.inProgress.id,
+ })
+ .returning();
+ await db.insert(schema.activityTable).values({
+ taskId: task.id,
+ type: "status_changed",
+ eventData: {
+ oldStatus: columns.todo.slug,
+ newStatus: columns.inProgress.slug,
+ },
+ });
+ mockAuthenticatedSession(member.user);
+ const { app } = createApp();
+ const response = await app.request(
+ `/api/activity/workspace/${member.workspace.id}`,
+ );
+ expect(response.status).toBe(200);
+ const [event] = await response.json();
+ expect(event.eventData).not.toHaveProperty("oldStatusName");
+ expect(event.eventData).toMatchObject({
+ oldStatus: "to-do",
+ newStatusName: "In Progress",
+ });
+ });
});