Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
keep a deleted project's slug until it is purged, like environments
DimitrisStaratzis653321d17e9b
diff --git a/backend/e2e-test/routes/v1/project.spec.ts b/backend/e2e-test/routes/v1/project.spec.tsindex bf2c1789df..63c4e793fd 100644--- a/backend/e2e-test/routes/v1/project.spec.ts+++ b/backend/e2e-test/routes/v1/project.spec.ts@@ -106,19 +106,19 @@ describe("Project deletion (soft-delete + async cleanup)", async () => {expect((await listProjects()).some((p) => p.id === project.id)).toBe(false);});- test("frees the slug so a same-slug project can be recreated immediately", async () => {+ test("hardDelete frees the slug so a same-slug project can be recreated immediately", async () => {const slug = "e2e-slug-reuse-test";const first = await createProject("e2e-slug-reuse-1", slug);expect(first.slug).toBe(slug);- expect((await deleteProject(first.id)).statusCode).toBe(200);+ expect((await deleteProject(first.id, true)).statusCode).toBe(200);// recreating with the same slug must succeed (slug was tombstoned on delete)const second = await createProject("e2e-slug-reuse-2", slug);expect(second.slug).toBe(slug);expect(second.id).not.toBe(first.id);- await deleteProject(second.id);+ await deleteProject(second.id, true);});test("cannot delete an already-deleted project", async () => {@@ -144,7 +144,9 @@ describe("Project deletion (soft-delete + async cleanup)", async () => {const deleted = (await listDeletedProjects()).find((p) => p.id === project.id);expect(new Date(deleted?.deleteAfter ?? 0).getTime()).toBeGreaterThan(Date.now() + 13 * 24 * 60 * 60 * 1000);- expect((await restoreProject(project.id)).statusCode).toBe(200);+ const restoreRes = await restoreProject(project.id);+ expect(restoreRes.statusCode).toBe(200);+ expect(JSON.parse(restoreRes.payload).project.slug).toBe(project.slug);expect((await getProject(project.id)).statusCode).toBe(200);expect((await listDeletedProjects()).some((p) => p.id === project.id)).toBe(false);const secret = await getSecretByNameV2({diff --git a/backend/src/services/project/project-dal.ts b/backend/src/services/project/project-dal.tsindex 84aee06f1f..0ac1c8e029 100644--- a/backend/src/services/project/project-dal.ts+++ b/backend/src/services/project/project-dal.ts@@ -131,7 +131,7 @@ export const projectDALFactory = (db: TDbClient) => {}};- const restoreById = async (id: string, slug: string, tx?: Knex) => {+ const restoreById = async (id: string, tx?: Knex) => {try {const [doc] = await (tx || db)(TableName.Project).where({ id })@@ -141,8 +141,7 @@ export const projectDALFactory = (db: TDbClient) => {deleteAfter: null,softDeletedAt: null,deletedByActorType: null,- deletedByActorId: null,- slug+ deletedByActorId: null}).returning("*");return doc as TProjects | undefined;diff --git a/backend/src/services/project/project-service.ts b/backend/src/services/project/project-service.tsindex 425e7fc55f..31c2f56c27 100644--- a/backend/src/services/project/project-service.ts+++ b/backend/src/services/project/project-service.ts@@ -874,7 +874,8 @@ export const projectServiceFactory = ({// This returns immediately (one UPDATE) and the project disappears from every read, but the// expensive cascade runs asynchronously in the hard-delete worker once deleteAfter passes. Only// secret manager projects get a restore grace period; the rest (and hard deletes) are eligible on- // the next worker tick. The slug is freed so a same-named project can be recreated right away.+ // the next worker tick. Like an environment, a restorable project keeps its slug so it comes back+ // unchanged; otherwise the slug is freed so a same-named project can be recreated right away.const now = new Date();const hasGracePeriod = !hardDelete && project.type === ProjectType.SecretManager;const softDeletedProject = await projectDAL.softDeleteById(project.id, {@@ -882,7 +883,7 @@ export const projectServiceFactory = ({softDeletedAt: now,deletedByActorType: actor,deletedByActorId: actorId,- slug: `del-${alphaNumericNanoId(20)}`+ slug: hasGracePeriod ? project.slug : `del-${alphaNumericNanoId(20)}`});if (!softDeletedProject) {@@ -979,10 +980,7 @@ export const projectServiceFactory = ({}}- // The original slug was freed on delete and may have been reused since. Slugifying the name can- // lengthen it, so it is cut after slugifying to stay within the 64-character slug limit.- const slug = slugify(`${slugify(project.name).slice(0, 59)}-${alphaNumericNanoId(4)}`);- return projectDAL.restoreById(project.id, slug, tx);+ return projectDAL.restoreById(project.id, tx);});if (!restoredProject) {diff --git a/frontend/src/pages/organization/ProjectsPage/components/DeletedProjectsTable.tsx b/frontend/src/pages/organization/ProjectsPage/components/DeletedProjectsTable.tsxindex c982d22162..2abc797315 100644--- a/frontend/src/pages/organization/ProjectsPage/components/DeletedProjectsTable.tsx+++ b/frontend/src/pages/organization/ProjectsPage/components/DeletedProjectsTable.tsx@@ -185,7 +185,7 @@ export const DeletedProjectsTable = ({ projectType }: { projectType: ProjectType<AlertDialogTitle>Restore {restoreProjectData?.name ?? "project"}?</AlertDialogTitle><AlertDialogDescription>The project will become accessible again with its secrets, environments, and history- preserved. Its slug was released on deletion, so it gets a new one.+ preserved.</AlertDialogDescription></AlertDialogHeader><AlertDialogFooter>