From 2586e76fee1fd2c61c5128a53cd5274499de10f2 Mon Sep 17 00:00:00 2001 From: Wei Hai Date: Wed, 26 Aug 2026 11:22:01 +0000 Subject: [PATCH 1/2] fix(billing): restore Resubscribe on the legacy rail and centralize the policy (#15967) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### The bug The cancelled-plan **Resubscribe** action was gated on the server-resolved `can_reactivate`. `legacy_stripe` workspaces have no capability projection row, so it resolves `false` for them and the button disappears for customers who should have it. `CurrentUserPopoverWorkspace` was the third and last site with this problem — the follow-up promised on the #15675 review thread, which deliberately left this file out of scope. ### The refactor (added in review) Fixing the third site would have made a third verbatim copy of the same expression, so per review feedback the policy is now centralized instead of duplicated in views. `useWorkspaceUI` — which already owns `permissions` — exposes one derived value: ```ts // legacy_stripe workspaces have no capability projection row, so the // server-resolved can_reactivate is false for them and cannot gate the // action; that rail stays on the membership check. const canReactivatePlan = computed(() => isCloud && shouldUseWorkspaceBilling.value ? canReactivate.value : permissions.value.canManageSubscriptionLifecycle ) ``` `SubscriptionPanelContentWorkspace`, `BillingStatusBanner` and `CurrentUserPopoverWorkspace` all consume it; their local copies and now-unused `useBillingRouting` / `isCloud` imports are gone. So the third site is fixed **and** the pre-existing duplication is removed. No import cycle — neither `useBillingRouting` nor `useBillingCapabilities` imports `useWorkspaceUI`. ### Deliberately not folded in `useWorkspaceMenuItems` has a similar-looking expression for **cancel**, but it carries an extra free-tier guard (`can_cancel` stays true for an active FREE plan). Same shape, different policy — left alone. ### Verification - Policy tests live in `useWorkspaceUI.test.ts` now, where the policy does: consolidated rail (uses the capability), legacy rail, and off-Cloud (both fall back to membership). Verified they actually bite by stubbing the policy out — **2 failed**. - The off-Cloud case is new: `isCloud` is `false` by default under vitest and the composable test wasn't mocking it, so that branch had never been exercised. - Component tests keep their behavioural cases and drive the shared value. - On this head: `pnpm typecheck` clean; **127 passing** across the four affected files; full suite `1317/1318` files green — the only failures are 12 pre-existing `check-binary-size` cases that fail independently of this change. (cherry picked from commit 0c89141b3ef3772b38722cad7153d2e861abe309) --- .../CurrentUserPopoverWorkspace.test.ts | 32 +++++++++- .../CurrentUserPopoverWorkspace.vue | 12 ++-- .../SubscriptionPanelContentWorkspace.test.ts | 4 +- .../SubscriptionPanelContentWorkspace.vue | 17 ++--- .../settings/BillingStatusBanner.test.ts | 8 ++- .../dialogs/settings/BillingStatusBanner.vue | 13 +--- .../composables/useWorkspaceUI.test.ts | 64 ++++++++++++++++++- .../workspace/composables/useWorkspaceUI.ts | 16 +++++ 8 files changed, 131 insertions(+), 35 deletions(-) diff --git a/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts b/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts index b83494babc1..9e68a4499cd 100644 --- a/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts +++ b/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts @@ -22,6 +22,8 @@ const state = vi.hoisted(() => ({ canManageSubscription: false, canManageSubscriptionLifecycle: false, canReactivate: false, + canReactivatePlan: false, + shouldUseWorkspaceBilling: true, showCreateWorkspaceDialog: vi.fn(), showTopUpCreditsDialog: vi.fn(), showPricingTable: vi.fn(), @@ -76,7 +78,8 @@ vi.mock('@/platform/workspace/composables/useWorkspaceUI', () => ({ permissions: computed(() => ({ canManageSubscription: state.canManageSubscription, canManageSubscriptionLifecycle: state.canManageSubscriptionLifecycle - })) + })), + canReactivatePlan: computed(() => state.canReactivatePlan) }) })) @@ -88,6 +91,12 @@ vi.mock('@/platform/workspace/composables/useBillingCapabilities', () => ({ }) })) +vi.mock('@/composables/billing/useBillingRouting', () => ({ + useBillingRouting: () => ({ + shouldUseWorkspaceBilling: computed(() => state.shouldUseWorkspaceBilling) + }) +})) + vi.mock( '@/platform/cloud/subscription/composables/useSubscriptionDialog', () => ({ @@ -190,6 +199,7 @@ describe('CurrentUserPopoverWorkspace', () => { state.canManageSubscription = false state.canManageSubscriptionLifecycle = false state.canReactivate = false + state.shouldUseWorkspaceBilling = true }) it('toggles the workspace switcher panel from the selector row', async () => { @@ -506,7 +516,7 @@ describe('CurrentUserPopoverWorkspace', () => { state.isCancelled = isCancelled state.canManageSubscription = canManageSubscription state.canManageSubscriptionLifecycle = canManageSubscriptionLifecycle - state.canReactivate = canReactivate + state.canReactivatePlan = canReactivate state.canSubscribeSelfServe = canSubscribeSelfServe renderComponent('team') @@ -526,7 +536,7 @@ describe('CurrentUserPopoverWorkspace', () => { state.canTopUp = true state.canManageSubscription = true state.canManageSubscriptionLifecycle = true - state.canReactivate = true + state.canReactivatePlan = true renderComponent('team') expect(screen.getByTestId('add-credits-button')).toBeInTheDocument() @@ -538,6 +548,22 @@ describe('CurrentUserPopoverWorkspace', () => { expect(state.showPricingTable).toHaveBeenCalledOnce() }) + it('reads the derived reactivate policy, not the raw server capability', () => { + state.isCancelled = true + state.canManageSubscriptionLifecycle = true + // The legacy rail resolves can_reactivate false but still permits + // reactivation, so the button must follow canReactivatePlan. Rail + // selection itself is covered in useWorkspaceUI.test.ts. + state.canReactivate = false + state.canReactivatePlan = true + + renderComponent('personal') + + expect( + screen.getByRole('button', { name: 'Resubscribe' }) + ).toBeInTheDocument() + }) + for (const workspaceType of ['personal', 'team'] as const) { it(`opens workspace plan management for a ${workspaceType} owner`, async () => { const user = userEvent.setup() diff --git a/src/platform/workspace/components/CurrentUserPopoverWorkspace.vue b/src/platform/workspace/components/CurrentUserPopoverWorkspace.vue index cb582279fe6..689792b581f 100644 --- a/src/platform/workspace/components/CurrentUserPopoverWorkspace.vue +++ b/src/platform/workspace/components/CurrentUserPopoverWorkspace.vue @@ -281,9 +281,8 @@ const { workspaceName, isInPersonalWorkspace: isPersonalWorkspace } = storeToRefs(workspaceStore) -const { permissions } = useWorkspaceUI() -const { canTopUp, canSubscribeSelfServe, canReactivate } = - useBillingCapabilities() +const { permissions, canReactivatePlan } = useWorkspaceUI() +const { canTopUp, canSubscribeSelfServe } = useBillingCapabilities() const isWorkspaceSwitcherOpen = ref(false) const workspaceSwitcherTrigger = useTemplateRef('workspaceSwitcherTrigger') const workspaceSwitcherPanel = useTemplateRef('workspaceSwitcherPanel') @@ -366,12 +365,13 @@ const showManagePlan = computed( permissions.value.canManageSubscription && (canAccessSubscriptionFeatures.value || hasDelinquentSubscription.value) ) + const showSubscribeAction = computed( () => - // Subscribing is Cloud-only, so the whole action stays gated on isCloud; - // inside it the server-resolved capabilities are authoritative. + // Subscribing is Cloud-only, so the whole action stays gated on isCloud. + // Self-serve subscribe is server-authoritative; reactivation is not. isCloud && - ((isCancelled.value && canReactivate.value) || + ((isCancelled.value && canReactivatePlan.value) || (!canAccessSubscriptionFeatures.value && !hasDelinquentSubscription.value && canSubscribeSelfServe.value)) diff --git a/src/platform/workspace/components/SubscriptionPanelContentWorkspace.test.ts b/src/platform/workspace/components/SubscriptionPanelContentWorkspace.test.ts index 1783e18921d..5a6993bbb5b 100644 --- a/src/platform/workspace/components/SubscriptionPanelContentWorkspace.test.ts +++ b/src/platform/workspace/components/SubscriptionPanelContentWorkspace.test.ts @@ -85,6 +85,7 @@ const mockCanManageSubscription = ref(true) const mockCanManageSubscriptionLifecycle = ref(true) const mockCanCancel = ref(true) const mockCanReactivate = ref(true) +const mockCanReactivatePlan = ref(true) const mockShouldUseWorkspaceBilling = ref(true) const mockCanChangeSeats = ref(true) const mockCanSubscribeSelfServe = ref(true) @@ -223,6 +224,7 @@ vi.mock('@/platform/workspace/composables/useWorkspaceUI', () => ({ canManageSubscriptionLifecycle: mockCanManageSubscriptionLifecycle.value, canLeaveWorkspace: mockCanLeaveWorkspace.value })), + canReactivatePlan: mockCanReactivatePlan, uiConfig: computed(() => mockUiConfig.value), isInPersonalWorkspace: mockIsInPersonalWorkspace, isActiveSubscription: computed(() => mockIsActiveSubscription.value), @@ -820,7 +822,7 @@ describe('SubscriptionPanelContentWorkspace', () => { mockHasTeamPlan.value = false mockIsWorkspaceSubscribed.value = false mockCanManageSubscriptionLifecycle.value = true - mockCanReactivate.value = false + mockCanReactivatePlan.value = false renderComponent() expect( diff --git a/src/platform/workspace/components/SubscriptionPanelContentWorkspace.vue b/src/platform/workspace/components/SubscriptionPanelContentWorkspace.vue index fb8923fa99b..ecc9aca37cb 100644 --- a/src/platform/workspace/components/SubscriptionPanelContentWorkspace.vue +++ b/src/platform/workspace/components/SubscriptionPanelContentWorkspace.vue @@ -417,7 +417,6 @@ import type { TierBenefit } from '@/platform/cloud/subscription/utils/tierBenefi import { getCommonTierBenefits } from '@/platform/cloud/subscription/utils/tierBenefits' import { isCloud } from '@/platform/distribution/types' import { useResubscribe } from '@/platform/workspace/composables/useResubscribe' -import { useBillingRouting } from '@/composables/billing/useBillingRouting' import { useBillingCapabilities } from '@/platform/workspace/composables/useBillingCapabilities' import { useWorkspaceMenuItems } from '@/platform/workspace/composables/useWorkspaceMenuItems' import { useWorkspacePlanPricing } from '@/platform/workspace/composables/useWorkspacePlanPricing' @@ -432,10 +431,13 @@ import { const workspaceStore = useTeamWorkspaceStore() const { isWorkspaceSubscribed, isInPersonalWorkspace } = storeToRefs(workspaceStore) -const { permissions, isSubscriptionCancelled, workspaceRole } = useWorkspaceUI() -const { shouldUseWorkspaceBilling } = useBillingRouting() -const { canReactivate, canChangeSeats, canSubscribeSelfServe } = - useBillingCapabilities() +const { + permissions, + isSubscriptionCancelled, + workspaceRole, + canReactivatePlan +} = useWorkspaceUI() +const { canChangeSeats, canSubscribeSelfServe } = useBillingCapabilities() const { maxAvailable: freeRunsAllowance, quotaEnabled: freeRunsQuotaEnabled } = useFreeTierQuota() const { t, n, locale } = useI18n() @@ -505,11 +507,6 @@ const showSubscribePrompt = computed(() => { // The legacy rail keeps lifecycle authorization on the client, and // handleResubscribe() skips its capability guard there, so the affordance has // to follow the same three-way condition or it hides a working action. -const canReactivatePlan = computed(() => - isCloud && shouldUseWorkspaceBilling.value - ? canReactivate.value - : permissions.value.canManageSubscriptionLifecycle -) const canChangePlan = computed(() => isCloud ? canChangeSeats.value : permissions.value.canManageSubscription ) diff --git a/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.test.ts b/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.test.ts index 0cebf36783c..eb773c855a6 100644 --- a/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.test.ts +++ b/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.test.ts @@ -28,10 +28,11 @@ const state = vi.hoisted(() => ({ endDate: null } as Subscription | null, renewalDate: null as string | null, - workspaceType: 'team' as string, + workspaceType: 'team' as WorkspaceType, canManageSubscription: true, canManageSubscriptionLifecycle: true, canReactivate: true, + canReactivatePlan: true, shouldUseWorkspaceBilling: true, canTopUp: true, canSubscribeSelfServe: false, @@ -80,7 +81,8 @@ vi.mock('@/platform/workspace/composables/useWorkspaceUI', () => ({ canManageSubscription: state.canManageSubscription, canManageSubscriptionLifecycle: state.canManageSubscriptionLifecycle })), - workspaceType: computed(() => state.workspaceType as WorkspaceType) + workspaceType: computed(() => state.workspaceType), + canReactivatePlan: computed(() => state.canReactivatePlan) }) })) @@ -405,7 +407,7 @@ describe('BillingStatusBanner', () => { } state.canManageSubscription = true state.canManageSubscriptionLifecycle = true - state.canReactivate = false + state.canReactivatePlan = false renderBanner() expect(screen.getByRole('status')).toHaveTextContent( diff --git a/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.vue b/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.vue index 546e60fc621..502e72bfc8d 100644 --- a/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.vue +++ b/src/platform/workspace/components/dialogs/settings/BillingStatusBanner.vue @@ -74,8 +74,6 @@ import { useI18n } from 'vue-i18n' import Button from '@/components/ui/button/Button.vue' import { useBillingContext } from '@/composables/billing/useBillingContext' import { useBillingBanner } from '@/platform/workspace/composables/useBillingBanner' -import { isCloud } from '@/platform/distribution/types' -import { useBillingRouting } from '@/composables/billing/useBillingRouting' import { useBillingCapabilities } from '@/platform/workspace/composables/useBillingCapabilities' import { useResubscribe } from '@/platform/workspace/composables/useResubscribe' import { useWorkspaceUI } from '@/platform/workspace/composables/useWorkspaceUI' @@ -85,10 +83,8 @@ type BannerAction = 'addCredits' | 'reactivate' | 'updatePayment' const { t, d } = useI18n() const { renewalDate, subscription, manageSubscription } = useBillingContext() -const { permissions } = useWorkspaceUI() -const { shouldUseWorkspaceBilling } = useBillingRouting() -const { canTopUp, canSubscribeSelfServe, canReactivate } = - useBillingCapabilities() +const { permissions, canReactivatePlan } = useWorkspaceUI() +const { canTopUp, canSubscribeSelfServe } = useBillingCapabilities() const { kind, dismiss } = useBillingBanner() const { isResubscribing, handleResubscribe } = useResubscribe() const dialogService = useDialogService() @@ -97,11 +93,6 @@ const canManage = computed(() => permissions.value.canManageSubscription) // The legacy rail keeps lifecycle authorization on the client, and // handleResubscribe() skips its capability guard there, so the affordance has // to follow the same three-way condition or it hides a working action. -const canReactivatePlan = computed(() => - isCloud && shouldUseWorkspaceBilling.value - ? canReactivate.value - : permissions.value.canManageSubscriptionLifecycle -) const cycleResetDate = computed(() => { const raw = renewalDate.value return raw ? d(new Date(raw), { month: 'short', day: 'numeric' }) : '' diff --git a/src/platform/workspace/composables/useWorkspaceUI.test.ts b/src/platform/workspace/composables/useWorkspaceUI.test.ts index 24fc5293a34..83ad9d99c7d 100644 --- a/src/platform/workspace/composables/useWorkspaceUI.test.ts +++ b/src/platform/workspace/composables/useWorkspaceUI.test.ts @@ -1,4 +1,4 @@ -import { ref } from 'vue' +import { computed, ref } from 'vue' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type { WorkspaceWithRole } from '@/platform/workspace/api/workspaceApi' @@ -9,6 +9,9 @@ const mockStore = vi.hoisted(() => ({ originalOwnerId: null as string | null, ensureMembersLoaded: vi.fn() })) +const mockIsCloud = ref(true) +const mockShouldUseWorkspaceBilling = ref(true) +const mockCanReactivate = ref(false) const mockIsActiveSubscription = vi.hoisted(() => ({ value: false })) const mockIsCancelled = vi.hoisted(() => ({ value: false })) const mockIsTeamPlan = vi.hoisted(() => ({ value: false })) @@ -35,6 +38,26 @@ vi.mock('@/platform/workspace/stores/teamWorkspaceStore', () => ({ }) })) +vi.mock('@/platform/distribution/types', () => ({ + get isCloud() { + return mockIsCloud.value + } +})) + +vi.mock('@/composables/billing/useBillingRouting', () => ({ + useBillingRouting: () => ({ + shouldUseWorkspaceBilling: computed( + () => mockShouldUseWorkspaceBilling.value + ) + }) +})) + +vi.mock('@/platform/workspace/composables/useBillingCapabilities', () => ({ + useBillingCapabilities: () => ({ + canReactivate: computed(() => mockCanReactivate.value) + }) +})) + vi.mock('@/composables/billing/useBillingContext', () => ({ useBillingContext: () => ({ isActiveSubscription: ref(mockIsActiveSubscription.value), @@ -100,6 +123,9 @@ function resetStore() { mockIsCancelled.value = false mockIsTeamPlan.value = false mockBillingControlEnabled.value = false + mockIsCloud.value = true + mockShouldUseWorkspaceBilling.value = true + mockCanReactivate.value = false } describe('useWorkspaceUI', () => { @@ -450,4 +476,40 @@ describe('useWorkspaceUI', () => { expect(second.uiConfig).toBe(first.uiConfig) }) }) + describe('canReactivatePlan', () => { + beforeEach(() => { + mockStore.activeWorkspace = personalWorkspace + }) + + it('uses the server capability on the consolidated rail', async () => { + mockShouldUseWorkspaceBilling.value = true + mockCanReactivate.value = false + + const denied = await loadComposable() + expect(denied.canReactivatePlan.value).toBe(false) + + vi.resetModules() + mockCanReactivate.value = true + const allowed = await loadComposable() + expect(allowed.canReactivatePlan.value).toBe(true) + }) + + it('falls back to membership on the legacy rail, where no capability row exists', async () => { + mockShouldUseWorkspaceBilling.value = false + mockCanReactivate.value = false + + const ui = await loadComposable() + expect(ui.permissions.value.canManageSubscriptionLifecycle).toBe(true) + expect(ui.canReactivatePlan.value).toBe(true) + }) + + it('falls back to membership off Cloud, where the endpoint is never called', async () => { + mockIsCloud.value = false + mockShouldUseWorkspaceBilling.value = true + mockCanReactivate.value = false + + const ui = await loadComposable() + expect(ui.canReactivatePlan.value).toBe(true) + }) + }) }) diff --git a/src/platform/workspace/composables/useWorkspaceUI.ts b/src/platform/workspace/composables/useWorkspaceUI.ts index e32d3a35afc..517b5f4ef6d 100644 --- a/src/platform/workspace/composables/useWorkspaceUI.ts +++ b/src/platform/workspace/composables/useWorkspaceUI.ts @@ -2,7 +2,10 @@ import { computed, watch } from 'vue' import { createSharedComposable } from '@vueuse/core' import { useBillingContext } from '@/composables/billing/useBillingContext' +import { useBillingRouting } from '@/composables/billing/useBillingRouting' import { useFeatureFlags } from '@/composables/useFeatureFlags' +import { isCloud } from '@/platform/distribution/types' +import { useBillingCapabilities } from '@/platform/workspace/composables/useBillingCapabilities' import type { WorkspaceRole, WorkspaceType } from '../api/workspaceApi' import { useTeamWorkspaceStore } from '../stores/teamWorkspaceStore' @@ -165,6 +168,9 @@ function useWorkspaceUIInternal() { { immediate: true } ) + const { shouldUseWorkspaceBilling } = useBillingRouting() + const { canReactivate } = useBillingCapabilities() + const permissions = computed(() => getPermissions( workspaceType.value, @@ -176,6 +182,15 @@ function useWorkspaceUIInternal() { ) ) + // legacy_stripe workspaces have no capability projection row, so the + // server-resolved can_reactivate is false for them and cannot gate the + // action; that rail stays on the membership check. + const canReactivatePlan = computed(() => + isCloud && shouldUseWorkspaceBilling.value + ? canReactivate.value + : permissions.value.canManageSubscriptionLifecycle + ) + const uiConfig = computed(() => { const base = getUIConfig(workspaceType.value, workspaceRole.value) const showCreditsColumn = @@ -217,6 +232,7 @@ function useWorkspaceUIInternal() { return { // Permissions and config permissions, + canReactivatePlan, uiConfig, workspaceType, workspaceRole, From 5f6a795190c887a70db044d120affe985166f121 Mon Sep 17 00:00:00 2001 From: Wei Hai Date: Wed, 26 Aug 2026 19:44:12 +0000 Subject: [PATCH 2/2] fix(billing): align pricing-dialog reactivation with the centralized rail policy (#16043) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #16033. ### The bug `UnifiedPricingTable` and `useSubscriptionCheckout.handleResubscribe` gated reactivation on `isCloud` plus the **raw** `can_reactivate`, ignoring the billing rail: ```ts const canReactivate = computed(() => isCloud ? capabilities.canReactivate.value : permissions.value.canManageSubscriptionLifecycle ) ``` `legacy_stripe` workspaces have no capability projection row, so on Cloud the raw capability is `false` for them. A cancelled `legacy_stripe` customer therefore saw the pricing dialog's reactivate CTA **disabled**, and `handleResubscribe` returned early even if they got there. This is the same defect #15967 fixed for the workspace surfaces — the pricing dialog is the primary resubscribe path, so it matters more. ### The fix Both sites now consume `canReactivatePlan` from `useWorkspaceUI`, the shared rail-aware policy introduced in #15967. Both files already imported `useWorkspaceUI`, so this removes code rather than adding a layer. ### Verification Each new test was checked against the unfixed code, not just run green: - **`useSubscriptionCheckout`** — new case: raw `can_reactivate` false, derived policy true → resubscribe proceeds. Fails against the old expression. - **`UnifiedPricingTable`** — new case: derived policy false → the Resubscribe CTA is disabled. Fails against the old expression. - Two existing checkout cases drove the raw capability and now drive the derived value; their intent is unchanged. - The pricing-table mock previously wired `canReactivate` to the same ref as `canSubscribeSelfServe`, so raw and derived could not diverge. It now has its own ref, which is what makes the new case meaningful. I also wrote and then **removed** a third test — a legacy-rail pricing case that passed against the unfixed code because its scenario never reached the reactivate branch. A test that passes against the bug is worse than no test. `pnpm typecheck` clean; 150 passing across the two affected files; full suite 1317/1318 with only the 12 pre-existing `check-binary-size` environment failures. (cherry picked from commit 77d3ecbb661f3f1c751e5a2289fe5649ddca736b) --- .../components/UnifiedPricingTable.test.ts | 29 +++++++++++++++++-- .../components/UnifiedPricingTable.vue | 11 ++----- .../useSubscriptionCheckout.test.ts | 29 +++++++++++++++++++ .../composables/useSubscriptionCheckout.ts | 17 +++-------- 4 files changed, 63 insertions(+), 23 deletions(-) diff --git a/src/platform/workspace/components/UnifiedPricingTable.test.ts b/src/platform/workspace/components/UnifiedPricingTable.test.ts index 903d258d8d2..87595850f64 100644 --- a/src/platform/workspace/components/UnifiedPricingTable.test.ts +++ b/src/platform/workspace/components/UnifiedPricingTable.test.ts @@ -29,6 +29,10 @@ const mockCurrentTeamCreditStop = ref(null) const mockIsTeamPlan = ref(false) const mockCanManageSubscription = ref(true) const mockCanDowngradeToPersonal = ref(true) +const mockCanReactivatePlan = ref(true) +// the raw server capability, kept separate so a test can prove the component +// follows the derived policy rather than this value +const mockRawCanReactivate = ref(true) const mockPermissions = ref({ canManageSubscription: true, canManageSubscriptionLifecycle: true, @@ -53,7 +57,7 @@ vi.mock('@/platform/distribution/types', () => mockDistributionTypes) vi.mock('@/platform/workspace/composables/useBillingCapabilities', () => ({ useBillingCapabilities: () => ({ canSubscribeSelfServe: computed(() => mockCanManageSubscription.value), - canReactivate: computed(() => mockCanManageSubscription.value), + canReactivate: computed(() => mockRawCanReactivate.value), canChangeSeats: computed(() => mockCanManageSubscription.value), canDowngradeToPersonal: computed(() => mockCanDowngradeToPersonal.value) }) @@ -61,7 +65,8 @@ vi.mock('@/platform/workspace/composables/useBillingCapabilities', () => ({ vi.mock('@/platform/workspace/composables/useWorkspaceUI', () => ({ useWorkspaceUI: () => ({ - permissions: computed(() => mockPermissions.value) + permissions: computed(() => mockPermissions.value), + canReactivatePlan: computed(() => mockCanReactivatePlan.value) }) })) @@ -93,6 +98,8 @@ function renderComponent(props: Record = {}) { describe('UnifiedPricingTable plan CTA labels', () => { beforeEach(() => { + mockCanReactivatePlan.value = true + mockRawCanReactivate.value = true mockSubscription.value = null mockSubscriptionStatus.value = null mockCurrentPlanSlug.value = null @@ -222,6 +229,8 @@ describe('UnifiedPricingTable team plan CTA', () => { } beforeEach(() => { + mockCanReactivatePlan.value = true + mockRawCanReactivate.value = true mockSubscription.value = null mockSubscriptionStatus.value = null mockCurrentPlanSlug.value = null @@ -309,6 +318,20 @@ describe('UnifiedPricingTable team plan CTA', () => { expect(emitted().resubscribe).toBeTruthy() }) + it('disables Resubscribe when the workspace may not reactivate', () => { + mockSubscription.value = { + tier: 'TEAM', + duration: 'ANNUAL', + isCancelled: true + } + mockCurrentTeamCreditStop.value = TEAM_STOP + mockCanReactivatePlan.value = false + + renderComponent({ initialPlanMode: 'team' }) + + expect(screen.getByRole('button', { name: 'Resubscribe' })).toBeDisabled() + }) + it('lets a cancelled sub change to a different stop (not re-subscribe)', async () => { const user = userEvent.setup() mockSubscription.value = { @@ -368,6 +391,8 @@ describe('UnifiedPricingTable outside Cloud', () => { } beforeEach(() => { + mockCanReactivatePlan.value = true + mockRawCanReactivate.value = true mockSubscription.value = null mockSubscriptionStatus.value = null mockCurrentPlanSlug.value = null diff --git a/src/platform/workspace/components/UnifiedPricingTable.vue b/src/platform/workspace/components/UnifiedPricingTable.vue index cf51357d4e4..509ad002af0 100644 --- a/src/platform/workspace/components/UnifiedPricingTable.vue +++ b/src/platform/workspace/components/UnifiedPricingTable.vue @@ -469,18 +469,13 @@ const emit = defineEmits<{ const { t, n } = useI18n() const capabilities = useBillingCapabilities() -const { permissions } = useWorkspaceUI() +const { permissions, canReactivatePlan } = useWorkspaceUI() const canSubscribeSelfServe = computed(() => isCloud ? capabilities.canSubscribeSelfServe.value : permissions.value.canManageSubscription ) -const canReactivate = computed(() => - isCloud - ? capabilities.canReactivate.value - : permissions.value.canManageSubscriptionLifecycle -) const canChangeSeats = computed(() => isCloud ? capabilities.canChangeSeats.value @@ -770,7 +765,7 @@ const isTeamButtonDisabled = computed(() => { if (isLoading) return true if (!isTeamSubscribed.value) return !canSubscribeSelfServe.value if (isTeamCurrentPlanSelected.value) { - return !isCancelled.value || !canReactivate.value + return !isCancelled.value || !canReactivatePlan.value } return !canChangeSeats.value }) @@ -861,7 +856,7 @@ const canUsePersonalPlanAction = (tierKey: CheckoutTierKey): boolean => { if (!canSelectPersonalPlan.value) return false if (isTeamPlan.value) return canDowngradeToPersonal.value if (isCurrentPlan(tierKey)) { - return isCancelled.value && canReactivate.value + return isCancelled.value && canReactivatePlan.value } return hasActivePaidPlan(currentAccountTier.value) ? canChangeSeats.value diff --git a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts index 4ac1258df5c..7be8ba0e4fa 100644 --- a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts +++ b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts @@ -175,6 +175,7 @@ const { mockSetActiveWorkspaceIdImpl, mockSetActiveWorkspaceId, mockPermissions, + mockCanReactivatePlan, mockCapabilities, mockSubscription } = vi.hoisted(() => ({ @@ -218,6 +219,7 @@ const { canDowngradeToPersonal: true } }, + mockCanReactivatePlan: { value: true }, mockCapabilities: { value: { canSubscribeSelfServe: true, @@ -282,6 +284,11 @@ vi.mock('@/platform/workspace/composables/useWorkspaceUI', () => ({ get value() { return mockPermissions.value } + }, + canReactivatePlan: { + get value() { + return mockCanReactivatePlan.value + } } }) })) @@ -503,6 +510,7 @@ describe('useSubscriptionCheckout', () => { canChangeSeats: true, canDowngradeToPersonal: true } + mockCanReactivatePlan.value = true mockSubscription.value = null sessionStorage.clear() emit = vi.fn() @@ -3876,9 +3884,29 @@ describe('useSubscriptionCheckout', () => { }) }) + it('resubscribes on the legacy rail even though the server withholds can_reactivate', async () => { + // legacy_stripe workspaces have no capability projection row, so the + // raw capability is false while the workspace may still reactivate. + mockCapabilities.value.canReactivate = false + mockCanReactivatePlan.value = true + const checkout = await setup() + mockResubscribe.mockResolvedValueOnce({ + billing_op_id: 'op-legacy-rail', + status: 'active' + }) + mockFetchStatus.mockResolvedValueOnce(undefined) + mockFetchBalance.mockResolvedValueOnce(undefined) + + await checkout.handleResubscribe() + + expect(emit).toHaveBeenCalledWith('close', true) + expect(mockResubscribe).toHaveBeenCalled() + }) + it('does not resubscribe for a member', async () => { mockPermissions.value.canManageSubscriptionLifecycle = false mockCapabilities.value.canReactivate = false + mockCanReactivatePlan.value = false const checkout = await setup() await checkout.handleResubscribe() @@ -3889,6 +3917,7 @@ describe('useSubscriptionCheckout', () => { it('does not resubscribe when the server denies reactivation to a client-side owner', async () => { mockCapabilities.value.canReactivate = false + mockCanReactivatePlan.value = false const checkout = await setup() await checkout.handleResubscribe() diff --git a/src/platform/workspace/composables/useSubscriptionCheckout.ts b/src/platform/workspace/composables/useSubscriptionCheckout.ts index 0a9ee5ab194..defd5fc4c4f 100644 --- a/src/platform/workspace/composables/useSubscriptionCheckout.ts +++ b/src/platform/workspace/composables/useSubscriptionCheckout.ts @@ -137,13 +137,9 @@ export function useSubscriptionCheckout( subscription } = useBillingContext() const { shouldUseWorkspaceBilling } = useBillingRouting() - const { - canSubscribeSelfServe, - canReactivate, - canChangeSeats, - canDowngradeToPersonal - } = useBillingCapabilities() - const { permissions } = useWorkspaceUI() + const { canSubscribeSelfServe, canChangeSeats, canDowngradeToPersonal } = + useBillingCapabilities() + const { permissions, canReactivatePlan } = useWorkspaceUI() const telemetry = useTelemetry() const billingOperationStore = useBillingOperationStore() const workspaceStore = useTeamWorkspaceStore() @@ -1459,12 +1455,7 @@ export function useSubscriptionCheckout( } async function handleResubscribe() { - if ( - !(isCloud - ? canReactivate.value - : permissions.value.canManageSubscriptionLifecycle) - ) - return + if (!canReactivatePlan.value) return const source = 'pricing_dialog' as const