The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Restrict staging workspace management and add clearer restriction messages
Kiran Kdf1062d33ee9
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.tsindex 8a118c2d8f..6b697db6ed 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts+++ b/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts@@ -1,6 +1,7 @@import { DubApiError } from "@/lib/api/errors";import { getDubAdminRole, withWorkspace } from "@/lib/auth";import { getDubCustomer } from "@/lib/dub";+import { assertNotStagingWorkspace } from "@/lib/sandbox/workspace-guards";import { stripe } from "@/lib/stripe";import { isEligibleForTrial } from "@/lib/stripe/is-eligible-for-trial";import { booleanQuerySchema } from "@/lib/zod/schemas/misc";@@ -21,6 +22,8 @@ const upgradePlanSchema = z.object({// POST /api/workspaces/[idOrSlug]/billing/upgradeexport const POST = withWorkspace(async ({ req, workspace, session }) => {+ assertNotStagingWorkspace(workspace);+let { plan, period, tier, baseUrl, onboarding } = upgradePlanSchema.parse(await req.json(),);diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsxindex ad11abd9be..83bd2de083 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx@@ -41,6 +41,7 @@ import {nFormatter,} from "@dub/utils";import NumberFlow from "@number-flow/react";+import { WorkspaceEnvironment } from "@prisma/client";import Link from "next/link";import { CSSProperties, ReactNode, useMemo } from "react";import { toast } from "sonner";@@ -76,6 +77,7 @@ export default function PlanUsage() {trialEndsAt,subscriptionCanceledAt,billingCycleEndsAt,+ environment,mutate,} = useWorkspace();@@ -84,6 +86,17 @@ export default function PlanUsage() {role,}).error;+ const { error: managePlanStagingError } = clientAccessCheck({+ action: "billing.write",+ role,+ environment,+ restrictedEnvironments: [WorkspaceEnvironment.staging],+ restrictedEnvironmentMessage:+ "Plans can only be managed from your production workspace (your staging workspace inherits your production plan).",+ });++ const managePlanError = permissionsError || managePlanStagingError;+const { StartPaidPlanModal, setShowStartPaidPlanModal } =useStartPaidPlanModal();@@ -318,13 +331,28 @@ export default function PlanUsage() {/></DynamicTooltipWrapper>) : (- <Link href={`/${slug}/settings/billing/upgrade`}>- <Button- text="Manage plan"- variant="primary"- className="h-9"- />- </Link>+ <DynamicTooltipWrapper+ tooltipProps={+ managePlanError ? { content: managePlanError } : undefined+ }+ >+ {managePlanError ? (+ <Button+ text="Manage plan"+ variant="primary"+ className="h-9"+ disabled+ />+ ) : (+ <Link href={`/${slug}/settings/billing/upgrade`}>+ <Button+ text="Manage plan"+ variant="primary"+ className="h-9"+ />+ </Link>+ )}+ </DynamicTooltipWrapper>))}<Linkdiff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/members/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/members/page.tsxindex 0129875d8b..0ad98894b4 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/members/page.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/members/page.tsx@@ -277,6 +277,8 @@ export default function WorkspaceMembersPage() {environment,customPermissionDescription: "invite new teammates",restrictedEnvironments: [WorkspaceEnvironment.staging],+ restrictedEnvironmentMessage:+ "Teammates can only be invited from your production workspace (members are automatically synced to staging).",});const { error: generateInviteLinksError } = clientAccessCheck({@@ -285,6 +287,8 @@ export default function WorkspaceMembersPage() {environment,customPermissionDescription: "generate invite links",restrictedEnvironments: [WorkspaceEnvironment.staging],+ restrictedEnvironmentMessage:+ "Invite links can only be generated from your production workspace (members are automatically synced to staging).",});return (@@ -487,8 +491,9 @@ function RowMenuButton({const isCurrentUser = session?.user?.email === user.email;- // In staging, only show menu for self (leave workspace)- if (isStagingEnvironment(environment) && !isCurrentUser) {+ // Leave workspace and member management are not available in staging+ // (members are managed from the production workspace)+ if (isStagingEnvironment(environment)) {return null;}diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/page-client.tsxindex 9f34fc2622..ce2ff024be 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/page-client.tsx@@ -21,6 +21,8 @@ export default function WorkspaceSettingsClient() {role,environment,restrictedEnvironments: [WorkspaceEnvironment.staging],+ restrictedEnvironmentMessage:+ "Workspace settings must be updated from your production workspace (changes are automatically synced to staging).",});const { update } = useSession();diff --git a/apps/web/lib/sandbox/create-staging-workspace.ts b/apps/web/lib/sandbox/create-staging-workspace.tsindex 0d257330dc..de337348a2 100644--- a/apps/web/lib/sandbox/create-staging-workspace.ts+++ b/apps/web/lib/sandbox/create-staging-workspace.ts@@ -160,7 +160,7 @@ export async function queueCreateStagingWorkspace({await qstash.publishJSON({url: `${APP_DOMAIN_WITH_NGROK}/api/cron/workspaces/create-staging`,- deduplicationId: `create-staging-workspace:${id}`,+ deduplicationId: `create-staging-workspace-${id}`,body: {workspaceId: id,},diff --git a/apps/web/ui/workspaces/delete-workspace.tsx b/apps/web/ui/workspaces/delete-workspace.tsxindex e3a61f6df4..94390a32d6 100644--- a/apps/web/ui/workspaces/delete-workspace.tsx+++ b/apps/web/ui/workspaces/delete-workspace.tsx@@ -18,6 +18,8 @@ export default function DeleteWorkspace() {role,environment,restrictedEnvironments: [WorkspaceEnvironment.staging],+ restrictedEnvironmentMessage:+ "Deleting a staging workspace is not allowed.",});return (diff --git a/apps/web/ui/workspaces/upload-logo.tsx b/apps/web/ui/workspaces/upload-logo.tsxindex 51b4196a80..0a91f88931 100644--- a/apps/web/ui/workspaces/upload-logo.tsx+++ b/apps/web/ui/workspaces/upload-logo.tsx@@ -22,6 +22,8 @@ export default function UploadLogo() {role,environment,restrictedEnvironments: [WorkspaceEnvironment.staging],+ restrictedEnvironmentMessage:+ "Your workspace logo must be updated from your production workspace (changes are automatically synced to staging).",});return (