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: hide inaccessible projects in move history

Andrej4e77eb052669
diff --git a/apps/api/src/activity/controllers/get-activities.ts b/apps/api/src/activity/controllers/get-activities.ts
index 712217eac..27c6533df 100644
--- a/apps/api/src/activity/controllers/get-activities.ts
+++ b/apps/api/src/activity/controllers/get-activities.ts
@@ -1,8 +1,13 @@
import { desc, eq } from "drizzle-orm";
import db from "../../database";
import { activityTable } from "../../database/schema";
+import { redactInaccessibleMoves } from "../redact-inaccessible-moves";
-async function getActivitiesFromTaskId(taskId: string, limit?: number) {
+async function getActivitiesFromTaskId(
+ taskId: string,
+ viewerId: string,
+ limit?: number,
+) {
const activities = await db.query.activityTable.findMany({
where: eq(activityTable.taskId, taskId),
orderBy: [desc(activityTable.createdAt), desc(activityTable.id)],
@@ -15,7 +20,7 @@ async function getActivitiesFromTaskId(taskId: string, limit?: number) {
}
});
- return activities;
+ return redactInaccessibleMoves(viewerId, activities);
}
export default getActivitiesFromTaskId;
diff --git a/apps/api/src/activity/controllers/get-workspace-activities.ts b/apps/api/src/activity/controllers/get-workspace-activities.ts
index 1a45a3b7e..2d66f83f2 100644
--- a/apps/api/src/activity/controllers/get-workspace-activities.ts
+++ b/apps/api/src/activity/controllers/get-workspace-activities.ts
@@ -1,5 +1,6 @@
import { and, desc, eq, gte, inArray, isNull, sql } from "drizzle-orm";
import db from "../../database";
+import { redactInaccessibleMoves } from "../redact-inaccessible-moves";
import {
activityTable,
columnTable,
@@ -98,7 +99,7 @@ async function getWorkspaceActivities(workspaceId: string, userId: string) {
)
: [];
- return rows.map(({ content, ...row }) => {
+ const activities = rows.map(({ content, ...row }) => {
const data =
row.type === "status_changed" ? statusData(row.eventData) : null;
const nameOf = (slug: unknown) => {
@@ -120,6 +121,7 @@ async function getWorkspaceActivities(workspaceId: string, userId: string) {
excerpt: commentExcerpt(content),
};
});
+ return redactInaccessibleMoves(userId, activities);
}
function statusData(value: unknown): Record<string, unknown> | null {
diff --git a/apps/api/src/activity/index.ts b/apps/api/src/activity/index.ts
index 1b122f2f9..39366f8e0 100644
--- a/apps/api/src/activity/index.ts
+++ b/apps/api/src/activity/index.ts
@@ -193,6 +193,7 @@ const activity = apiRouter()
c.json(
await getActivities(
c.req.valid("param").taskId,
+ c.get("userId"),
c.req.valid("query").limit,
),
200,
diff --git a/apps/api/src/activity/redact-inaccessible-moves.ts b/apps/api/src/activity/redact-inaccessible-moves.ts
new file mode 100644
index 000000000..8e102821a
--- /dev/null
+++ b/apps/api/src/activity/redact-inaccessible-moves.ts
@@ -0,0 +1,49 @@
+import { findInaccessibleProjectIds } from "../project-access/find-inaccessible-project-ids";
+
+type MoveData = Record<string, unknown>;
+
+function moveData(row: { type: string; eventData: unknown }) {
+ return row.type === "moved" &&
+ row.eventData &&
+ typeof row.eventData === "object" &&
+ !Array.isArray(row.eventData)
+ ? (row.eventData as MoveData)
+ : null;
+}
+
+function redactSide(data: MoveData, side: "from" | "to", hidden: Set<string>) {
+ const projectId = data[`${side}ProjectId`];
+ return typeof projectId === "string" && hidden.has(projectId)
+ ? { [`${side}ProjectId`]: null, [`${side}ProjectName`]: null }
+ : {};
+}
+
+export async function redactInaccessibleMoves<
+ T extends { type: string; eventData: unknown },
+>(viewerId: string, rows: T[]): Promise<T[]> {
+ const projectIds = rows.flatMap((row) => {
+ const data = moveData(row);
+ return data
+ ? [data.fromProjectId, data.toProjectId].filter(
+ (id): id is string => typeof id === "string",
+ )
+ : [];
+ });
+ const hidden = new Set(
+ await findInaccessibleProjectIds(viewerId, projectIds),
+ );
+ if (hidden.size === 0) return rows;
+
+ return rows.map((row) => {
+ const data = moveData(row);
+ if (!data) return row;
+ return {
+ ...row,
+ eventData: {
+ ...data,
+ ...redactSide(data, "from", hidden),
+ ...redactSide(data, "to", hidden),
+ },
+ };
+ });
+}
diff --git a/apps/web/src/components/activity/index.tsx b/apps/web/src/components/activity/index.tsx
index 2a61648f0..ab5f38b53 100644
--- a/apps/web/src/components/activity/index.tsx
+++ b/apps/web/src/components/activity/index.tsx
@@ -384,10 +384,14 @@ function renderActivityContent({
if (eventData) {
return (
<span className="text-sm text-muted-foreground">
- {t("activity:moved", {
- from: String(eventData.fromProjectName ?? ""),
- to: String(eventData.toProjectName ?? ""),
- })}
+ {eventData.fromProjectName
+ ? t("activity:moved", {
+ from: String(eventData.fromProjectName),
+ to: String(eventData.toProjectName ?? ""),
+ })
+ : t("activity:movedFromOtherProject", {
+ to: String(eventData.toProjectName ?? ""),
+ })}
</span>
);
}
diff --git a/apps/web/src/components/home/describe-activity.ts b/apps/web/src/components/home/describe-activity.ts
index 44e69f3e2..61baa864e 100644
--- a/apps/web/src/components/home/describe-activity.ts
+++ b/apps/web/src/components/home/describe-activity.ts
@@ -88,10 +88,14 @@ export function describeActivity(activity: WorkspaceActivity, t: Translate) {
break;
case "moved":
if (eventData) {
- return t("activity:moved", {
- from: String(eventData.fromProjectName ?? ""),
- to: String(eventData.toProjectName ?? ""),
- });
+ return eventData.fromProjectName
+ ? t("activity:moved", {
+ from: String(eventData.fromProjectName),
+ to: String(eventData.toProjectName ?? ""),
+ })
+ : t("activity:movedFromOtherProject", {
+ to: String(eventData.toProjectName ?? ""),
+ });
}
break;
default:
diff --git a/i18n/az-AZ.json b/i18n/az-AZ.json
index 334d56835..d0bf263ad 100644
--- a/i18n/az-AZ.json
+++ b/i18n/az-AZ.json
@@ -2237,7 +2237,8 @@
"importedFrom": "Imported from {{source}}",
"importedBy": "Imported by {{name}}",
"commentedOnForge": "{{forge}}-da şərh yazdı"
- }
+ },
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\""
},
"tasks": {
"title": "Tapşırıqlar",
diff --git a/i18n/de-DE.json b/i18n/de-DE.json
index f69cae657..1cf269d57 100644
--- a/i18n/de-DE.json
+++ b/i18n/de-DE.json
@@ -2237,7 +2237,8 @@
"importedFrom": "Importiert aus {{source}}",
"importedBy": "Importiert von {{name}}",
"commentedOnForge": "hat auf {{forge}} kommentiert"
- }
+ },
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\""
},
"tasks": {
"title": "Aufgaben",
diff --git a/i18n/el-GR.json b/i18n/el-GR.json
index 9037d308c..2ddabd692 100644
--- a/i18n/el-GR.json
+++ b/i18n/el-GR.json
@@ -2237,7 +2237,8 @@
"importedFrom": "Imported from {{source}}",
"importedBy": "Imported by {{name}}",
"commentedOnForge": "σχολίασε στο {{forge}}"
- }
+ },
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\""
},
"tasks": {
"title": "Εργασίες",
diff --git a/i18n/en-US.json b/i18n/en-US.json
index 8ebb3082f..e900f57de 100644
--- a/i18n/en-US.json
+++ b/i18n/en-US.json
@@ -2136,6 +2136,7 @@
"changedDueDate": "changed due date from {{from}} to {{to}}",
"changedTitle": "changed title from \"{{from}}\" to \"{{to}}\"",
"moved": "moved task from \"{{from}}\" to \"{{to}}\"",
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\"",
"created": "created this task",
"githubUser": "GitHub User",
"comment": {
diff --git a/i18n/es-ES.json b/i18n/es-ES.json
index fa425232b..f2a2fef1a 100644
--- a/i18n/es-ES.json
+++ b/i18n/es-ES.json
@@ -2249,7 +2249,8 @@
"importedFrom": "Imported from {{source}}",
"importedBy": "Imported by {{name}}",
"commentedOnForge": "comentado en {{forge}}"
- }
+ },
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\""
},
"tasks": {
"title": "Tareas",
diff --git a/i18n/fr-FR.json b/i18n/fr-FR.json
index b40740af1..cd6dbe515 100644
--- a/i18n/fr-FR.json
+++ b/i18n/fr-FR.json
@@ -2249,7 +2249,8 @@
"importedFrom": "Imported from {{source}}",
"importedBy": "Imported by {{name}}",
"commentedOnForge": "a commenté sur {{forge}}"
- }
+ },
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\""
},
"tasks": {
"title": "Tâches",
diff --git a/i18n/hi-IN.json b/i18n/hi-IN.json
index 284fc3fe7..5fd581d6e 100644
--- a/i18n/hi-IN.json
+++ b/i18n/hi-IN.json
@@ -2237,7 +2237,8 @@
"importedFrom": "Imported from {{source}}",
"importedBy": "Imported by {{name}}",
"commentedOnForge": "{{forge}} पर टिप्पणी की"
- }
+ },
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\""
},
"tasks": {
"title": "कार्य",
diff --git a/i18n/id-ID.json b/i18n/id-ID.json
index 404ff9356..92064ced3 100644
--- a/i18n/id-ID.json
+++ b/i18n/id-ID.json
@@ -2225,7 +2225,8 @@
"importedFrom": "Imported from {{source}}",
"importedBy": "Imported by {{name}}",
"commentedOnForge": "berkomentar di {{forge}}"
- }
+ },
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\""
},
"tasks": {
"title": "Tugas",
diff --git a/i18n/it-IT.json b/i18n/it-IT.json
index 57dc33768..247a92050 100644
--- a/i18n/it-IT.json
+++ b/i18n/it-IT.json
@@ -2249,7 +2249,8 @@
"importedFrom": "Imported from {{source}}",
"importedBy": "Imported by {{name}}",
"commentedOnForge": "ha commentato su {{forge}}"
- }
+ },
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\""
},
"tasks": {
"title": "Attività",
diff --git a/i18n/ja-JP.json b/i18n/ja-JP.json
index 8ea5f4a92..0d0f3aedd 100644
--- a/i18n/ja-JP.json
+++ b/i18n/ja-JP.json
@@ -2225,7 +2225,8 @@
"importedFrom": "Imported from {{source}}",
"importedBy": "Imported by {{name}}",
"commentedOnForge": "{{forge}} でコメント"
- }
+ },
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\""
},
"tasks": {
"title": "タスク",
diff --git a/i18n/ko-KR.json b/i18n/ko-KR.json
index c5d6443d3..c8ea2d035 100644
--- a/i18n/ko-KR.json
+++ b/i18n/ko-KR.json
@@ -2225,7 +2225,8 @@
"importedFrom": "Imported from {{source}}",
"importedBy": "Imported by {{name}}",
"commentedOnForge": "{{forge}}에 댓글을 남김"
- }
+ },
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\""
},
"tasks": {
"title": "작업",
diff --git a/i18n/mk-MK.json b/i18n/mk-MK.json
index 85cbf2934..7117f5e8d 100644
--- a/i18n/mk-MK.json
+++ b/i18n/mk-MK.json
@@ -2237,7 +2237,8 @@
"importedFrom": "Imported from {{source}}",
"importedBy": "Imported by {{name}}",
"commentedOnForge": "коментираше на {{forge}}"
- }
+ },
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\""
},
"tasks": {
"title": "Задачи",
diff --git a/i18n/nl-NL.json b/i18n/nl-NL.json
index 42e429bbb..a67f0ee6e 100644
--- a/i18n/nl-NL.json
+++ b/i18n/nl-NL.json
@@ -2237,7 +2237,8 @@
"importedFrom": "Imported from {{source}}",
"importedBy": "Imported by {{name}}",
"commentedOnForge": "heeft gereageerd op {{forge}}"
- }
+ },
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\""
},
"tasks": {
"title": "Taken",
diff --git a/i18n/pl-PL.json b/i18n/pl-PL.json
index 9618c0c0f..a2525fd47 100644
--- a/i18n/pl-PL.json
+++ b/i18n/pl-PL.json
@@ -1010,7 +1010,8 @@
"githubUser": "Użytkownik GitHub",
"moved": "przeniósł(ęła) zadanie z \"{{from}}\" do \"{{to}}\"",
"setDueDate": "ustawił(a) termin na {{date}}",
- "unassigned": "usunął(ęła) przypisanie zadania"
+ "unassigned": "usunął(ęła) przypisanie zadania",
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\""
},
"settings": {
"advancedSettings": "Ustawienia zaawansowane",
diff --git a/i18n/pt-BR.json b/i18n/pt-BR.json
index feb27130e..bef110dd9 100644
--- a/i18n/pt-BR.json
+++ b/i18n/pt-BR.json
@@ -2249,7 +2249,8 @@
"importedFrom": "Imported from {{source}}",
"importedBy": "Imported by {{name}}",
"commentedOnForge": "comentou no {{forge}}"
- }
+ },
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\""
},
"tasks": {
"title": "Tarefas",
diff --git a/i18n/ru-RU.json b/i18n/ru-RU.json
index d8b441b84..207fcd909 100644
--- a/i18n/ru-RU.json
+++ b/i18n/ru-RU.json
@@ -2269,7 +2269,8 @@
"commentedOnForge": "прокомментировал на {{forge}}"
},
"moved": "переместил задачу из «{{from}}» в «{{to}}»",
- "created": "создал эту задачу"
+ "created": "создал эту задачу",
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\""
},
"tasks": {
"title": "Задачи",
diff --git a/i18n/tr-TR.json b/i18n/tr-TR.json
index f9c76aa00..7fd918345 100644
--- a/i18n/tr-TR.json
+++ b/i18n/tr-TR.json
@@ -2237,7 +2237,8 @@
"importedFrom": "Imported from {{source}}",
"importedBy": "Imported by {{name}}",
"commentedOnForge": "{{forge}}'da yorum yaptı"
- }
+ },
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\""
},
"tasks": {
"title": "Görevler",
diff --git a/i18n/uk-UA.json b/i18n/uk-UA.json
index 3042e52f7..47a4d06fc 100644
--- a/i18n/uk-UA.json
+++ b/i18n/uk-UA.json
@@ -2261,7 +2261,8 @@
"commentedOnForge": "прокоментував на {{forge}}"
},
"moved": "перемістив завдання з «{{from}}» до «{{to}}»",
- "created": "створив це завдання"
+ "created": "створив це завдання",
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\""
},
"tasks": {
"title": "Завдання",
diff --git a/i18n/vi-VN.json b/i18n/vi-VN.json
index 0fb38d3ed..72e67b8d9 100644
--- a/i18n/vi-VN.json
+++ b/i18n/vi-VN.json
@@ -2225,7 +2225,8 @@
"importedFrom": "Imported from {{source}}",
"importedBy": "Imported by {{name}}",
"commentedOnForge": "đã bình luận trên {{forge}}"
- }
+ },
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\""
},
"tasks": {
"title": "Nhiệm vụ",
diff --git a/i18n/zh-CN.json b/i18n/zh-CN.json
index 6cd3e242a..becc7b4d1 100644
--- a/i18n/zh-CN.json
+++ b/i18n/zh-CN.json
@@ -2225,7 +2225,8 @@
"importedFrom": "从 {{source}} 导入",
"importedBy": "由 {{name}} 导入",
"commentedOnForge": "在 {{forge}} 上评论"
- }
+ },
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\""
},
"tasks": {
"title": "任务",
diff --git a/i18n/zh-TW.json b/i18n/zh-TW.json
index 9ef98ecaa..4144049a9 100644
--- a/i18n/zh-TW.json
+++ b/i18n/zh-TW.json
@@ -2225,7 +2225,8 @@
"importedFrom": "匯入自 {{source}}",
"importedBy": "由 {{name}} 匯入",
"commentedOnForge": "在 {{forge}} 上留言"
- }
+ },
+ "movedFromOtherProject": "moved task from another project to \"{{to}}\""
},
"tasks": {
"title": "任務",
diff --git a/tests/api-integration/project-access.test.ts b/tests/api-integration/project-access.test.ts
index 24a80d239..e6cdf601a 100644
--- a/tests/api-integration/project-access.test.ts
+++ b/tests/api-integration/project-access.test.ts
@@ -1,12 +1,13 @@
import { createHash, randomUUID } from "node:crypto";
import { eq } from "drizzle-orm";
-import { beforeEach, describe, expect, it } from "vite-plus/test";
+import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
import db, { schema } from "../../apps/api/src/database";
import { mockAnonymousSession, mockAuthenticatedSession } from "./helpers/auth";
import { resetTestDatabase } from "./helpers/database";
import { addWorkspaceMember } from "./helpers/project-access/add-workspace-member";
import { createRestrictedWorkspace } from "./helpers/project-access/create-restricted-workspace";
import { projectAccessApi } from "./helpers/project-access/project-access-api";
+import { restrictToProjects } from "./helpers/project-access/restrict-to-projects";
beforeEach(resetTestDatabase);
@@ -242,6 +243,37 @@ describe("project access enforcement", () => {
expect(task?.userId).toBeNull();
});
+ it("hides the source project of a move from members who can't see it", async () => {
+ const ctx = await createRestrictedWorkspace();
+ const betaOnly = await addWorkspaceMember(ctx.workspace.id);
+ await restrictToProjects(ctx.workspace.id, betaOnly.id, [ctx.beta.id]);
+ mockAuthenticatedSession(ctx.owner);
+ const moved = await projectAccessApi()(`/task/move/${ctx.alphaTask.id}`, {
+ method: "PUT",
+ body: { destinationProjectId: ctx.beta.id },
+ });
+ expect(moved.status).toBe(200);
+
+ mockAuthenticatedSession(betaOnly);
+ await vi.waitFor(async () => {
+ const response = await projectAccessApi()(
+ `/activity/${ctx.alphaTask.id}`,
+ );
+ const activities = (await response.json()) as {
+ type: string;
+ eventData: Record<string, unknown> | null;
+ }[];
+ expect(
+ activities.find((activity) => activity.type === "moved")?.eventData,
+ ).toMatchObject({
+ fromProjectId: null,
+ fromProjectName: null,
+ toProjectId: ctx.beta.id,
+ toProjectName: "Beta",
+ });
+ });
+ });
+
it("keeps tasks editable after their assignee loses access", async () => {
const ctx = await createRestrictedWorkspace();
mockAuthenticatedSession(ctx.owner);