Skip to content

Commit cf6f0dd

Browse files
refactor: rename isActiveSubscription to canAccessSubscriptionFeatures
The name isActiveSubscription was misleading: it's defined as !isCloud || !subscription_required || subscription.is_active so it returns true on non-cloud builds and when subscription is not required, regardless of actual subscription state. The new name canAccessSubscriptionFeatures reads correctly at every call site: 'if can access features, show UI / allow action'. Pure identifier rename, no behavioral changes. Also renames the internal alias isSubscribedOrIsNotCloud to match.
1 parent 630ae61 commit cf6f0dd

40 files changed

Lines changed: 418 additions & 407 deletions

src/components/topbar/CurrentUserPopoverLegacy.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function makeSubscription(
6464

6565
const mockFetchStatus = vi.fn().mockResolvedValue(undefined)
6666
const mockFetchBalance = vi.fn().mockResolvedValue(undefined)
67-
const mockIsActiveSubscription = ref(true)
67+
const mockCanAccessSubscriptionFeatures = ref(true)
6868
const mockIsFreeTier = ref(false)
6969
const mockTier = ref<SubscriptionInfo['tier']>('CREATOR')
7070
const mockSubscription = ref<SubscriptionInfo | null>(makeSubscription())
@@ -73,7 +73,7 @@ const mockIsLoading = ref(false)
7373

7474
vi.mock('@/composables/billing/useBillingContext', () => ({
7575
useBillingContext: vi.fn(() => ({
76-
isActiveSubscription: mockIsActiveSubscription,
76+
canAccessSubscriptionFeatures: mockCanAccessSubscriptionFeatures,
7777
isFreeTier: mockIsFreeTier,
7878
tier: mockTier,
7979
subscription: mockSubscription,
@@ -153,7 +153,7 @@ describe('CurrentUserPopoverLegacy', () => {
153153
beforeEach(() => {
154154
vi.clearAllMocks()
155155
mockIsCloud.value = true
156-
mockIsActiveSubscription.value = true
156+
mockCanAccessSubscriptionFeatures.value = true
157157
mockIsFreeTier.value = false
158158
mockTier.value = 'CREATOR'
159159
mockSubscription.value = makeSubscription()
@@ -203,7 +203,7 @@ describe('CurrentUserPopoverLegacy', () => {
203203
})
204204

205205
it('refreshes subscription status through the billing facade after subscribing', async () => {
206-
mockIsActiveSubscription.value = false
206+
mockCanAccessSubscriptionFeatures.value = false
207207
const { user } = renderComponent()
208208

209209
await user.click(screen.getByTestId('subscribe-button-mock'))
@@ -478,7 +478,7 @@ describe('CurrentUserPopoverLegacy', () => {
478478
})
479479

480480
it('hides subscribe button', () => {
481-
mockIsActiveSubscription.value = false
481+
mockCanAccessSubscriptionFeatures.value = false
482482
renderComponent()
483483
expect(
484484
screen.queryByTestId('subscribe-button-mock')

src/components/topbar/CurrentUserPopoverLegacy.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@
3030
</div>
3131

3232
<!-- Credits Section -->
33-
<div v-if="isActiveSubscription" class="flex items-center gap-2 px-4 py-2">
34-
<i class="icon-[lucide--component] text-sm text-credit" />
33+
<div
34+
v-if="canAccessSubscriptionFeatures"
35+
class="flex items-center gap-2 px-4 py-2"
36+
>
37+
<i class="icon-[lucide--component] text-sm text-amber-400" />
3538
<Skeleton v-if="isLoading" width="4rem" height="1.25rem" class="w-full" />
3639
<span v-else class="text-base font-semibold text-base-foreground">{{
3740
formattedBalance
@@ -80,7 +83,7 @@
8083
<Divider class="mx-0 my-2" />
8184

8285
<div
83-
v-if="isActiveSubscription"
86+
v-if="canAccessSubscriptionFeatures"
8487
class="flex cursor-pointer items-center gap-2 px-4 py-2 hover:bg-secondary-background-hover"
8588
data-testid="partner-nodes-menu-item"
8689
@click="handleOpenPartnerNodesInfo"
@@ -110,7 +113,7 @@
110113
</div>
111114

112115
<div
113-
v-if="isActiveSubscription"
116+
v-if="canAccessSubscriptionFeatures"
114117
class="flex cursor-pointer items-center gap-2 px-4 py-2 hover:bg-secondary-background-hover"
115118
data-testid="manage-plan-menu-item"
116119
@click="handleOpenPlanAndCreditsSettings"
@@ -178,7 +181,7 @@ const { userDisplayName, userEmail, userPhotoUrl, handleSignOut } =
178181
const settingsDialog = useSettingsDialog()
179182
const dialogService = useDialogService()
180183
const {
181-
isActiveSubscription,
184+
canAccessSubscriptionFeatures,
182185
isFreeTier,
183186
tier,
184187
subscription,

src/composables/auth/useAuthActions.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ vi.mock('@/stores/authStore', () => ({
8181

8282
vi.mock('@/composables/billing/useBillingContext', () => ({
8383
useBillingContext: vi.fn(() => ({
84-
isActiveSubscription: { value: false },
84+
canAccessSubscriptionFeatures: { value: false },
8585
isFreeTier: { value: true },
8686
type: { value: 'free' }
8787
}))

src/composables/auth/useAuthActions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ export const useAuthActions = () => {
141141
)
142142

143143
const purchaseCredits = wrapWithErrorHandlingAsync(async (amount: number) => {
144-
const { isActiveSubscription } = useBillingContext()
145-
if (!isActiveSubscription.value) return
144+
const { canAccessSubscriptionFeatures } = useBillingContext()
145+
if (!canAccessSubscriptionFeatures.value) return
146146

147147
const response = await authStore.initiateCreditPurchase({
148148
amount_micros: usdToMicros(amount),

src/composables/billing/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export interface BillingState {
9494
currentTeamCreditStop: ComputedRef<CurrentTeamCreditStop | null>
9595
isLoading: Ref<boolean>
9696
error: Ref<string | null>
97-
isActiveSubscription: ComputedRef<boolean>
97+
canAccessSubscriptionFeatures: ComputedRef<boolean>
9898
/** Reflects the active workspace's tier, not the user's personal tier. */
9999
isFreeTier: ComputedRef<boolean>
100100
/** Coarse funding state (`billing_status`); legacy reports null. */
@@ -121,4 +121,6 @@ export interface BillingContext extends BillingState, BillingActions {
121121
isTeamPlan: ComputedRef<boolean>
122122
getMaxSeats: (tierKey: TierKey) => number
123123
canRunWorkflows: ComputedRef<boolean>
124+
/** @deprecated Use canAccessSubscriptionFeatures instead */
125+
isActiveSubscription: ComputedRef<boolean>
124126
}

src/composables/billing/useBillingContext.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ vi.mock('@/platform/workspace/stores/teamWorkspaceStore', () => ({
9696

9797
vi.mock('@/platform/cloud/subscription/composables/useSubscription', () => ({
9898
useSubscription: () => ({
99-
isActiveSubscription: { value: true },
99+
canAccessSubscriptionFeatures: { value: true },
100100
subscriptionTier: { value: 'PRO' },
101101
subscriptionDuration: { value: 'MONTHLY' },
102102
subscriptionStatus: {
@@ -269,9 +269,9 @@ describe('useBillingContext', () => {
269269
await expect(topup(99.5)).rejects.toThrow()
270270
})
271271

272-
it('provides isActiveSubscription convenience computed', () => {
273-
const { isActiveSubscription } = useBillingContext()
274-
expect(isActiveSubscription.value).toBe(true)
272+
it('provides canAccessSubscriptionFeatures convenience computed', () => {
273+
const { canAccessSubscriptionFeatures } = useBillingContext()
274+
expect(canAccessSubscriptionFeatures.value).toBe(true)
275275
})
276276

277277
it('exposes requireActiveSubscription action', async () => {

src/composables/billing/useBillingContext.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,13 @@ function useBillingContextInternal(): BillingContext {
124124
toValue(activeContext.value.currentTeamCreditStop)
125125
)
126126

127-
const isActiveSubscription = computed(() =>
128-
toValue(activeContext.value.isActiveSubscription)
127+
const canAccessSubscriptionFeatures = computed(() =>
128+
toValue(activeContext.value.canAccessSubscriptionFeatures)
129129
)
130130

131+
// Alias kept for backward compatibility; equals canAccessSubscriptionFeatures.
132+
const isActiveSubscription = canAccessSubscriptionFeatures
133+
131134
const isFreeTier = computed(() => subscription.value?.tier === 'FREE')
132135

133136
const freeTierQuota = useFreeTierQuota()
@@ -143,7 +146,7 @@ function useBillingContextInternal(): BillingContext {
143146
const isLegacyTeamPlan = computed(
144147
() =>
145148
type.value === 'workspace' &&
146-
isActiveSubscription.value &&
149+
canAccessSubscriptionFeatures.value &&
147150
!isFreeTier.value &&
148151
currentTeamCreditStop.value === null &&
149152
(currentPlanSlug.value
@@ -324,6 +327,7 @@ function useBillingContextInternal(): BillingContext {
324327
error,
325328
isActiveSubscription,
326329
canRunWorkflows,
330+
canAccessSubscriptionFeatures,
327331
isFreeTier,
328332
isLegacyTeamPlan,
329333
isTeamPlan,

src/composables/billing/useLegacyBilling.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import type {
2727
*/
2828
export function useLegacyBilling(): BillingState & BillingActions {
2929
const {
30-
isActiveSubscription: legacyIsActiveSubscription,
30+
canAccessSubscriptionFeatures: legacyCanAccessSubscriptionFeatures,
3131
subscriptionTier,
3232
subscriptionDuration,
3333
subscriptionStatus: legacySubscriptionStatus,
@@ -45,16 +45,18 @@ export function useLegacyBilling(): BillingState & BillingActions {
4545
const isLoading = ref(false)
4646
const error = ref<string | null>(null)
4747

48-
const isActiveSubscription = computed(() => legacyIsActiveSubscription.value)
48+
const canAccessSubscriptionFeatures = computed(
49+
() => legacyCanAccessSubscriptionFeatures.value
50+
)
4951
const isFreeTier = computed(() => subscriptionTier.value === 'FREE')
5052

5153
const subscription = computed<SubscriptionInfo | null>(() => {
52-
if (!legacyIsActiveSubscription.value && !subscriptionTier.value) {
54+
if (!legacyCanAccessSubscriptionFeatures.value && !subscriptionTier.value) {
5355
return null
5456
}
5557

5658
return {
57-
isActive: legacyIsActiveSubscription.value,
59+
isActive: legacyCanAccessSubscriptionFeatures.value,
5860
tier: subscriptionTier.value,
5961
duration: subscriptionDuration.value,
6062
planSlug: null, // Legacy doesn't use plan slugs
@@ -85,7 +87,7 @@ export function useLegacyBilling(): BillingState & BillingActions {
8587
const billingStatus = computed<BillingStatus | null>(() => null)
8688
const subscriptionStatus = computed<BillingSubscriptionStatus | null>(() => {
8789
if (isCancelled.value) return 'canceled'
88-
if (legacyIsActiveSubscription.value) return 'active'
90+
if (legacyCanAccessSubscriptionFeatures.value) return 'active'
8991
return null
9092
})
9193
const tier = computed(() => subscriptionTier.value)
@@ -189,8 +191,8 @@ export function useLegacyBilling(): BillingState & BillingActions {
189191

190192
async function requireActiveSubscription(): Promise<void> {
191193
await fetchStatus()
192-
if (!isActiveSubscription.value) {
193-
legacyShowSubscriptionDialog({ reason: 'subscription_required' })
194+
if (!canAccessSubscriptionFeatures.value) {
195+
legacyShowSubscriptionDialog()
194196
}
195197
}
196198

@@ -209,7 +211,7 @@ export function useLegacyBilling(): BillingState & BillingActions {
209211
currentTeamCreditStop,
210212
isLoading,
211213
error,
212-
isActiveSubscription,
214+
canAccessSubscriptionFeatures,
213215
isFreeTier,
214216
billingStatus,
215217
subscriptionStatus,

src/composables/useCoreCommands.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,14 @@ vi.mock('@/composables/auth/useAuthActions', () => ({
190190

191191
vi.mock('@/platform/cloud/subscription/composables/useSubscription', () => ({
192192
useSubscription: vi.fn(() => ({
193-
isActiveSubscription: vi.fn().mockReturnValue(true),
193+
canAccessSubscriptionFeatures: vi.fn().mockReturnValue(true),
194194
showSubscriptionDialog: vi.fn()
195195
}))
196196
}))
197197

198198
vi.mock('@/composables/billing/useBillingContext', () => ({
199199
useBillingContext: vi.fn(() => ({
200-
isActiveSubscription: { value: true },
200+
canAccessSubscriptionFeatures: { value: true },
201201
showSubscriptionDialog: vi.fn()
202202
}))
203203
}))

src/composables/useCoreCommands.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ import { useDialogStore } from '@/stores/dialogStore'
7474

7575
const moveSelectedNodesVersionAdded = '1.22.2'
7676
export function useCoreCommands(): ComfyCommand[] {
77-
const { isActiveSubscription, showSubscriptionDialog } = useBillingContext()
77+
const { canAccessSubscriptionFeatures, showSubscriptionDialog } =
78+
useBillingContext()
7879
const workflowService = useWorkflowService()
7980
const workflowStore = useWorkflowStore()
8081
const settingsDialog = useSettingsDialog()
@@ -502,8 +503,8 @@ export function useCoreCommands(): ComfyCommand[] {
502503
trigger_source?: ExecutionTriggerSource
503504
}) => {
504505
trackRunButton(metadata)
505-
if (!isActiveSubscription.value) {
506-
showSubscriptionDialog({ reason: 'subscribe_to_run' })
506+
if (!canAccessSubscriptionFeatures.value) {
507+
showSubscriptionDialog()
507508
return
508509
}
509510

@@ -525,8 +526,8 @@ export function useCoreCommands(): ComfyCommand[] {
525526
trigger_source?: ExecutionTriggerSource
526527
}) => {
527528
trackRunButton(metadata)
528-
if (!isActiveSubscription.value) {
529-
showSubscriptionDialog({ reason: 'subscribe_to_run' })
529+
if (!canAccessSubscriptionFeatures.value) {
530+
showSubscriptionDialog()
530531
return
531532
}
532533

@@ -547,8 +548,8 @@ export function useCoreCommands(): ComfyCommand[] {
547548
trigger_source?: ExecutionTriggerSource
548549
}) => {
549550
trackRunButton(metadata)
550-
if (!isActiveSubscription.value) {
551-
showSubscriptionDialog({ reason: 'subscribe_to_run' })
551+
if (!canAccessSubscriptionFeatures.value) {
552+
showSubscriptionDialog()
552553
return
553554
}
554555

0 commit comments

Comments
 (0)