⭐️⭐️⭐️ 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(api): bound the auto-archive day count (#304)
Ahmad Othman Ammar Adie6ac5c291138
diff --git a/apps/api/src/modules/projects/__tests__/integration/projects.test.ts b/apps/api/src/modules/projects/__tests__/integration/projects.test.tsindex acff5a19..dec3bbff 100644--- a/apps/api/src/modules/projects/__tests__/integration/projects.test.ts+++ b/apps/api/src/modules/projects/__tests__/integration/projects.test.ts@@ -809,6 +809,16 @@ describe('projects', () => {expect(res.status).toBe(400);});+ // The worker subtracts this from now() for every project in one statement, so a+ // day count no interval can carry fails that statement for the whole instance.+ it('rejects a day count no interval can carry', async () => {+ const { api } = await signUpClient();+ await api.projects.post({ key: 'MKT', name: 'Marketing' });++ const res = await autoArchive(api).patch({ completedDays: 3_000_000, canceledDays: 7 });+ expect(res.status).toBe(400);+ });+it('holds the default member role out of the section', async () => {const owner = await signUpClient();await owner.api.projects.post({ key: 'MKT', name: 'Marketing' });diff --git a/apps/api/src/modules/projects/model.ts b/apps/api/src/modules/projects/model.tsindex d25cd561..77bbba8f 100644--- a/apps/api/src/modules/projects/model.ts+++ b/apps/api/src/modules/projects/model.ts@@ -149,6 +149,9 @@ export const updateProjectSettingsBody = t.Object({features: t.Optional(t.Partial(FeaturesResponse)),});+// Ten years, well inside the range make_interval and a timestamp can hold.+export const MAX_AUTO_ARCHIVE_DAYS = 3650;+// Auto-archive thresholds (AutoArchiveSettings from the service): days of inactivity// in a completed/canceled column before the worker archives an issue; null = off.export const AutoArchiveResponse = t.Object({@@ -156,9 +159,12 @@ export const AutoArchiveResponse = t.Object({canceledDays: t.Nullable(t.Number()),});+// The upper bound keeps the value inside what an interval can carry: the worker+// subtracts it from now() for every project in one statement, so a day count large+// enough to overflow a timestamp fails that statement for the whole instance.export const updateAutoArchiveBody = t.Object({- completedDays: t.Nullable(t.Integer({ minimum: 1 })),- canceledDays: t.Nullable(t.Integer({ minimum: 1 })),+ completedDays: t.Nullable(t.Integer({ minimum: 1, maximum: MAX_AUTO_ARCHIVE_DAYS })),+ canceledDays: t.Nullable(t.Integer({ minimum: 1, maximum: MAX_AUTO_ARCHIVE_DAYS })),});// The estimate kinds the project's issues carry and whether its members log timediff --git a/apps/worker/src/store.ts b/apps/worker/src/store.tsindex 0239b63f..e083e1d7 100644--- a/apps/worker/src/store.ts+++ b/apps/worker/src/store.ts@@ -166,11 +166,11 @@ export async function archiveStaleIssues(): Promise<number[]> {AND i.archived_at IS NULLAND ((c.state_type = 'completed'- AND (s.value->>'completedDays') ~ '^[0-9]+$'+ AND (s.value->>'completedDays') ~ '^[0-9]{1,4}$'AND i.updated_at < now() - make_interval(days => (s.value->>'completedDays')::int))OR(c.state_type = 'canceled'- AND (s.value->>'canceledDays') ~ '^[0-9]+$'+ AND (s.value->>'canceledDays') ~ '^[0-9]{1,4}$'AND i.updated_at < now() - make_interval(days => (s.value->>'canceledDays')::int)))RETURNING i.id