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: gate the archive settings section by its own permission (#81)

Croff09c0e90b8811
diff --git a/apps/api/src/projects/__tests__/integration/projects.test.ts b/apps/api/src/projects/__tests__/integration/projects.test.ts
index e6325a91..c94f9484 100644
--- a/apps/api/src/projects/__tests__/integration/projects.test.ts
+++ b/apps/api/src/projects/__tests__/integration/projects.test.ts
@@ -23,6 +23,18 @@ async function signUpClient() {
return { user, api: authedApi(user.cookie) };
}
+// Adds a member to project MKT through the invite flow, on the default member role
+// unless a custom one is named. Returns a Treaty client acting as them.
+async function addMember(owner: Api, roleId?: number) {
+ const user = await signUpTestUser();
+ const invite = await owner
+ .projects({ projectKey: 'MKT' })
+ .invites.post({ email: user.email, role: 'member', roleId });
+ const api = authedApi(user.cookie);
+ await api.invites({ token: invite.data!.token }).accept.post();
+ return api;
+}
+
async function viewOf(client: Api, projectKey: string) {
return client.projects({ projectKey }).get();
}
@@ -565,16 +577,13 @@ describe('projects', () => {
});
describe('settings', () => {
- it('defaults a new project to MCP off and the default auto-archive thresholds', async () => {
+ it('defaults a new project to MCP off', async () => {
const { api } = await signUpClient();
await api.projects.post({ key: 'MKT', name: 'Marketing' });
const res = await api.projects({ projectKey: 'MKT' }).settings.get();
expect(res.status).toBe(200);
- expect(res.data).toMatchObject({
- mcpEnabled: false,
- autoArchive: { completedDays: 28, canceledDays: 7 },
- });
+ expect(res.data).toMatchObject({ mcpEnabled: false });
});
it('starts a new project with every optional section enabled', async () => {
@@ -627,54 +636,108 @@ describe('projects', () => {
expect(res.status).toBe(403);
});
- it('lets an owner set and read back the auto-archive thresholds', async () => {
+ it('changes only the supplied field, leaving the other', async () => {
const { api } = await signUpClient();
await api.projects.post({ key: 'MKT', name: 'Marketing' });
+ await api.projects({ projectKey: 'MKT' }).settings.patch({ features: { notes: false } });
+
+ const res = await api.projects({ projectKey: 'MKT' }).settings.patch({ mcpEnabled: true });
+ expect(res.data).toMatchObject({ mcpEnabled: true, features: { notes: false } });
+ });
- const patch = await api
+ it('denies writing settings to a non-owner (owner-only)', async () => {
+ const owner = await signUpClient();
+ await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });
+
+ const outsider = await signUpClient();
+ const res = await outsider.api
.projects({ projectKey: 'MKT' })
- .settings.patch({ autoArchive: { completedDays: 28, canceledDays: 7 } });
+ .settings.patch({ mcpEnabled: true });
+ expect(res.status).toBe(403);
+ });
+ });
+
+ describe('auto-archive settings', () => {
+ const autoArchive = (client: Api) =>
+ client.projects({ projectKey: 'MKT' }).settings['auto-archive'];
+
+ it('defaults a new project to the default thresholds', async () => {
+ const { api } = await signUpClient();
+ await api.projects.post({ key: 'MKT', name: 'Marketing' });
+
+ const res = await autoArchive(api).get();
+ expect(res.status).toBe(200);
+ expect(res.data).toMatchObject({ completedDays: 28, canceledDays: 7 });
+ });
+
+ it('lets an owner set and read back the thresholds', async () => {
+ const { api } = await signUpClient();
+ await api.projects.post({ key: 'MKT', name: 'Marketing' });
+
+ const patch = await autoArchive(api).patch({ completedDays: 14, canceledDays: 3 });
expect(patch.status).toBe(200);
- expect(patch.data?.autoArchive).toMatchObject({ completedDays: 28, canceledDays: 7 });
+ expect(patch.data).toMatchObject({ completedDays: 14, canceledDays: 3 });
- const get = await api.projects({ projectKey: 'MKT' }).settings.get();
- expect(get.data?.autoArchive).toMatchObject({ completedDays: 28, canceledDays: 7 });
+ expect((await autoArchive(api).get()).data).toMatchObject({
+ completedDays: 14,
+ canceledDays: 3,
+ });
});
it('stores null to disable a state group', async () => {
const { api } = await signUpClient();
await api.projects.post({ key: 'MKT', name: 'Marketing' });
- const res = await api
- .projects({ projectKey: 'MKT' })
- .settings.patch({ autoArchive: { completedDays: 30, canceledDays: null } });
+ const res = await autoArchive(api).patch({ completedDays: 30, canceledDays: null });
expect(res.status).toBe(200);
- expect(res.data?.autoArchive).toMatchObject({ completedDays: 30, canceledDays: null });
+ expect(res.data).toMatchObject({ completedDays: 30, canceledDays: null });
});
- it('changes only the supplied field, leaving the other', async () => {
+ it('rejects a day count below 1', async () => {
const { api } = await signUpClient();
await api.projects.post({ key: 'MKT', name: 'Marketing' });
- await api
- .projects({ projectKey: 'MKT' })
- .settings.patch({ autoArchive: { completedDays: 14, canceledDays: 3 } });
- const res = await api.projects({ projectKey: 'MKT' }).settings.patch({ mcpEnabled: true });
- expect(res.data).toMatchObject({
- mcpEnabled: true,
- autoArchive: { completedDays: 14, canceledDays: 3 },
- });
+ const res = await autoArchive(api).patch({ completedDays: 0, canceledDays: 7 });
+ expect(res.status).toBe(400);
});
- it('denies writing settings to a non-owner (owner-only)', async () => {
+ 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);
- const outsider = await signUpClient();
- const res = await outsider.api
+ expect((await autoArchive(member).get()).status).toBe(403);
+ expect((await autoArchive(member).patch({ completedDays: 14, canceledDays: 3 })).status).toBe(
+ 403,
+ );
+ });
+
+ it('lets a granted role read the thresholds 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' })
- .settings.patch({ autoArchive: { completedDays: 28, canceledDays: 7 } });
- expect(res.status).toBe(403);
+ .roles.post({ name: 'Reader', permissions: { auto_archive: { read: true } } });
+ const member = await addMember(owner.api, role.data!.id);
+
+ expect((await autoArchive(member).get()).status).toBe(200);
+ expect((await autoArchive(member).patch({ completedDays: 14, canceledDays: 3 })).status).toBe(
+ 403,
+ );
+ });
+
+ it('lets a role with edit change the thresholds', 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: 'Archivist',
+ permissions: { auto_archive: { read: true, edit: true } },
+ });
+ const member = await addMember(owner.api, role.data!.id);
+
+ const res = await autoArchive(member).patch({ completedDays: 14, canceledDays: 3 });
+ expect(res.status).toBe(200);
+ expect(res.data).toMatchObject({ completedDays: 14, canceledDays: 3 });
});
});
});
diff --git a/apps/api/src/projects/routes.ts b/apps/api/src/projects/routes.ts
index 8d17874d..64e6b959 100644
--- a/apps/api/src/projects/routes.ts
+++ b/apps/api/src/projects/routes.ts
@@ -173,12 +173,10 @@ const FeaturesResponse = t.Object({
notes: t.Boolean(),
});
-// The project's settings: MCP reachability, the enabled sections and the
-// auto-archive thresholds.
+// The project's settings: MCP reachability and the enabled sections.
const ProjectSettingsResponse = t.Object({
mcpEnabled: t.Boolean(),
features: FeaturesResponse,
- autoArchive: AutoArchiveResponse,
});
// The caller's own role in a project (from MemberContext in members/store). The
@@ -383,16 +381,13 @@ export const projectRoutes = new Elysia({ name: 'projects', detail: { tags: ['Pr
},
)
- // Reads the project's settings: whether it is reachable over MCP, which optional
- // sections are enabled, and the auto-archive thresholds (days of inactivity in a
- // completed/canceled column before the worker archives an issue; null = off).
- // Any member may read.
+ // Reads the project's settings: whether it is reachable over MCP and which
+ // optional sections are enabled. Any member may read.
.get(
'/projects/:projectKey/settings',
- async ({ project }) => ({
+ ({ project }) => ({
mcpEnabled: project.mcpEnabled,
features: projectFeatures(project),
- autoArchive: await getAutoArchiveSettings(project.id),
}),
{
projectMember: true,
@@ -408,10 +403,8 @@ export const projectRoutes = new Elysia({ name: 'projects', detail: { tags: ['Pr
// Updates the project's settings. Each field is optional; only the supplied ones
// change. mcpEnabled toggles MCP access to the project. features turns the
- // optional sections (initiatives, dashboards, notes) on or off. autoArchive sets
- // the day count per state group (positive integer) or disables it (null).
- // Owner-only. Not an MCP tool: it governs MCP access, so an agent must not
- // change it.
+ // optional sections (initiatives, dashboards, notes) on or off. Owner-only. Not
+ // an MCP tool: it governs MCP access, so an agent must not change it.
.patch(
'/projects/:projectKey/settings',
async ({ project, body }) => {
@@ -426,11 +419,7 @@ export const projectRoutes = new Elysia({ name: 'projects', detail: { tags: ['Pr
if (!updated) throw new HttpError(404, 'Project not found');
current = updated;
}
- const autoArchive =
- body.autoArchive !== undefined
- ? await setAutoArchiveSettings(project.id, body.autoArchive)
- : await getAutoArchiveSettings(project.id);
- return { mcpEnabled: current.mcpEnabled, features: projectFeatures(current), autoArchive };
+ return { mcpEnabled: current.mcpEnabled, features: projectFeatures(current) };
},
{
body: t.Object({
@@ -442,12 +431,6 @@ export const projectRoutes = new Elysia({ name: 'projects', detail: { tags: ['Pr
notes: t.Optional(t.Boolean()),
}),
),
- autoArchive: t.Optional(
- t.Object({
- completedDays: t.Nullable(t.Integer({ minimum: 1 })),
- canceledDays: t.Nullable(t.Integer({ minimum: 1 })),
- }),
- ),
}),
projectOwner: true,
response: {
@@ -461,6 +444,46 @@ 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.
+ .get(
+ '/projects/:projectKey/settings/auto-archive',
+ ({ project }) => getAutoArchiveSettings(project.id),
+ {
+ permission: ['auto_archive', 'read'],
+ response: {
+ 200: AutoArchiveResponse,
+ 401: ErrorResponse,
+ 403: ErrorResponse,
+ 404: ErrorResponse,
+ },
+ detail: { summary: "Get a project's auto-archive thresholds" },
+ },
+ )
+
+ // Sets both thresholds at once: a partial body would read as "leave the other
+ // group as it is", which this endpoint does not do.
+ .patch(
+ '/projects/:projectKey/settings/auto-archive',
+ ({ project, body }) => setAutoArchiveSettings(project.id, body),
+ {
+ body: t.Object({
+ completedDays: t.Nullable(t.Integer({ minimum: 1 })),
+ canceledDays: t.Nullable(t.Integer({ minimum: 1 })),
+ }),
+ permission: ['auto_archive', 'edit'],
+ response: {
+ 200: AutoArchiveResponse,
+ 400: ErrorResponse,
+ 401: ErrorResponse,
+ 403: ErrorResponse,
+ 404: ErrorResponse,
+ },
+ detail: { summary: "Update a project's auto-archive thresholds" },
+ },
+ )
+
// Permanently removes the project and everything scoped to it. Irreversible.
// Owner-only.
.delete(
diff --git a/apps/api/src/shared/permissions.ts b/apps/api/src/shared/permissions.ts
index 3eb2da8a..7f84b582 100644
--- a/apps/api/src/shared/permissions.ts
+++ b/apps/api/src/shared/permissions.ts
@@ -18,6 +18,7 @@ export const PERMISSION_RESOURCES = [
'agent_skills',
'agent_tools',
'custom_fields',
+ 'auto_archive',
'actions',
'webhooks',
'note_boards',
diff --git a/apps/web/src/features/settings/components/archive/SettingsArchive.tsx b/apps/web/src/features/settings/components/archive/SettingsArchive.tsx
index 059f58fc..ec1ede55 100644
--- a/apps/web/src/features/settings/components/archive/SettingsArchive.tsx
+++ b/apps/web/src/features/settings/components/archive/SettingsArchive.tsx
@@ -2,7 +2,6 @@ import { Input } from '@/components/ui/input';
import { Switch } from '@/components/ui/switch';
import type { AutoArchiveForm } from '../../hooks/useAutoArchiveForm';
-// Only an owner may edit; others see the values read-only.
export default function SettingsArchive({ form }: { form: AutoArchiveForm }) {
return (
<section className="flex flex-col gap-4">
diff --git a/apps/web/src/features/settings/hooks/useAutoArchiveForm.ts b/apps/web/src/features/settings/hooks/useAutoArchiveForm.ts
index 9ec0083a..f6b7c78c 100644
--- a/apps/web/src/features/settings/hooks/useAutoArchiveForm.ts
+++ b/apps/web/src/features/settings/hooks/useAutoArchiveForm.ts
@@ -25,7 +25,7 @@ export interface AutoArchiveForm {
}
export function useAutoArchiveForm(projectKey: string): AutoArchiveForm {
- const { isOwner } = usePermissions();
+ const { can } = usePermissions();
const settingsQuery = useAutoArchiveQuery(projectKey);
const updateSettings = useUpdateAutoArchive(projectKey);
@@ -53,7 +53,7 @@ export function useAutoArchiveForm(projectKey: string): AutoArchiveForm {
}
return {
- editable: isOwner,
+ editable: can('auto_archive', 'edit'),
saving: updateSettings.isPending,
save,
completedOn,
diff --git a/apps/web/src/features/settings/services/settings.service.ts b/apps/web/src/features/settings/services/settings.service.ts
index 9ac7ad8f..1e4ea675 100644
--- a/apps/web/src/features/settings/services/settings.service.ts
+++ b/apps/web/src/features/settings/services/settings.service.ts
@@ -109,22 +109,19 @@ export function useDeleteLabelGroup(projectKey: string) {
return useProjectMutation(projectKey, (id: number) => api.deleteLabelGroup(projectKey, id));
}
-// Archive section: the project's auto-archive thresholds, read from the project
-// settings resource and narrowed to the autoArchive part for this section.
+// Archive section: the project's auto-archive thresholds.
export function useAutoArchiveQuery(projectKey: string) {
return useQuery({
- queryKey: qk.projectSettings(projectKey),
- queryFn: () => api.getProjectSettings(projectKey),
- select: (s) => s.autoArchive,
+ queryKey: qk.autoArchive(projectKey),
+ queryFn: () => api.getAutoArchive(projectKey),
});
}
export function useUpdateAutoArchive(projectKey: string) {
const qc = useQueryClient();
return useMutation({
- mutationFn: (input: AutoArchiveSettings) =>
- api.updateProjectSettings(projectKey, { autoArchive: input }),
- onSuccess: (data) => qc.setQueryData(qk.projectSettings(projectKey), data),
+ mutationFn: (input: AutoArchiveSettings) => api.updateAutoArchive(projectKey, input),
+ onSuccess: (data) => qc.setQueryData(qk.autoArchive(projectKey), data),
});
}
diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.ts
index 5e789f27..d5d29221 100644
--- a/apps/web/src/lib/api.ts
+++ b/apps/web/src/lib/api.ts
@@ -555,7 +555,7 @@ export interface IssueSearchHit {
// Per-project auto-archive thresholds: days an issue may sit inactive in a
// completed/canceled column before the worker archives it. null disables archiving
-// for that state group. Both null by default (nothing is archived until enabled).
+// for that state group. A new project starts at 28 completed / 7 canceled days.
export interface AutoArchiveSettings {
completedDays: number | null;
canceledDays: number | null;
@@ -569,12 +569,10 @@ export interface ProjectFeatures {
notes: boolean;
}
-// A project's settings: MCP reachability, the enabled sections and the
-// auto-archive thresholds.
+// A project's settings: MCP reachability and the enabled sections.
export interface ProjectSettings {
mcpEnabled: boolean;
features: ProjectFeatures;
- autoArchive: AutoArchiveSettings;
}
// Per-project notification provider credentials (owner-managed) plus a member's own
@@ -1676,6 +1674,7 @@ export type PermissionResource =
| 'agent_skills'
| 'agent_tools'
| 'custom_fields'
+ | 'auto_archive'
| 'actions'
| 'webhooks'
| 'note_boards'
@@ -2505,23 +2504,27 @@ export const api = {
`/webhooks/${webhookId}/deliveries?limit=25${before ? `&before=${before}` : ''}`,
),
- // Project settings: MCP reachability and auto-archive thresholds. Any member
- // reads; owner writes. The PATCH takes only the fields being changed.
- getProjectSettings: (projectKey: string) =>
- request<ProjectSettings>(`/projects/${projectKey}/settings`),
+ // Project settings: MCP reachability and the enabled sections. Owner-only; the
+ // current state comes with the project payload (getProject), so there is no read
+ // here.
updateProjectSettings: (
projectKey: string,
- patch: {
- mcpEnabled?: boolean;
- features?: Partial<ProjectFeatures>;
- autoArchive?: AutoArchiveSettings;
- },
+ patch: { mcpEnabled?: boolean; features?: Partial<ProjectFeatures> },
) =>
request<ProjectSettings>(`/projects/${projectKey}/settings`, {
method: 'PATCH',
body: JSON.stringify(patch),
}),
+ // Auto-archive thresholds (auto_archive: read to view, edit to change).
+ getAutoArchive: (projectKey: string) =>
+ request<AutoArchiveSettings>(`/projects/${projectKey}/settings/auto-archive`),
+ updateAutoArchive: (projectKey: string, input: AutoArchiveSettings) =>
+ request<AutoArchiveSettings>(`/projects/${projectKey}/settings/auto-archive`, {
+ method: 'PATCH',
+ body: JSON.stringify(input),
+ }),
+
// Notification provider credentials (danger_zone: read to view, edit to change).
getNotificationSettings: (projectKey: string) =>
request<NotificationSettings>(`/projects/${projectKey}/notification-settings`),
diff --git a/apps/web/src/services/queryKeys.ts b/apps/web/src/services/queryKeys.ts
index fad59ccf..a2cd287e 100644
--- a/apps/web/src/services/queryKeys.ts
+++ b/apps/web/src/services/queryKeys.ts
@@ -9,11 +9,12 @@ export const qk = {
// Split from the scaffold so issue writes and live-refresh touch only the
// issues, not the scaffold.
boardIssues: (projectKey: string) => ['boardIssues', projectKey] as const,
- // A project's archived issues and its auto-archive settings (the Archive section).
+ // A project's archived issues.
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,
- projectSettings: (projectKey: string) => ['projectSettings', projectKey] as const,
+ // The project's auto-archive thresholds (the Archive settings section).
+ autoArchive: (projectKey: string) => ['autoArchive', 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 9d8aaf97..9605af78 100644
--- a/apps/web/src/utils/permissions.ts
+++ b/apps/web/src/utils/permissions.ts
@@ -17,6 +17,7 @@ const RESOURCE_LABELS: Record<string, string> = {
agent_skills: 'Agent skills',
agent_tools: 'Agent tools',
custom_fields: 'Custom fields',
+ auto_archive: 'Auto-archive',
actions: 'Actions',
webhooks: 'Webhooks',
note_boards: 'Note boards',
@@ -61,7 +62,15 @@ const GROUP_DEFS: PermissionGroup[] = [
{ title: 'AI', resources: ['ai_agents', 'integrations', 'agent_skills', 'agent_tools'] },
{
title: 'Configuration',
- resources: ['states', 'issue_types', 'labels', 'custom_fields', 'actions', 'webhooks'],
+ resources: [
+ 'states',
+ 'issue_types',
+ 'labels',
+ 'custom_fields',
+ 'auto_archive',
+ 'actions',
+ 'webhooks',
+ ],
},
{ title: 'Members', resources: ['members_manage', 'members_invite'] },
{ title: 'Project', resources: ['danger_zone'] },
diff --git a/apps/web/src/utils/settingsSections.ts b/apps/web/src/utils/settingsSections.ts
index 15b35f63..2ec385a4 100644
--- a/apps/web/src/utils/settingsSections.ts
+++ b/apps/web/src/utils/settingsSections.ts
@@ -95,7 +95,7 @@ export const SETTINGS_SECTIONS: SettingsSection[] = [
label: 'Archive',
description: 'Auto-archive stale completed and canceled issues so the board stays clear.',
icon: Archive,
- resource: 'work_items',
+ resource: 'auto_archive',
group: 'configuration',
},
{