( sourceWorkspaceId: string, userId: string )
| 96 | * which the policy would otherwise fall back to when the source is personal. |
| 97 | */ |
| 98 | export async function assertCanFork( |
| 99 | sourceWorkspaceId: string, |
| 100 | userId: string |
| 101 | ): Promise<ForkAuthorization> { |
| 102 | const source = await assertWorkspaceAdminAccess(sourceWorkspaceId, userId) |
| 103 | const policy = await getWorkspaceCreationPolicy({ |
| 104 | userId, |
| 105 | activeOrganizationId: source.organizationId, |
| 106 | pinOrganization: true, |
| 107 | }) |
| 108 | if (!policy.canCreate) { |
| 109 | throw new ForkError( |
| 110 | policy.reason ?? 'You cannot create another workspace on your current plan', |
| 111 | policy.status >= 400 ? policy.status : 403 |
| 112 | ) |
| 113 | } |
| 114 | return { source, policy } |
| 115 | } |
| 116 | |
| 117 | export interface PromoteAuthorization { |
| 118 | edge: ForkEdge |
no test coverage detected