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.

feat: sync subtask and parent closing, move archive into workflow configuration (#103)

Croffe93fc89730e6
diff --git a/apps/api/src/issues/__tests__/integration/subtasks.test.ts b/apps/api/src/issues/__tests__/integration/subtasks.test.ts
index f5f4ffda..253e50fa 100644
--- a/apps/api/src/issues/__tests__/integration/subtasks.test.ts
+++ b/apps/api/src/issues/__tests__/integration/subtasks.test.ts
@@ -13,6 +13,8 @@ import { resetDb } from '../../../__tests__/helpers/db';
interface Setup {
asOwner: Api;
columnId: number;
+ doneColumnId: number;
+ canceledColumnId: number;
}
async function setupProject(): Promise<Setup> {
@@ -20,7 +22,14 @@ async function setupProject(): Promise<Setup> {
const asOwner = authedApi(owner.cookie);
await asOwner.projects.post({ key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
- return { asOwner, columnId: view.data!.columns[0].id };
+ const columns = view.data!.columns;
+ const byState = (stateType: string) => columns.find((c) => c.stateType === stateType)!.id;
+ return {
+ asOwner,
+ columnId: columns[0].id,
+ doneColumnId: byState('completed'),
+ canceledColumnId: byState('canceled'),
+ };
}
function createIssue(client: Api, columnId: number, title = 'Task') {
@@ -40,10 +49,22 @@ async function parentWithSubtask(client: Api, columnId: number) {
return { parent, subtask };
}
+function createSubtask(client: Api, columnId: number, parentId: number, title: string) {
+ return client.projects({ projectKey: 'MKT' }).issues.post({ columnId, title, parentId });
+}
+
function setParent(client: Api, issueId: number, parentId: number | null) {
return client.issues({ issueId }).patch({ parentId });
}
+function move(client: Api, issueId: number, columnId: number) {
+ return client.issues({ issueId }).patch({ columnId });
+}
+
+function setAutomations(client: Api, input: { completeParent: boolean; closeSubtasks: boolean }) {
+ return client.projects({ projectKey: 'MKT' }).settings.subtasks.patch(input);
+}
+
async function read(client: Api, issueId: number) {
const res = await client.issues({ issueId }).get();
return res.data!;
@@ -368,4 +389,76 @@ describe('subtasks', () => {
expect(await read(asOwner, subtask.id)).toMatchObject({ parentId: null });
});
});
+
+ describe('close automations', () => {
+ it('leaves the hierarchy alone while both automations are off', async () => {
+ const { asOwner, columnId, doneColumnId } = await setupProject();
+ const { parent, subtask } = await parentWithSubtask(asOwner, columnId);
+
+ await move(asOwner, subtask.id, doneColumnId);
+ expect((await read(asOwner, parent.id)).columnId).toBe(columnId);
+
+ await move(asOwner, parent.id, doneColumnId);
+ expect((await read(asOwner, subtask.id)).columnId).toBe(doneColumnId);
+ await move(asOwner, subtask.id, columnId);
+ expect((await read(asOwner, subtask.id)).columnId).toBe(columnId);
+ });
+
+ it('closes the parent in the column its last subtask landed in', async () => {
+ const { asOwner, columnId, doneColumnId, canceledColumnId } = await setupProject();
+ const { parent, subtask } = await parentWithSubtask(asOwner, columnId);
+ const second = (await createSubtask(asOwner, columnId, parent.id, 'Second')).data!;
+ await setAutomations(asOwner, { completeParent: true, closeSubtasks: false });
+
+ await move(asOwner, subtask.id, canceledColumnId);
+ expect((await read(asOwner, parent.id)).columnId).toBe(columnId);
+
+ await move(asOwner, second.id, doneColumnId);
+ expect((await read(asOwner, parent.id)).columnId).toBe(doneColumnId);
+ });
+
+ it('holds the parent open while a subtask is still open', async () => {
+ const { asOwner, columnId, doneColumnId } = await setupProject();
+ const { parent, subtask } = await parentWithSubtask(asOwner, columnId);
+ await createSubtask(asOwner, columnId, parent.id, 'Second');
+ await setAutomations(asOwner, { completeParent: true, closeSubtasks: false });
+
+ await move(asOwner, subtask.id, doneColumnId);
+ expect((await read(asOwner, parent.id)).columnId).toBe(columnId);
+ });
+
+ it('ignores an archived subtask when closing the parent', async () => {
+ const { asOwner, columnId, doneColumnId } = await setupProject();
+ const { parent, subtask } = await parentWithSubtask(asOwner, columnId);
+ const archived = (await createSubtask(asOwner, columnId, parent.id, 'Archived')).data!;
+ await asOwner.issues({ issueId: archived.id }).archive.post();
+ await setAutomations(asOwner, { completeParent: true, closeSubtasks: false });
+
+ await move(asOwner, subtask.id, doneColumnId);
+ expect((await read(asOwner, parent.id)).columnId).toBe(doneColumnId);
+ });
+
+ it('closes the open subtasks in the column the parent was closed in', async () => {
+ const { asOwner, columnId, doneColumnId, canceledColumnId } = await setupProject();
+ const { parent, subtask } = await parentWithSubtask(asOwner, columnId);
+ const alreadyClosed = (await createSubtask(asOwner, columnId, parent.id, 'Closed')).data!;
+ await move(asOwner, alreadyClosed.id, canceledColumnId);
+ await setAutomations(asOwner, { completeParent: false, closeSubtasks: true });
+
+ await move(asOwner, parent.id, doneColumnId);
+ expect((await read(asOwner, subtask.id)).columnId).toBe(doneColumnId);
+ expect((await read(asOwner, alreadyClosed.id)).columnId).toBe(canceledColumnId);
+ });
+
+ it('settles with both automations on', async () => {
+ const { asOwner, columnId, doneColumnId } = await setupProject();
+ const { parent, subtask } = await parentWithSubtask(asOwner, columnId);
+ await setAutomations(asOwner, { completeParent: true, closeSubtasks: true });
+
+ const res = await move(asOwner, parent.id, doneColumnId);
+ expect(res.status).toBe(200);
+ expect((await read(asOwner, parent.id)).columnId).toBe(doneColumnId);
+ expect((await read(asOwner, subtask.id)).columnId).toBe(doneColumnId);
+ });
+ });
});
diff --git a/apps/api/src/issues/automation.ts b/apps/api/src/issues/automation.ts
new file mode 100644
index 00000000..d7f9a26d
--- /dev/null
+++ b/apps/api/src/issues/automation.ts
@@ -0,0 +1,87 @@
+import { db, issue, projectColumn } from '@repo/db';
+import { and, eq, inArray, isNull } from 'drizzle-orm';
+import { getSubtaskAutomationSettings } from '../projects/store';
+import { listSubtasks } from './subtasks';
+import { updateIssue, type IssueRow } from './store';
+
+// The subtask automations a column change triggers, both off unless the project
+// turns them on (projects/store.ts). A closed issue is one sitting in a column
+// whose stateType is 'completed' or 'canceled'.
+//
+// The hierarchy is one level deep, so an issue is either a subtask or a parent and
+// only one of the two rules applies to it. Each rule writes through updateIssue, so
+// the moved issues get their own activity entries and webhooks — and re-enter this
+// function. That does not loop: a rule skips an issue already in the target column,
+// which is where the nested pass finds every issue it would move.
+
+const CLOSED_STATE_TYPES = ['completed', 'canceled'];
+
+export async function applySubtaskAutomation(
+ after: IssueRow,
+ actorUserId?: string | null,
+): Promise<void> {
+ const settings = await getSubtaskAutomationSettings(after.projectId);
+ if (!settings.completeParent && !settings.closeSubtasks) return;
+ if (!(await isClosedColumn(after.columnId))) return;
+
+ if (after.parentId !== null) {
+ if (settings.completeParent) await completeParent(after.parentId, after, actorUserId);
+ return;
+ }
+ if (settings.closeSubtasks) await closeSubtasks(after, actorUserId);
+}
+
+// Moves the issue's parent into the column the issue was just closed in, once every
+// other subtask is closed too. Archived subtasks are off the board and do not hold
+// the parent open; an archived parent is left where it is rather than brought back.
+// A parent already closed keeps its own column: the rule has nothing left to do.
+async function completeParent(
+ parentId: number,
+ subtask: IssueRow,
+ actorUserId?: string | null,
+): Promise<void> {
+ const siblingColumnIds = (await listSubtasks(parentId))
+ .filter((s) => !s.archived && s.id !== subtask.id)
+ .map((s) => s.columnId);
+ const parentColumnId = await activeColumn(parentId);
+ if (parentColumnId === null) return;
+ const closed = await closedColumnIds([...siblingColumnIds, parentColumnId]);
+ if (closed.has(parentColumnId)) return;
+ if (siblingColumnIds.some((id) => !closed.has(id))) return;
+ await updateIssue(parentId, { columnId: subtask.columnId }, actorUserId);
+}
+
+// Moves the issue's still-open subtasks into the column it was just closed in.
+async function closeSubtasks(parent: IssueRow, actorUserId?: string | null): Promise<void> {
+ const subtasks = (await listSubtasks(parent.id)).filter((s) => !s.archived);
+ const closed = await closedColumnIds(subtasks.map((s) => s.columnId));
+ for (const subtask of subtasks)
+ if (!closed.has(subtask.columnId))
+ await updateIssue(subtask.id, { columnId: parent.columnId }, actorUserId);
+}
+
+async function isClosedColumn(columnId: number): Promise<boolean> {
+ return (await closedColumnIds([columnId])).has(columnId);
+}
+
+// The subset of the given column ids whose stateType counts as closed.
+async function closedColumnIds(columnIds: number[]): Promise<Set<number>> {
+ const ids = [...new Set(columnIds)];
+ if (ids.length === 0) return new Set();
+ const rows = await db
+ .select({ id: projectColumn.id })
+ .from(projectColumn)
+ .where(
+ and(inArray(projectColumn.id, ids), inArray(projectColumn.stateType, CLOSED_STATE_TYPES)),
+ );
+ return new Set(rows.map((r) => r.id));
+}
+
+// The issue's column, or null when it is gone or archived.
+async function activeColumn(issueId: number): Promise<number | null> {
+ const [row] = await db
+ .select({ columnId: issue.columnId })
+ .from(issue)
+ .where(and(eq(issue.id, issueId), isNull(issue.archivedAt)));
+ return row?.columnId ?? null;
+}
diff --git a/apps/api/src/issues/store.ts b/apps/api/src/issues/store.ts
index f80ceb6b..9e44d273 100644
--- a/apps/api/src/issues/store.ts
+++ b/apps/api/src/issues/store.ts
@@ -53,6 +53,7 @@ import { getInitiativeProjectId } from '../initiatives/store';
import { getCycleRef } from '../cycles/store';
import { getMembership } from '../members/store';
import { enqueueAgentRun } from '../ai-agents/run-queue';
+import { applySubtaskAutomation } from './automation';
// Data access for issues and their per-issue data: labels, custom field values,
// and selected options. The human identifier (e.g. "MKT-42") is the project key
@@ -951,8 +952,10 @@ export async function updateIssue(
await emitWebhookEvent(after.projectId, 'issue.assigned', after);
if (before.delegateUserId !== after.delegateUserId)
await enqueueDelegateRun(after, actorUserId);
- if (before.columnId !== after.columnId)
+ if (before.columnId !== after.columnId) {
await emitWebhookEvent(after.projectId, 'issue.state_changed', after);
+ await applySubtaskAutomation(after, actorUserId);
+ }
}
}
return after;
diff --git a/apps/api/src/projects/__tests__/integration/projects.test.ts b/apps/api/src/projects/__tests__/integration/projects.test.ts
index 08dff549..0ac347ed 100644
--- a/apps/api/src/projects/__tests__/integration/projects.test.ts
+++ b/apps/api/src/projects/__tests__/integration/projects.test.ts
@@ -718,7 +718,7 @@ describe('projects', () => {
await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
const role = await owner.api
.projects({ projectKey: 'MKT' })
- .roles.post({ name: 'Reader', permissions: { auto_archive: { read: true } } });
+ .roles.post({ name: 'Reader', permissions: { workflow_config: { read: true } } });
const member = await addMember(owner.api, role.data!.id);
expect((await autoArchive(member).get()).status).toBe(200);
@@ -732,7 +732,7 @@ describe('projects', () => {
await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
const role = await owner.api.projects({ projectKey: 'MKT' }).roles.post({
name: 'Archivist',
- permissions: { auto_archive: { read: true, edit: true } },
+ permissions: { workflow_config: { read: true, edit: true } },
});
const member = await addMember(owner.api, role.data!.id);
@@ -741,4 +741,56 @@ describe('projects', () => {
expect(res.data).toMatchObject({ completedDays: 14, canceledDays: 3 });
});
});
+
+ describe('subtask automation settings', () => {
+ const subtasks = (client: Api) => client.projects({ projectKey: 'MKT' }).settings.subtasks;
+
+ it('defaults a new project to both automations off', async () => {
+ const { api } = await signUpClient();
+ await api.projects.post({ key: 'MKT', name: 'Marketing' });
+
+ const res = await subtasks(api).get();
+ expect(res.status).toBe(200);
+ expect(res.data).toMatchObject({ completeParent: false, closeSubtasks: false });
+ });
+
+ it('lets an owner set and read back the automations', async () => {
+ const { api } = await signUpClient();
+ await api.projects.post({ key: 'MKT', name: 'Marketing' });
+
+ const patch = await subtasks(api).patch({ completeParent: true, closeSubtasks: false });
+ expect(patch.status).toBe(200);
+ expect(patch.data).toMatchObject({ completeParent: true, closeSubtasks: false });
+
+ expect((await subtasks(api).get()).data).toMatchObject({
+ completeParent: true,
+ closeSubtasks: false,
+ });
+ });
+
+ it('holds the default member role out of the section', async () => {
+ const owner = await signUpClient();
+ await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ const member = await addMember(owner.api);
+
+ expect((await subtasks(member).get()).status).toBe(403);
+ expect(
+ (await subtasks(member).patch({ completeParent: true, closeSubtasks: true })).status,
+ ).toBe(403);
+ });
+
+ it('lets a granted role read the automations but not change them without edit', async () => {
+ const owner = await signUpClient();
+ await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+ const role = await owner.api
+ .projects({ projectKey: 'MKT' })
+ .roles.post({ name: 'Reader', permissions: { workflow_config: { read: true } } });
+ const member = await addMember(owner.api, role.data!.id);
+
+ expect((await subtasks(member).get()).status).toBe(200);
+ expect(
+ (await subtasks(member).patch({ completeParent: true, closeSubtasks: true })).status,
+ ).toBe(403);
+ });
+ });
});
diff --git a/apps/api/src/projects/copy.ts b/apps/api/src/projects/copy.ts
index 85a03217..28afeb29 100644
--- a/apps/api/src/projects/copy.ts
+++ b/apps/api/src/projects/copy.ts
@@ -48,7 +48,7 @@ export interface CopyProjectInclude {
views: boolean;
dashboards: boolean;
actions: boolean;
- archive: boolean;
+ configuration: boolean;
roles: boolean;
notificationProviders: boolean;
webhooks: boolean;
@@ -67,7 +67,7 @@ export const COPY_INCLUDE_KEYS: (keyof CopyProjectInclude)[] = [
'views',
'dashboards',
'actions',
- 'archive',
+ 'configuration',
'roles',
'notificationProviders',
'webhooks',
@@ -519,9 +519,10 @@ export async function copyProject(
}
}
- // Project settings key/value rows (the Archive section's auto-archive thresholds,
- // and any other project-scoped setting). Copied verbatim.
- if (inc.archive) {
+ // Project settings key/value rows (the Configuration section's subtask
+ // automations and auto-archive thresholds, and any other project-scoped
+ // setting). Copied verbatim.
+ if (inc.configuration) {
const settingRows = await tx
.select()
.from(projectSetting)
diff --git a/apps/api/src/projects/routes.ts b/apps/api/src/projects/routes.ts
index 48848e48..466a57ba 100644
--- a/apps/api/src/projects/routes.ts
+++ b/apps/api/src/projects/routes.ts
@@ -18,6 +18,8 @@ import {
setProjectFeatures,
getAutoArchiveSettings,
setAutoArchiveSettings,
+ getSubtaskAutomationSettings,
+ setSubtaskAutomationSettings,
ISSUE_TYPE_PRESET_KEYS,
} from './store';
import { copyProject, COPY_INCLUDE_KEYS } from './copy';
@@ -167,6 +169,12 @@ const AutoArchiveResponse = t.Object({
canceledDays: t.Nullable(t.Number()),
});
+// The subtask automations (SubtaskAutomationSettings from the store).
+const SubtaskAutomationResponse = t.Object({
+ completeParent: t.Boolean(),
+ closeSubtasks: t.Boolean(),
+});
+
// Which optional sections the project shows (ProjectFeatures from the store).
const FeaturesResponse = t.Object({
initiatives: t.Boolean(),
@@ -447,14 +455,14 @@ export const projectRoutes = new Elysia({ name: 'projects', detail: { tags: ['Pr
},
)
- // The thresholds are their own permission resource rather than part of the
- // settings payload above: a granted role reads or changes them without being an
- // owner.
+ // The workflow configuration — the auto-archive thresholds and the subtask
+ // automations — is its own permission resource rather than part of the settings
+ // payload above: a granted role reads or changes it without being an owner.
.get(
'/projects/:projectKey/settings/auto-archive',
({ project }) => getAutoArchiveSettings(project.id),
{
- permission: ['auto_archive', 'read'],
+ permission: ['workflow_config', 'read'],
response: {
200: AutoArchiveResponse,
401: ErrorResponse,
@@ -475,7 +483,7 @@ export const projectRoutes = new Elysia({ name: 'projects', detail: { tags: ['Pr
completedDays: t.Nullable(t.Integer({ minimum: 1 })),
canceledDays: t.Nullable(t.Integer({ minimum: 1 })),
}),
- permission: ['auto_archive', 'edit'],
+ permission: ['workflow_config', 'edit'],
response: {
200: AutoArchiveResponse,
400: ErrorResponse,
@@ -487,6 +495,42 @@ export const projectRoutes = new Elysia({ name: 'projects', detail: { tags: ['Pr
},
)
+ .get(
+ '/projects/:projectKey/settings/subtasks',
+ ({ project }) => getSubtaskAutomationSettings(project.id),
+ {
+ permission: ['workflow_config', 'read'],
+ response: {
+ 200: SubtaskAutomationResponse,
+ 401: ErrorResponse,
+ 403: ErrorResponse,
+ 404: ErrorResponse,
+ },
+ detail: { summary: "Get a project's subtask automations" },
+ },
+ )
+
+ // Both automations are sent together, the same as the thresholds above.
+ .patch(
+ '/projects/:projectKey/settings/subtasks',
+ ({ project, body }) => setSubtaskAutomationSettings(project.id, body),
+ {
+ body: t.Object({
+ completeParent: t.Boolean(),
+ closeSubtasks: t.Boolean(),
+ }),
+ permission: ['workflow_config', 'edit'],
+ response: {
+ 200: SubtaskAutomationResponse,
+ 400: ErrorResponse,
+ 401: ErrorResponse,
+ 403: ErrorResponse,
+ 404: ErrorResponse,
+ },
+ detail: { summary: "Update a project's subtask automations" },
+ },
+ )
+
// Permanently removes the project and everything scoped to it. Irreversible.
// Owner-only.
.delete(
diff --git a/apps/api/src/projects/store.ts b/apps/api/src/projects/store.ts
index 0dc3184a..31b8a7d3 100644
--- a/apps/api/src/projects/store.ts
+++ b/apps/api/src/projects/store.ts
@@ -354,6 +354,43 @@ export async function setAutoArchiveSettings(
return next;
}
+// The subtask automations, stored in project_setting under SUBTASK_AUTOMATION_KEY.
+// completeParent moves a parent into the column of its last closed subtask once
+// every subtask is closed; closeSubtasks moves the still-open subtasks of an issue
+// into the column the issue was closed in. Both off unless a project turns them on:
+// they rewrite states nobody asked to change. Applied in issues/automation.ts.
+const SUBTASK_AUTOMATION_KEY = 'subtask_automation';
+
+export interface SubtaskAutomationSettings {
+ completeParent: boolean;
+ closeSubtasks: boolean;
+}
+
+export async function getSubtaskAutomationSettings(
+ projectId: number,
+): Promise<SubtaskAutomationSettings> {
+ const stored = await getProjectSetting<Partial<SubtaskAutomationSettings>>(
+ projectId,
+ SUBTASK_AUTOMATION_KEY,
+ );
+ return {
+ completeParent: stored?.completeParent === true,
+ closeSubtasks: stored?.closeSubtasks === true,
+ };
+}
+
+export async function setSubtaskAutomationSettings(
+ projectId: number,
+ input: SubtaskAutomationSettings,
+): Promise<SubtaskAutomationSettings> {
+ const next: SubtaskAutomationSettings = {
+ completeParent: input.completeParent,
+ closeSubtasks: input.closeSubtasks,
+ };
+ await setProjectSetting(projectId, SUBTASK_AUTOMATION_KEY, next);
+ return next;
+}
+
// Deletes a project and everything scoped to it. Every project-scoped foreign key
// has ON DELETE CASCADE on project_id, so deleting the project row removes its
// columns, issue types, labels, initiatives, issues, views, dashboards, and
diff --git a/apps/api/src/shared/permissions.ts b/apps/api/src/shared/permissions.ts
index b2f5e25f..9438d075 100644
--- a/apps/api/src/shared/permissions.ts
+++ b/apps/api/src/shared/permissions.ts
@@ -19,7 +19,7 @@ export const PERMISSION_RESOURCES = [
'agent_skills',
'agent_tools',
'custom_fields',
- 'auto_archive',
+ 'workflow_config',
'actions',
'webhooks',
'note_boards',
diff --git a/apps/web/src/app/project/[projectKey]/settings/archive/page.tsx b/apps/web/src/app/project/[projectKey]/settings/archive/page.tsx
deleted file mode 100644
index 7a9a056b..00000000
--- a/apps/web/src/app/project/[projectKey]/settings/archive/page.tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-import SettingsArchivePage from '@/features/settings/SettingsArchivePage';
-
-export default function Page() {
- return <SettingsArchivePage />;
-}
diff --git a/apps/web/src/app/project/[projectKey]/settings/configuration/page.tsx b/apps/web/src/app/project/[projectKey]/settings/configuration/page.tsx
new file mode 100644
index 00000000..05feb57f
--- /dev/null
+++ b/apps/web/src/app/project/[projectKey]/settings/configuration/page.tsx
@@ -0,0 +1,5 @@
+import SettingsConfigurationPage from '@/features/settings/SettingsConfigurationPage';
+
+export default function Page() {
+ return <SettingsConfigurationPage />;
+}
diff --git a/apps/web/src/components/layout/CopyProjectOptions.tsx b/apps/web/src/components/layout/CopyProjectOptions.tsx
index f69eafa8..7cf1ef33 100644
--- a/apps/web/src/components/layout/CopyProjectOptions.tsx
+++ b/apps/web/src/components/layout/CopyProjectOptions.tsx
@@ -15,7 +15,7 @@ const REQUIRES: Record<CopyProjectIncludeKey, CopyProjectIncludeKey[]> = {
views: ['states', 'issueTypes', 'labels', 'customFields'],
dashboards: [],
actions: ['states', 'issueTypes', 'labels'],
- archive: [],
+ configuration: [],
roles: [],
notificationProviders: [],
webhooks: [],
@@ -34,7 +34,7 @@ const LABELS: Record<CopyProjectIncludeKey, string> = {
views: 'Views',
dashboards: 'Dashboards',
actions: 'Actions',
- archive: 'Archive settings',
+ configuration: 'Configuration',
roles: 'Roles',
notificationProviders: 'Notification providers',
webhooks: 'Webhooks',
@@ -50,7 +50,12 @@ type Group = { title: string; keys: CopyProjectIncludeKey[] };
// Groups assigned to the four rendered columns by hand, keeping each column close
// to the same number of rows.
const COLUMNS: Group[][] = [
- [{ title: 'Workflow', keys: ['states', 'issueTypes', 'labels', 'customFields', 'archive'] }],
+ [
+ {
+ title: 'Workflow',
+ keys: ['states', 'issueTypes', 'labels', 'customFields', 'configuration'],
+ },
+ ],
[{ title: 'Automation', keys: ['actions', 'schedules', 'webhooks'] }],
[{ title: 'AI Team', keys: ['agents', 'integrations', 'skills', 'tools'] }],
[
diff --git a/apps/web/src/features/settings/SettingsArchivePage.tsx b/apps/web/src/features/settings/SettingsArchivePage.tsx
deleted file mode 100644
index d9ceace7..00000000
--- a/apps/web/src/features/settings/SettingsArchivePage.tsx
+++ /dev/null
@@ -1,46 +0,0 @@
-'use client';
-
-import type { ProjectDetail } from '@/lib/api';
-import { useShell } from '@/context/shellContext';
-import { settingsSection } from '@/utils/settingsSections';
-import { Button } from '@/components/ui/button';
-import SectionPageView from '@/components/common/page/SectionPageView';
-import RequirePermission from '@/components/common/permissions/RequirePermission';
-import { SettingsResourceProvider } from './context/settingsPermission';
-import SettingsArchive from './components/archive/SettingsArchive';
-import { useAutoArchiveForm } from './hooks/useAutoArchiveForm';
-
-const section = settingsSection('archive');
-
-// The Archive settings page (/project/:projectKey/settings/archive). Shows the
-// auto-archive thresholds; Save lives in the page header.
-export default function SettingsArchivePage() {
- const { project } = useShell();
- if (!project) return null;
- return <ArchivePage project={project} />;
-}
-
-function ArchivePage({ project }: { project: ProjectDetail }) {
- const form = useAutoArchiveForm(project.project.key);
- return (
- <SectionPageView
- title={section.label}
- description={section.description}
- wide
- widthClassName="min-w-[600px] max-w-[60%]"
- actions={
- form.editable ? (
- <Button size="sm" onClick={() => void form.save()} disabled={form.saving}>
- Save
- </Button>
- ) : undefined
- }
- >
- <SettingsResourceProvider resource={section.resource}>
- <RequirePermission resource={section.resource} action="read">
- <SettingsArchive form={form} />
- </RequirePermission>
- </SettingsResourceProvider>
- </SectionPageView>
- );
-}
diff --git a/apps/web/src/features/settings/SettingsConfigurationPage.tsx b/apps/web/src/features/settings/SettingsConfigurationPage.tsx
new file mode 100644
index 00000000..8bc1e950
--- /dev/null
+++ b/apps/web/src/features/settings/SettingsConfigurationPage.tsx
@@ -0,0 +1,65 @@
+'use client';
+
+import { toast } from 'sonner';
+import type { ProjectDetail } from '@/lib/api';
+import { useShell } from '@/context/shellContext';
+import { settingsSection } from '@/utils/settingsSections';
+import { usePermissions } from '@/hooks/usePermissions';
+import { Button } from '@/components/ui/button';
+import SectionPageView from '@/components/common/page/SectionPageView';
+import RequirePermission from '@/components/common/permissions/RequirePermission';
+import { SettingsResourceProvider } from './context/settingsPermission';
+import SettingsSubtaskAutomation from './components/configuration/SettingsSubtaskAutomation';
+import SettingsAutoArchive from './components/configuration/SettingsAutoArchive';
+import { useAutoArchiveForm } from './hooks/useAutoArchiveForm';
+import { useSubtaskAutomationForm } from './hooks/useSubtaskAutomationForm';
+
+const section = settingsSection('configuration');
+
+// The Configuration settings page (/project/:projectKey/settings/configuration).
+// Holds the subtask automations and the auto-archive thresholds; the Save in the
+// page header writes both.
+export default function SettingsConfigurationPage() {
+ const { project } = useShell();
+ if (!project) return null;
+ return <ConfigurationPage project={project} />;
+}
+
+function ConfigurationPage({ project }: { project: ProjectDetail }) {
+ const { can } = usePermissions();
+ const subtasks = useSubtaskAutomationForm(project.project.key);
+ const archive = useAutoArchiveForm(project.project.key);
+ const saving = subtasks.saving || archive.saving;
+ const loaded = subtasks.loaded && archive.loaded;
+
+ async function save() {
+ await subtasks.save();
+ await archive.save();
+ toast.success('Changes saved');
+ }
+
+ return (
+ <SectionPageView
+ title={section.label}
+ description={section.description}
+ wide
+ widthClassName="min-w-[600px] max-w-[60%]"
+ actions={
+ can(section.resource, 'edit') ? (
+ <Button size="sm" onClick={() => void save()} disabled={saving || !loaded}>
+ Save
+ </Button>
+ ) : undefined
+ }
+ >
+ <SettingsResourceProvider resource={section.resource}>
+ <RequirePermission resource={section.resource} action="read">
+ <div className="space-y-10">
+ <SettingsSubtaskAutomation form={subtasks} />
+ <SettingsAutoArchive form={archive} />
+ </div>
+ </RequirePermission>
+ </SettingsResourceProvider>
+ </SectionPageView>
+ );
+}
diff --git a/apps/web/src/features/settings/components/archive/SettingsArchive.tsx b/apps/web/src/features/settings/components/archive/SettingsArchive.tsx
deleted file mode 100644
index ec1ede55..00000000
--- a/apps/web/src/features/settings/components/archive/SettingsArchive.tsx
+++ /dev/null
@@ -1,62 +0,0 @@
-import { Input } from '@/components/ui/input';
-import { Switch } from '@/components/ui/switch';
-import type { AutoArchiveForm } from '../../hooks/useAutoArchiveForm';
-
-export default function SettingsArchive({ form }: { form: AutoArchiveForm }) {
- return (
- <section className="flex flex-col gap-4">
- <div className="divide-y divide-border rounded-lg border border-border">
- <ThresholdRow
- label="Completed issues"
- on={form.completedOn}
- days={form.completedDays}
- editable={form.editable}
- onToggle={form.setCompletedOn}
- onDays={form.setCompletedDays}
- />
- <ThresholdRow
- label="Canceled issues"
- on={form.canceledOn}
- days={form.canceledDays}
- editable={form.editable}
- onToggle={form.setCanceledOn}
- onDays={form.setCanceledDays}
- />
- </div>
- </section>
- );
-}
-
-function ThresholdRow({
- label,
- on,
- days,
- editable,
- onToggle,
- onDays,
-}: {
- label: string;
- on: boolean;
- days: string;
- editable: boolean;
- onToggle: (v: boolean) => void;
- onDays: (v: string) => void;
-}) {
- return (
- <div className="flex items-center gap-3 px-4 py-3">
- <Switch checked={on} onCheckedChange={onToggle} disabled={!editable} />
- <span className="flex-1 text-sm">{label}</span>
- <div className="flex items-center gap-2">
- <Input
- type="number"
- min={1}
- value={days}
- onChange={(e) => onDays(e.target.value)}
- disabled={!editable || !on}
- className="h-8 w-20"
- />
- <span className="text-sm text-muted-foreground">days</span>
- </div>
- </div>
- );
-}
diff --git a/apps/web/src/features/settings/components/configuration/SettingsAutoArchive.tsx b/apps/web/src/features/settings/components/configuration/SettingsAutoArchive.tsx
new file mode 100644
index 00000000..3cda8688
--- /dev/null
+++ b/apps/web/src/features/settings/components/configuration/SettingsAutoArchive.tsx
@@ -0,0 +1,36 @@
+import SettingsCard from '@/components/common/page/SettingsCard';
+import SettingsSection from '@/components/common/page/SettingsSection';
+import type { AutoArchiveForm } from '../../hooks/useAutoArchiveForm';
+import SettingsAutoArchiveRow from './SettingsAutoArchiveRow';
+
+// The Archive block of the Configuration page: how long a closed issue may sit
+// untouched before the worker archives it.
+export default function SettingsAutoArchive({ form }: { form: AutoArchiveForm }) {
+ return (
+ <SettingsSection
+ title="Archive"
+ description="Archive stale closed issues so the board stays clear."
+ >
+ <SettingsCard className="divide-y divide-border/60">
+ <SettingsAutoArchiveRow
+ title="Completed issues"
+ description="Archive after this many days without activity."
+ on={form.completedOn}
+ days={form.completedDays}
+ editable={form.editable}
+ onToggle={form.setCompletedOn}
+ onDays={form.setCompletedDays}
+ />
+ <SettingsAutoArchiveRow
+ title="Canceled issues"
+ description="Archive after this many days without activity."
+ on={form.canceledOn}
+ days={form.canceledDays}
+ editable={form.editable}
+ onToggle={form.setCanceledOn}
+ onDays={form.setCanceledDays}
+ />
+ </SettingsCard>
+ </SettingsSection>
+ );
+}
diff --git a/apps/web/src/features/settings/components/configuration/SettingsAutoArchiveRow.tsx b/apps/web/src/features/settings/components/configuration/SettingsAutoArchiveRow.tsx
new file mode 100644
index 00000000..15cc523a
--- /dev/null
+++ b/apps/web/src/features/settings/components/configuration/SettingsAutoArchiveRow.tsx
@@ -0,0 +1,45 @@
+import SettingsRow from '@/components/common/page/SettingsRow';
+import { Input } from '@/components/ui/input';
+import { Switch } from '@/components/ui/switch';
+
+// One state group's auto-archive threshold: the switch that turns archiving on for
+// the group and the day count it waits. The day count stays visible while the group
+// is off, disabled, so the stored value is still readable.
+export default function SettingsAutoArchiveRow({
+ title,
+ description,
+ on,
+ days,
+ editable,
+ onToggle,
+ onDays,
+}: {
+ title: string;
+ description: string;
+ on: boolean;
+ days: string;
+ editable: boolean;
+ onToggle: (v: boolean) => void;
+ onDays: (v: string) => void;
+}) {
+ return (
+ <SettingsRow
+ title={title}
+ description={description}
+ control={
+ <div className="flex shrink-0 items-center gap-3">
+ <Input
+ type="number"
+ min={1}
+ value={days}
+ onChange={(e) => onDays(e.target.value)}
+ disabled={!editable || !on}
+ className="h-8 w-20"
+ />
+ <span className="text-xs text-muted-foreground">days</span>
+ <Switch checked={on} onCheckedChange={onToggle} disabled={!editable} />
+ </div>
+ }
+ />
+ );
+}
diff --git a/apps/web/src/features/settings/components/configuration/SettingsSubtaskAutomation.tsx b/apps/web/src/features/settings/components/configuration/SettingsSubtaskAutomation.tsx
new file mode 100644
index 00000000..f929f057
--- /dev/null
+++ b/apps/web/src/features/settings/components/configuration/SettingsSubtaskAutomation.tsx
@@ -0,0 +1,41 @@
+import SettingsCard from '@/components/common/page/SettingsCard';
+import SettingsSection from '@/components/common/page/SettingsSection';
+import SettingsRow from '@/components/common/page/SettingsRow';
+import { Switch } from '@/components/ui/switch';
+import type { SubtaskAutomationForm } from '../../hooks/useSubtaskAutomationForm';
+
+// The Subtasks block of the Configuration page: the two automations that keep a
+// parent and its subtasks closed together. Both off unless turned on here.
+export default function SettingsSubtaskAutomation({ form }: { form: SubtaskAutomationForm }) {
+ return (
+ <SettingsSection
+ title="Subtasks"
+ description="Only closing is synced. Moving an issue between open states changes nothing else."
+ >
+ <SettingsCard className="divide-y divide-border/60">
+ <SettingsRow
+ title="Close the parent when its subtasks are done"
+ description="The parent moves to the state its last subtask closed in."
+ control={
+ <Switch
+ checked={form.completeParent}
+ disabled={!form.editable}
+ onCheckedChange={form.setCompleteParent}
+ />
+ }
+ />
+ <SettingsRow
+ title="Close subtasks when the parent closes"
+ description="Open subtasks move to the state the parent closed in."
+ control={
+ <Switch
+ checked={form.closeSubtasks}
+ disabled={!form.editable}
+ onCheckedChange={form.setCloseSubtasks}
+ />
+ }
+ />
+ </SettingsCard>
+ </SettingsSection>
+ );
+}
diff --git a/apps/web/src/features/settings/hooks/useAutoArchiveForm.ts b/apps/web/src/features/settings/hooks/useAutoArchiveForm.ts
index f6b7c78c..25249a62 100644
--- a/apps/web/src/features/settings/hooks/useAutoArchiveForm.ts
+++ b/apps/web/src/features/settings/hooks/useAutoArchiveForm.ts
@@ -1,5 +1,4 @@
import { useEffect, useState } from 'react';
-import { toast } from 'sonner';
import { usePermissions } from '@/hooks/usePermissions';
import { useAutoArchiveQuery, useUpdateAutoArchive } from '../services/settings.service';
@@ -12,6 +11,7 @@ const DEFAULT_CANCELED_DAYS = 7;
// reseeds whenever they change (e.g. after a save).
export interface AutoArchiveForm {
editable: boolean;
+ loaded: boolean;
saving: boolean;
save: () => Promise<void>;
completedOn: boolean;
@@ -49,11 +49,11 @@ export function useAutoArchiveForm(projectKey: string): AutoArchiveForm {
: null,
canceledDays: canceledOn ? Math.max(1, Number(canceledDays) || DEFAULT_CANCELED_DAYS) : null,
});
- toast.success('Auto-archive settings saved');
}
return {
- editable: can('auto_archive', 'edit'),
+ editable: can('workflow_config', 'edit'),
+ loaded: settingsQuery.isSuccess,
saving: updateSettings.isPending,
save,
completedOn,
diff --git a/apps/web/src/features/settings/hooks/useSubtaskAutomationForm.ts b/apps/web/src/features/settings/hooks/useSubtaskAutomationForm.ts
new file mode 100644
index 00000000..29238d7b
--- /dev/null
+++ b/apps/web/src/features/settings/hooks/useSubtaskAutomationForm.ts
@@ -0,0 +1,50 @@
+import { useEffect, useState } from 'react';
+import { usePermissions } from '@/hooks/usePermissions';
+import {
+ useSubtaskAutomationQuery,
+ useUpdateSubtaskAutomation,
+} from '../services/settings.service';
+
+// The subtask automation form state, saved by the Configuration page header
+// together with the auto-archive thresholds. Seeds from the stored settings and
+// reseeds whenever they change (e.g. after a save).
+export interface SubtaskAutomationForm {
+ editable: boolean;
+ loaded: boolean;
+ saving: boolean;
+ save: () => Promise<void>;
+ completeParent: boolean;
+ setCompleteParent: (v: boolean) => void;
+ closeSubtasks: boolean;
+ setCloseSubtasks: (v: boolean) => void;
+}
+
+export function useSubtaskAutomationForm(projectKey: string): SubtaskAutomationForm {
+ const { can } = usePermissions();
+ const settingsQuery = useSubtaskAutomationQuery(projectKey);
+ const updateSettings = useUpdateSubtaskAutomation(projectKey);
+
+ const [completeParent, setCompleteParent] = useState(false);
+ const [closeSubtasks, setCloseSubtasks] = useState(false);
+
+ const data = settingsQuery.data;
+ useEffect(() => {
+ setCompleteParent(data?.completeParent ?? false);
+ setCloseSubtasks(data?.closeSubtasks ?? false);
+ }, [data]);
+
+ async function save() {
+ await updateSettings.mutateAsync({ completeParent, closeSubtasks });
+ }
+
+ return {
+ editable: can('workflow_config', 'edit'),
+ loaded: settingsQuery.isSuccess,
+ saving: updateSettings.isPending,
+ save,
+ completeParent,
+ setCompleteParent,
+ closeSubtasks,
+ setCloseSubtasks,
+ };
+}
diff --git a/apps/web/src/features/settings/services/settings.service.ts b/apps/web/src/features/settings/services/settings.service.ts
index 1e4ea675..83663924 100644
--- a/apps/web/src/features/settings/services/settings.service.ts
+++ b/apps/web/src/features/settings/services/settings.service.ts
@@ -1,6 +1,6 @@
// React Query hooks for everything the settings feature reads and writes: the
// project's structural entities (columns, issue types, labels and label groups,
-// custom fields), the auto-archive thresholds, the project notification delivery
+// custom fields), the workflow configuration, the project notification delivery
// settings, and the session member's own notification preferences. Structural
// writes go through useProjectMutation and invalidate the project detail; the
// settings and notification writes return the stored result and put it straight
@@ -13,6 +13,7 @@ import {
type NotificationSettingsPatch,
type NotificationPreferences,
type ProjectFeatures,
+ type SubtaskAutomationSettings,
} from '@/lib/api';
import { useInvalidateProject } from '@/services/projects.service';
import { qk } from '@/services/queryKeys';
@@ -109,7 +110,8 @@ export function useDeleteLabelGroup(projectKey: string) {
return useProjectMutation(projectKey, (id: number) => api.deleteLabelGroup(projectKey, id));
}
-// Archive section: the project's auto-archive thresholds.
+// Configuration section: the project's auto-archive thresholds and subtask
+// automations.
export function useAutoArchiveQuery(projectKey: string) {
return useQuery({
queryKey: qk.autoArchive(projectKey),
@@ -125,6 +127,22 @@ export function useUpdateAutoArchive(projectKey: string) {
});
}
+export function useSubtaskAutomationQuery(projectKey: string) {
+ return useQuery({
+ queryKey: qk.subtaskAutomation(projectKey),
+ queryFn: () => api.getSubtaskAutomation(projectKey),
+ });
+}
+
+export function useUpdateSubtaskAutomation(projectKey: string) {
+ const qc = useQueryClient();
+ return useMutation({
+ mutationFn: (input: SubtaskAutomationSettings) =>
+ api.updateSubtaskAutomation(projectKey, input),
+ onSuccess: (data) => qc.setQueryData(qk.subtaskAutomation(projectKey), data),
+ });
+}
+
// General section: which optional sections the project shows. The current state
// comes with the project payload (getProject), so a write only invalidates it —
// the navigation and the sections themselves read it from there.
diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.ts
index f6c60c57..077e1b98 100644
--- a/apps/web/src/lib/api.ts
+++ b/apps/web/src/lib/api.ts
@@ -88,7 +88,7 @@ export type CopyProjectIncludeKey =
| 'views'
| 'dashboards'
| 'actions'
- | 'archive'
+ | 'configuration'
| 'roles'
| 'notificationProviders'
| 'webhooks'
@@ -575,6 +575,15 @@ export interface AutoArchiveSettings {
canceledDays: number | null;
}
+// Per-project subtask automations, both off by default. completeParent closes a
+// parent once all its subtasks are closed; closeSubtasks closes the remaining
+// subtasks of a closed parent. Only closing is synchronized — an issue moving
+// between open states leaves the rest of the hierarchy alone.
+export interface SubtaskAutomationSettings {
+ completeParent: boolean;
+ closeSubtasks: boolean;
+}
+
// Which optional sections a project shows. All on by default; turning one off
// hides its navigation entry and its section, keeping the rows behind it.
export interface ProjectFeatures {
@@ -1816,7 +1825,7 @@ export type PermissionResource =
| 'agent_skills'
| 'agent_tools'
| 'custom_fields'
- | 'auto_archive'
+ | 'workflow_config'
| 'actions'
| 'webhooks'
| 'note_boards'
@@ -2747,7 +2756,8 @@ export const api = {
body: JSON.stringify(patch),
}),
- // Auto-archive thresholds (auto_archive: read to view, edit to change).
+ // The workflow configuration (workflow_config: read to view, edit to change):
+ // the auto-archive thresholds and the subtask automations.
getAutoArchive: (projectKey: string) =>
request<AutoArchiveSettings>(`/projects/${projectKey}/settings/auto-archive`),
updateAutoArchive: (projectKey: string, input: AutoArchiveSettings) =>
@@ -2755,6 +2765,13 @@ export const api = {
method: 'PATCH',
body: JSON.stringify(input),
}),
+ getSubtaskAutomation: (projectKey: string) =>
+ request<SubtaskAutomationSettings>(`/projects/${projectKey}/settings/subtasks`),
+ updateSubtaskAutomation: (projectKey: string, input: SubtaskAutomationSettings) =>
+ request<SubtaskAutomationSettings>(`/projects/${projectKey}/settings/subtasks`, {
+ method: 'PATCH',
+ body: JSON.stringify(input),
+ }),
// Notification provider credentials (danger_zone: read to view, edit to change).
getNotificationSettings: (projectKey: string) =>
diff --git a/apps/web/src/services/queryKeys.ts b/apps/web/src/services/queryKeys.ts
index 5bec9d1e..65b9243f 100644
--- a/apps/web/src/services/queryKeys.ts
+++ b/apps/web/src/services/queryKeys.ts
@@ -13,8 +13,10 @@ export const qk = {
archivedIssues: (projectKey: string) => ['archivedIssues', projectKey] as const,
// Command-palette issue search, scoped to a project and the search term.
issueSearch: (projectKey: string, q: string) => ['issueSearch', projectKey, q] as const,
- // The project's auto-archive thresholds (the Archive settings section).
+ // The project's auto-archive thresholds and subtask automations (the
+ // Configuration settings section).
autoArchive: (projectKey: string) => ['autoArchive', projectKey] as const,
+ subtaskAutomation: (projectKey: string) => ['subtaskAutomation', projectKey] as const,
// A project's notification delivery settings (the Notifications section).
notificationSettings: (projectKey: string) => ['notificationSettings', projectKey] as const,
notificationPreferences: (projectKey: string) => ['notificationPreferences', projectKey] as const,
diff --git a/apps/web/src/utils/permissions.ts b/apps/web/src/utils/permissions.ts
index 2fabb95f..8bdd5d5a 100644
--- a/apps/web/src/utils/permissions.ts
+++ b/apps/web/src/utils/permissions.ts
@@ -18,7 +18,7 @@ const RESOURCE_LABELS: Record<string, string> = {
agent_skills: 'Agent skills',
agent_tools: 'Agent tools',
custom_fields: 'Custom fields',
- auto_archive: 'Auto-archive',
+ workflow_config: 'Workflow configuration',
actions: 'Actions',
webhooks: 'Webhooks',
note_boards: 'Note boards',
@@ -68,7 +68,7 @@ const GROUP_DEFS: PermissionGroup[] = [
'issue_types',
'labels',
'custom_fields',
- 'auto_archive',
+ 'workflow_config',
'actions',
'webhooks',
],
diff --git a/apps/web/src/utils/settingsSections.ts b/apps/web/src/utils/settingsSections.ts
index 2ec385a4..31bffcbc 100644
--- a/apps/web/src/utils/settingsSections.ts
+++ b/apps/web/src/utils/settingsSections.ts
@@ -1,5 +1,4 @@
import {
- Archive,
Bell,
Bot,
BookText,
@@ -10,6 +9,7 @@ import {
ListPlus,
type LucideIcon,
Shapes,
+ SlidersHorizontal,
Tags,
Webhook,
Wrench,
@@ -91,11 +91,11 @@ export const SETTINGS_SECTIONS: SettingsSection[] = [
group: 'configuration',
},
{
- slug: 'archive',
- label: 'Archive',
- description: 'Auto-archive stale completed and canceled issues so the board stays clear.',
- icon: Archive,
- resource: 'auto_archive',
+ slug: 'configuration',
+ label: 'Configuration',
+ description: 'How subtasks close with their parent, and when stale issues are archived.',
+ icon: SlidersHorizontal,
+ resource: 'workflow_config',
group: 'configuration',
},
{
diff --git a/packages/db/drizzle/0067_rename_auto_archive_permission.sql b/packages/db/drizzle/0067_rename_auto_archive_permission.sql
new file mode 100644
index 00000000..e32cc02b
--- /dev/null
+++ b/packages/db/drizzle/0067_rename_auto_archive_permission.sql
@@ -0,0 +1,8 @@
+-- Custom SQL migration file, put your code below! --
+-- The `auto_archive` permission resource became `workflow_config`: the settings
+-- section it gates now holds the subtask automations alongside the auto-archive
+-- thresholds. Carry each role's flags over under the new key.
+UPDATE "project_role"
+SET "permissions" = ("permissions" - 'auto_archive')
+ || jsonb_build_object('workflow_config', "permissions" -> 'auto_archive')
+WHERE "permissions" ? 'auto_archive';
diff --git a/packages/db/drizzle/meta/_journal.json b/packages/db/drizzle/meta/_journal.json
index c5622cd5..f059783d 100644
--- a/packages/db/drizzle/meta/_journal.json
+++ b/packages/db/drizzle/meta/_journal.json
@@ -470,6 +470,13 @@
"when": 1785961218376,
"tag": "0066_tidy_golden_guardian",
"breakpoints": true
+ },
+ {
+ "idx": 67,
+ "version": "7",
+ "when": 1785961218377,
+ "tag": "0067_rename_auto_archive_permission",
+ "breakpoints": true
}
]
}
\ No newline at end of file