Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -76,7 +78,8 @@ vi.mock('@/platform/workspace/composables/useWorkspaceUI', () => ({
permissions: computed(() => ({
canManageSubscription: state.canManageSubscription,
canManageSubscriptionLifecycle: state.canManageSubscriptionLifecycle
}))
})),
canReactivatePlan: computed(() => state.canReactivatePlan)
})
}))

Expand All @@ -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',
() => ({
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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')
Expand All @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -820,7 +822,7 @@ describe('SubscriptionPanelContentWorkspace', () => {
mockHasTeamPlan.value = false
mockIsWorkspaceSubscribed.value = false
mockCanManageSubscriptionLifecycle.value = true
mockCanReactivate.value = false
mockCanReactivatePlan.value = false
renderComponent()

expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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()
Expand Down Expand Up @@ -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
)
Expand Down
29 changes: 27 additions & 2 deletions src/platform/workspace/components/UnifiedPricingTable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const mockCurrentTeamCreditStop = ref<MockTeamStop | null>(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,
Expand All @@ -53,15 +57,16 @@ 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)
})
}))

vi.mock('@/platform/workspace/composables/useWorkspaceUI', () => ({
useWorkspaceUI: () => ({
permissions: computed(() => mockPermissions.value)
permissions: computed(() => mockPermissions.value),
canReactivatePlan: computed(() => mockCanReactivatePlan.value)
})
}))

Expand Down Expand Up @@ -93,6 +98,8 @@ function renderComponent(props: Record<string, unknown> = {}) {

describe('UnifiedPricingTable plan CTA labels', () => {
beforeEach(() => {
mockCanReactivatePlan.value = true
mockRawCanReactivate.value = true
mockSubscription.value = null
mockSubscriptionStatus.value = null
mockCurrentPlanSlug.value = null
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -368,6 +391,8 @@ describe('UnifiedPricingTable outside Cloud', () => {
}

beforeEach(() => {
mockCanReactivatePlan.value = true
mockRawCanReactivate.value = true
mockSubscription.value = null
mockSubscriptionStatus.value = null
mockCurrentPlanSlug.value = null
Expand Down
11 changes: 3 additions & 8 deletions src/platform/workspace/components/UnifiedPricingTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
})
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
})
}))

Expand Down Expand Up @@ -405,7 +407,7 @@ describe('BillingStatusBanner', () => {
}
state.canManageSubscription = true
state.canManageSubscriptionLifecycle = true
state.canReactivate = false
state.canReactivatePlan = false
renderBanner()

expect(screen.getByRole('status')).toHaveTextContent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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()
Expand All @@ -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' }) : ''
Expand Down
Loading
Loading