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(api): hide deleted projects in move history

Andrej866c2f66ec46
diff --git a/apps/api/src/activity/redact-inaccessible-moves.ts b/apps/api/src/activity/redact-inaccessible-moves.ts
index 8e102821a..301838059 100644
--- a/apps/api/src/activity/redact-inaccessible-moves.ts
+++ b/apps/api/src/activity/redact-inaccessible-moves.ts
@@ -1,4 +1,6 @@
-import { findInaccessibleProjectIds } from "../project-access/find-inaccessible-project-ids";
+import { and, inArray } from "drizzle-orm";
+import db, { schema } from "../database";
+import { projectAccessCondition } from "../project-access/project-access-condition";
type MoveData = Record<string, unknown>;
@@ -29,9 +31,22 @@ export async function redactInaccessibleMoves<
)
: [];
});
- const hidden = new Set(
- await findInaccessibleProjectIds(viewerId, projectIds),
+ const referenced = [...new Set(projectIds)];
+ if (referenced.length === 0) return rows;
+ const visible = new Set(
+ (
+ await db
+ .select({ id: schema.projectTable.id })
+ .from(schema.projectTable)
+ .where(
+ and(
+ inArray(schema.projectTable.id, referenced),
+ projectAccessCondition(viewerId, schema.projectTable.id),
+ ),
+ )
+ ).map((project) => project.id),
);
+ const hidden = new Set(referenced.filter((id) => !visible.has(id)));
if (hidden.size === 0) return rows;
return rows.map((row) => {
diff --git a/tests/api-integration/project-access.test.ts b/tests/api-integration/project-access.test.ts
index e6cdf601a..baf977f4b 100644
--- a/tests/api-integration/project-access.test.ts
+++ b/tests/api-integration/project-access.test.ts
@@ -254,24 +254,33 @@ describe("project access enforcement", () => {
});
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",
+ const expectHiddenSource = () =>
+ vi.waitFor(async () => {
+ mockAuthenticatedSession(betaOnly);
+ 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",
+ });
});
+ await expectHiddenSource();
+
+ mockAuthenticatedSession(ctx.owner);
+ const deleted = await projectAccessApi()(`/project/${ctx.alpha.id}`, {
+ method: "DELETE",
});
+ expect(deleted.status).toBe(200);
+ await expectHiddenSource();
});
it("keeps tasks editable after their assignee loses access", async () => {