(workspaceId: string)
| 545 | * - the billed user has an individual Max/enterprise subscription (personal workspace). |
| 546 | */ |
| 547 | export async function hasWorkspaceInboxAccess(workspaceId: string): Promise<boolean> { |
| 548 | try { |
| 549 | if (isInboxEnabled) return true |
| 550 | if (!isBillingEnabled) return true |
| 551 | |
| 552 | const { getWorkspaceWithOwner } = await import('@/lib/workspaces/permissions/utils') |
| 553 | const ws = await getWorkspaceWithOwner(workspaceId, { includeArchived: true }) |
| 554 | if (!ws) return false |
| 555 | |
| 556 | if (ws.organizationId) { |
| 557 | if (await isOrganizationBillingBlocked(ws.organizationId)) return false |
| 558 | const orgSub = await getOrganizationSubscriptionUsable(ws.organizationId) |
| 559 | return !!orgSub && isInboxEntitledPlan(orgSub.plan) |
| 560 | } |
| 561 | |
| 562 | const [billedSub, billingStatus] = await Promise.all([ |
| 563 | getHighestPrioritySubscription(ws.billedAccountUserId), |
| 564 | getEffectiveBillingStatus(ws.billedAccountUserId), |
| 565 | ]) |
| 566 | if (!billedSub) return false |
| 567 | if (!hasUsableSubscriptionAccess(billedSub.status, billingStatus.billingBlocked)) return false |
| 568 | return isInboxEntitledPlan(billedSub.plan) |
| 569 | } catch (error) { |
| 570 | logger.error('Error checking workspace inbox access', { error, workspaceId }) |
| 571 | return false |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | /** |
| 576 | * Whether a workspace should RETAIN its provisioned inbox (Sim Mailer) |
no test coverage detected