(
workspaceState: WorkspaceOwnershipState,
context: { billedPlanCategory: PlanCategory }
)
| 109 | * unique billed account user rather than re-querying per workspace. |
| 110 | */ |
| 111 | export function evaluateWorkspaceInvitePolicy( |
| 112 | workspaceState: WorkspaceOwnershipState, |
| 113 | context: { billedPlanCategory: PlanCategory } |
| 114 | ): WorkspaceInvitePolicy { |
| 115 | if (!isBillingEnabled) { |
| 116 | return { |
| 117 | allowed: true, |
| 118 | reason: null, |
| 119 | requiresSeat: false, |
| 120 | organizationId: workspaceState.organizationId, |
| 121 | upgradeRequired: false, |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | if (workspaceState.workspaceMode === WORKSPACE_MODE.ORGANIZATION) { |
| 126 | if (workspaceState.organizationId === null || context.billedPlanCategory === 'free') { |
| 127 | return blockInvite(workspaceState.organizationId) |
| 128 | } |
| 129 | |
| 130 | return { |
| 131 | allowed: true, |
| 132 | reason: null, |
| 133 | requiresSeat: context.billedPlanCategory === 'enterprise', |
| 134 | organizationId: workspaceState.organizationId, |
| 135 | upgradeRequired: false, |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | switch (context.billedPlanCategory) { |
| 140 | case 'pro': |
| 141 | case 'team': |
| 142 | return { |
| 143 | allowed: true, |
| 144 | reason: null, |
| 145 | requiresSeat: false, |
| 146 | organizationId: workspaceState.organizationId, |
| 147 | upgradeRequired: false, |
| 148 | } |
| 149 | case 'enterprise': |
| 150 | return { |
| 151 | allowed: true, |
| 152 | reason: null, |
| 153 | requiresSeat: true, |
| 154 | organizationId: workspaceState.organizationId, |
| 155 | upgradeRequired: false, |
| 156 | } |
| 157 | default: |
| 158 | return blockInvite(workspaceState.organizationId) |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | function blockInvite(organizationId: string | null): WorkspaceInvitePolicy { |
| 163 | return { |
no test coverage detected