Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Prevent staging workspace deletion and clear staging reference on delete

Kiran K57c69cdf477d
diff --git a/apps/web/app/(ee)/api/cron/workspaces/create-staging/route.ts b/apps/web/app/(ee)/api/cron/workspaces/create-staging/route.ts
index 5759a91b6e..cc48fb2593 100644
--- a/apps/web/app/(ee)/api/cron/workspaces/create-staging/route.ts
+++ b/apps/web/app/(ee)/api/cron/workspaces/create-staging/route.ts
@@ -17,5 +17,7 @@ export const POST = withCron(async ({ rawBody }) => {
await createStagingWorkspace(workspaceId);
await createStagingProgram(workspaceId);
- return logAndRespond("OK");
+ return logAndRespond(
+ `Staging workspace and program created for workspace ${workspaceId}`,
+ );
});
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/route.ts
index 533e66ab32..ab2ac76f03 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/route.ts
@@ -3,8 +3,8 @@ import { DubApiError } from "@/lib/api/errors";
import { parseRequestBody } from "@/lib/api/utils";
import { validateAllowedHostnames } from "@/lib/api/validate-allowed-hostnames";
import { deleteWorkspace } from "@/lib/api/workspaces/delete-workspace";
-import { getWorkspaceLogoKeyPrefix } from "@/lib/api/workspaces/workspace-logo";
import { prefixWorkspaceId } from "@/lib/api/workspaces/workspace-id";
+import { getWorkspaceLogoKeyPrefix } from "@/lib/api/workspaces/workspace-logo";
import { withWorkspace } from "@/lib/auth";
import { getFeatureFlags } from "@/lib/edge-config";
import { jackson } from "@/lib/jackson";
@@ -312,7 +312,9 @@ export const DELETE = withWorkspace(
});
}
- assertNotStagingWorkspace(workspace);
+ assertNotStagingWorkspace(workspace, {
+ message: "Deleting a staging workspace is not allowed.",
+ });
await deleteWorkspace(workspace);
diff --git a/apps/web/lib/api/workspaces/delete-workspace.ts b/apps/web/lib/api/workspaces/delete-workspace.ts
index 1f623ac391..ac2a9ee854 100644
--- a/apps/web/lib/api/workspaces/delete-workspace.ts
+++ b/apps/web/lib/api/workspaces/delete-workspace.ts
@@ -67,6 +67,15 @@ export async function deleteWorkspace(
},
},
}),
+
+ prisma.project.update({
+ where: {
+ id: workspace.id,
+ },
+ data: {
+ stagingWorkspaceId: null,
+ },
+ }),
]);
waitUntil(
diff --git a/apps/web/lib/sandbox/create-staging-workspace.ts b/apps/web/lib/sandbox/create-staging-workspace.ts
index 1615f9ac82..0e414cc063 100644
--- a/apps/web/lib/sandbox/create-staging-workspace.ts
+++ b/apps/web/lib/sandbox/create-staging-workspace.ts
@@ -31,7 +31,7 @@ export async function createStagingWorkspace(workspaceId: string) {
if (!isProductionEnvironment(workspace.environment)) {
console.error(
- `Skipping staging creation for non-production workspace ${workspace.id}.`,
+ `Skipping staging workspace creation for non-production workspace ${workspace.id}.`,
);
return;
}
@@ -65,6 +65,7 @@ export async function createStagingWorkspace(workspaceId: string) {
plan: workspace.plan,
billingCycleStart: new Date().getDate(),
invoicePrefix: generateRandomString(8),
+ // Staging workspace will uses the trial limits
usageLimit: TRIAL_LIMITS.clicks,
linksLimit: TRIAL_LIMITS.links,
domainsLimit: TRIAL_LIMITS.domains,