Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

fix(api): let only the creator delete a note board (#348)

Egor Vasilyev5edd3b4e3b33
diff --git a/apps/api/src/modules/note-boards/__tests__/integration/note-boards.test.ts b/apps/api/src/modules/note-boards/__tests__/integration/note-boards.test.ts
index 80fed490..ef638ed7 100644
--- a/apps/api/src/modules/note-boards/__tests__/integration/note-boards.test.ts
+++ b/apps/api/src/modules/note-boards/__tests__/integration/note-boards.test.ts
@@ -285,6 +285,79 @@ describe('note boards', () => {
});
});
+ describe('delete', () => {
+ it('lets the creator delete their board', async () => {
+ const owner = await setupOwnerProject();
+ const boardId = (await boards(owner.api).post({ name: 'Ideas' })).data!.id;
+
+ expect((await boards(owner.api)({ boardId }).delete()).status).toBe(204);
+ expect((await boards(owner.api)({ boardId }).get()).status).toBe(404);
+ });
+
+ it('keeps a granted member from deleting a board shared with them', async () => {
+ const owner = await setupOwnerProject();
+ const author = await addMember(owner.api);
+ const granted = await addMember(owner.api);
+ const boardId = (await boards(author.api).post({ name: 'Ideas' })).data!.id;
+ await boards(author.api)({ boardId }).patch({
+ visibility: 'restricted',
+ memberIds: [granted.userId],
+ });
+
+ const res = await boards(granted.api)({ boardId }).delete();
+ expect(res.status).toBe(403);
+ expect(res.error?.value).toEqual({
+ error: 'Only the board creator or a project owner can delete the board',
+ });
+ expect((await boards(author.api)({ boardId }).get()).status).toBe(200);
+ });
+
+ it('lets a member delete a public board they did not create', async () => {
+ const owner = await setupOwnerProject();
+ const member = await addMember(owner.api);
+ const boardId = (await boards(owner.api).post({ name: 'Ideas' })).data!.id;
+
+ expect((await boards(member.api)({ boardId }).delete()).status).toBe(204);
+ expect((await boards(owner.api)({ boardId }).get()).status).toBe(404);
+ });
+
+ it("lets a project owner delete a member's private board they cannot see", async () => {
+ const owner = await setupOwnerProject();
+ const author = await addMember(owner.api);
+ const boardId = (await boards(author.api).post({ name: 'Ideas' })).data!.id;
+ await boards(author.api)({ boardId }).patch({ visibility: 'private' });
+
+ expect((await boards(owner.api)({ boardId }).get()).status).toBe(404);
+ expect((await boards(owner.api)({ boardId }).delete()).status).toBe(204);
+ expect((await boards(author.api)({ boardId }).get()).status).toBe(404);
+ });
+
+ it("keeps a member from deleting another member's private board", async () => {
+ const owner = await setupOwnerProject();
+ const author = await addMember(owner.api);
+ const other = await addMember(owner.api);
+ const boardId = (await boards(author.api).post({ name: 'Ideas' })).data!.id;
+ await boards(author.api)({ boardId }).patch({ visibility: 'private' });
+
+ expect((await boards(other.api)({ boardId }).delete()).status).toBe(404);
+ expect((await boards(author.api)({ boardId }).get()).status).toBe(200);
+ });
+
+ it('answers a delete from outside the board the way an update is answered', async () => {
+ const owner = await setupOwnerProject();
+ const other = await addMember(owner.api);
+ const outsider = authedApi((await signUpTestUser()).cookie);
+ const boardId = (await boards(owner.api).post({ name: 'Ideas' })).data!.id;
+ await boards(owner.api)({ boardId }).patch({ visibility: 'private' });
+
+ expect((await boards(other.api)({ boardId }).patch({ name: 'Nope' })).status).toBe(404);
+ expect((await boards(other.api)({ boardId }).delete()).status).toBe(404);
+ expect((await boards(outsider)({ boardId }).patch({ name: 'Nope' })).status).toBe(403);
+ expect((await boards(outsider)({ boardId }).delete()).status).toBe(403);
+ expect((await boards(owner.api)({ boardId }).get()).status).toBe(200);
+ });
+ });
+
describe('permissions', () => {
it('grants the default member role every note board action', async () => {
const owner = await setupOwnerProject();
diff --git a/apps/api/src/modules/note-boards/index.ts b/apps/api/src/modules/note-boards/index.ts
index d6994a99..c1033d30 100644
--- a/apps/api/src/modules/note-boards/index.ts
+++ b/apps/api/src/modules/note-boards/index.ts
@@ -3,6 +3,7 @@ import { noContent } from '#shared/http';
import { guards } from '#shared/guards';
import { authContext } from '#shared/auth-context';
import { requireUser } from '#shared/access';
+import { getMembership } from '#modules/members/service';
import { HttpError } from '#shared/lib';
import { mcpTool } from '#mcp/generate';
import { accessErrors, commonErrors } from '#shared/responses';
@@ -25,17 +26,10 @@ import {
type NoteBoardRow,
} from './service';
-// Load a board that belongs to this project and that the user may access: a
-// public board is open to any member; a private one to its owner and the members
+// A public board is open to any member; a private one to its owner and the members
// granted access. Anything else is a 404 so a private board's existence does not
// leak.
-async function loadAccessibleBoard(
- boardId: number,
- projectId: number,
- userId: string,
-): Promise<NoteBoardRow> {
- const board = await getNoteBoard(boardId);
- if (!board || board.projectId !== projectId) throw new HttpError(404, 'Board not found');
+function assertBoardVisible(board: NoteBoardRow, userId: string): void {
if (
board.ownerUserId !== null &&
board.ownerUserId !== userId &&
@@ -43,6 +37,17 @@ async function loadAccessibleBoard(
) {
throw new HttpError(404, 'Board not found');
}
+}
+
+// Load a board that belongs to this project and that the user may access.
+async function loadAccessibleBoard(
+ boardId: number,
+ projectId: number,
+ userId: string,
+): Promise<NoteBoardRow> {
+ const board = await getNoteBoard(boardId);
+ if (!board || board.projectId !== projectId) throw new HttpError(404, 'Board not found');
+ assertBoardVisible(board, userId);
return board;
}
@@ -202,7 +207,23 @@ export const noteBoardRoutes = new Elysia({
.delete(
'/projects/:projectKey/note-boards/:boardId',
async ({ project, user, params }) => {
- await loadAccessibleBoard(params.boardId, project.id, requireUser(user).id);
+ const userId = requireUser(user).id;
+ const board = await getNoteBoard(params.boardId);
+ if (!board || board.projectId !== project.id) throw new HttpError(404, 'Board not found');
+ // A project owner deletes any board, a private one included: the board of a
+ // member who left the project would otherwise stay for good.
+ if ((await getMembership(project.id, userId)) !== 'owner') {
+ assertBoardVisible(board, userId);
+ // A private or restricted board belongs to the member who made it, and
+ // being granted a view of one does not carry deleting it. A public board
+ // stays open to every member the role matrix allows.
+ if (board.ownerUserId !== null && board.ownerUserId !== userId) {
+ throw new HttpError(
+ 403,
+ 'Only the board creator or a project owner can delete the board',
+ );
+ }
+ }
await deleteNoteBoard(params.boardId);
return noContent();
},
@@ -213,7 +234,8 @@ export const noteBoardRoutes = new Elysia({
response: { 204: t.Void(), ...accessErrors },
detail: {
summary: 'Delete a note board',
- description: 'Permanently delete a note board and every note on it.',
+ description:
+ 'Permanently delete a note board and every note on it. A public board is open to every member the role matrix allows; a private or restricted one only to the member who made it. A project owner deletes any board, including one they cannot see.',
...mcpTool('delete_note_board'),
},
},