⭐️⭐️⭐️ 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.
TypeScript agenticagileai-agentsbug-reportingbug-trackerganttissue-trackerjirajira-alternativekanbanlinearlinear-alternativeopen-sourceproduct-managementproject-managementroadmapself-hostedsprint-planningteam-collaborationtrello-alternative
fix: allow deleting additional backlog states (#590)
TXyy2023bf52251541eb
diff --git a/apps/api/src/modules/columns/__tests__/integration/columns.test.ts b/apps/api/src/modules/columns/__tests__/integration/columns.test.tsindex 46f580c0..2f4b02d1 100644--- a/apps/api/src/modules/columns/__tests__/integration/columns.test.ts+++ b/apps/api/src/modules/columns/__tests__/integration/columns.test.ts@@ -248,14 +248,104 @@ describe('columns', () => {expect(gone.status).toBe(404);});- it('rejects deleting a backlog column', async () => {+ it('deletes an additional backlog column and its issues', async () => {const { asOwner } = await setupProject();const backlog = await columnByName(asOwner, 'Backlog');+ const extra = (+ await asOwner+ .projects({ projectKey: 'MKT' })+ .columns.post({ name: 'Triage', stateType: 'backlog' })+ ).data!;+ const issue = (await createIssue(asOwner, extra.id)).data!;++ const res = await asOwner+ .projects({ projectKey: 'MKT' })+ .columns({ columnId: extra.id })+ .delete({ mode: 'delete' });+ expect(res.status).toBe(204);+ const cols = await columnsOf(asOwner);+ expect(cols.map((c) => c.id)).not.toContain(extra.id);+ expect(cols.map((c) => c.id)).toContain(backlog.id);+ expect((await asOwner.issues({ issueId: issue.id }).get()).status).toBe(404);+ });++ it('moves issues when deleting the original backlog if another remains', async () => {+ const { asOwner } = await setupProject();+ const backlog = await columnByName(asOwner, 'Backlog');+ const extra = (+ await asOwner+ .projects({ projectKey: 'MKT' })+ .columns.post({ name: 'Triage', stateType: 'backlog' })+ ).data!;+ const issue = (await createIssue(asOwner, backlog.id)).data!;+const res = await asOwner.projects({ projectKey: 'MKT' }).columns({ columnId: backlog.id })+ .delete({ mode: 'move', targetColumnId: extra.id });+ expect(res.status).toBe(204);+ expect((await columnsOf(asOwner)).map((c) => c.id)).not.toContain(backlog.id);+ expect((await asOwner.issues({ issueId: issue.id }).get()).data?.columnId).toBe(extra.id);+ const timeline = await asOwner.issues({ issueId: issue.id }).timeline.get();+ expect(timeline.data!.map((s) => s.status)).toEqual(['Backlog', 'Triage']);+ });++ it('deletes an additional backlog in a copied project without changing the source', async () => {+ const { asOwner } = await setupProject();+ const extra = (+ await asOwner+ .projects({ projectKey: 'MKT' })+ .columns.post({ name: 'Triage', stateType: 'backlog' })+ ).data!;+ const copied = await asOwner+ .projects({ projectKey: 'MKT' })+ .copy.post({ key: 'COPY', name: 'Copy' });+ expect(copied.status).toBe(201);+ const copyExtra = await columnByName(asOwner, 'Triage', 'COPY');++ const res = await asOwner+ .projects({ projectKey: 'COPY' })+ .columns({ columnId: copyExtra.id }).delete({ mode: 'delete' });- expect(res.status).toBe(400);+ expect(res.status).toBe(204);+ expect((await columnsOf(asOwner, 'COPY')).map((c) => c.name)).not.toContain('Triage');+ expect((await columnsOf(asOwner)).map((c) => c.id)).toContain(extra.id);+ });++ it.each(['move', 'delete'] as const)(+ 'rejects deleting the last backlog in %s mode',+ async (mode) => {+ const { asOwner } = await setupProject();+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });+ const backlog = await columnByName(asOwner, 'Backlog');+ const todo = await columnByName(asOwner, 'Todo');+ const issue = (await createIssue(asOwner, backlog.id)).data!;+ const res = await asOwner+ .projects({ projectKey: 'MKT' })+ .columns({ columnId: backlog.id })+ .delete(mode === 'move' ? { mode, targetColumnId: todo.id } : { mode });+ expect(res.status).toBe(400);+ expect((await columnsOf(asOwner)).map((c) => c.id)).toContain(backlog.id);+ expect((await asOwner.issues({ issueId: issue.id }).get()).data?.columnId).toBe(backlog.id);+ },+ );++ it('keeps one backlog when two backlog deletions arrive together', async () => {+ const { asOwner } = await setupProject();+ const backlog = await columnByName(asOwner, 'Backlog');+ const extra = (+ await asOwner+ .projects({ projectKey: 'MKT' })+ .columns.post({ name: 'Triage', stateType: 'backlog' })+ ).data!;++ const results = await Promise.all(+ [backlog.id, extra.id].map((columnId) =>+ asOwner.projects({ projectKey: 'MKT' }).columns({ columnId }).delete({ mode: 'delete' }),+ ),+ );+ expect(results.map((r) => r.status).sort()).toEqual([204, 400]);+ expect((await columnsOf(asOwner)).filter((c) => c.stateType === 'backlog')).toHaveLength(1);});it('rejects a move whose target is in another project', async () => {diff --git a/apps/api/src/modules/columns/index.ts b/apps/api/src/modules/columns/index.tsindex c2a30c6c..3ec41c85 100644--- a/apps/api/src/modules/columns/index.ts+++ b/apps/api/src/modules/columns/index.ts@@ -97,7 +97,7 @@ export const columnRoutes = new Elysia({ name: 'columns', detail: { tags: ['Colusummary: 'Delete a column',description:"Delete a column. Body mode 'move' reassigns its issues to targetColumnId, " +- "'delete' removes them. Backlog columns cannot be deleted, nor a column whose " ++ "'delete' removes them. The last backlog column cannot be deleted, nor a column whose " +'agent schedules have runs that have not finished. The schedules of a deleted ' +'column are deleted with it.',...mcpTool('delete_column'),diff --git a/apps/api/src/modules/columns/service.ts b/apps/api/src/modules/columns/service.tsindex b11d117b..e283bc3a 100644--- a/apps/api/src/modules/columns/service.ts+++ b/apps/api/src/modules/columns/service.ts@@ -1,4 +1,12 @@-import { db, projectColumn, issue, issueLabel, issueFieldValue, issueFieldOption } from '@repo/db';+import {+ db,+ project,+ projectColumn,+ issue,+ issueLabel,+ issueFieldValue,+ issueFieldOption,+} from '@repo/db';import { and, eq, inArray, isNull, sql } from 'drizzle-orm';import { HttpError } from '#shared/lib';import { getMembership } from '#modules/members/service';@@ -210,9 +218,8 @@ export async function reorderColumns(projectId: number, orderedIds: number[]): Pexport type DeleteColumnOptions = { mode: 'move'; targetColumnId: number } | { mode: 'delete' };-// Backlog columns cannot be deleted, which keeps at least one column on every-// project. The column and its issues go in one transaction so neither is left-// half-deleted.+// Keep one backlog column per project. The column and its issues go in one+// transaction so neither is left half-deleted.export async function deleteColumn(columnId: number,projectId: number,@@ -222,7 +229,6 @@ export async function deleteColumn(const column = await getColumnById(columnId);if (!column || column.projectId !== projectId)throw new HttpError(404, `Column ${columnId} not found`);- if (column.stateType === 'backlog') throw new HttpError(400, 'Backlog columns cannot be deleted');if (await hasUnfinishedStatusRuns(columnId)) {throw new HttpError(409,@@ -247,6 +253,20 @@ export async function deleteColumn(}const movedIssueIds = await db.transaction(async (tx) => {+ if (column.stateType === 'backlog') {+ // Serialize backlog deletions so concurrent requests cannot remove the last two.+ await tx+ .select({ id: project.id })+ .from(project)+ .where(eq(project.id, projectId))+ .for('update');+ const [{ count }] = await tx+ .select({ count: sql<number>`count(*)::int` })+ .from(projectColumn)+ .where(and(eq(projectColumn.projectId, projectId), eq(projectColumn.stateType, 'backlog')));+ if (count <= 1) throw new HttpError(400, 'The last backlog column cannot be deleted');+ }+let moved: number[] = [];if (opts.mode === 'move') {const rows = await txdiff --git a/apps/web/src/features/settings/components/states/SettingsStateRow.tsx b/apps/web/src/features/settings/components/states/SettingsStateRow.tsxindex 858b3eee..8f448a3f 100644--- a/apps/web/src/features/settings/components/states/SettingsStateRow.tsx+++ b/apps/web/src/features/settings/components/states/SettingsStateRow.tsx@@ -13,16 +13,17 @@ import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltipimport { useSettingsCan } from '../../context/settingsPermission';// One sortable state row. The whole row is the sortable node; the grip is the-// drag handle so the Edit/Delete buttons stay clickable. A backlog state cannot-// be deleted, so its delete action is hidden.+// drag handle so the Edit/Delete buttons stay clickable.export function SettingsStateRow({column,autoAssignee,+ deletable,onEdit,onDelete,}: {column: Column;autoAssignee?: Assignee;+ deletable: boolean;onEdit: () => void;onDelete: () => void;}) {@@ -97,7 +98,7 @@ export function SettingsStateRow({<Pencil className="size-4" /></Button>)}- {can('delete') && column.stateType !== 'backlog' && (+ {can('delete') && deletable && (<Buttonvariant="ghost"size="icon"diff --git a/apps/web/src/features/settings/components/states/SettingsStates.tsx b/apps/web/src/features/settings/components/states/SettingsStates.tsxindex a91b11c1..00f23bb7 100644--- a/apps/web/src/features/settings/components/states/SettingsStates.tsx+++ b/apps/web/src/features/settings/components/states/SettingsStates.tsx@@ -192,6 +192,7 @@ export default function SettingsStates({ project }: { project: ProjectDetail })<SettingsStateRowkey={c.id}column={c}+ deletable={s !== 'backlog' || group.length > 1}autoAssignee={project.assignees.find((a) => a.userId === c.autoAssignUserId,)}