( workspaceId: string, userId: string, level: 'read' | 'write' | 'admin' = 'read' )
| 44 | } |
| 45 | |
| 46 | export async function ensureWorkspaceAccess( |
| 47 | workspaceId: string, |
| 48 | userId: string, |
| 49 | level: 'read' | 'write' | 'admin' = 'read' |
| 50 | ): Promise<void> { |
| 51 | const access = await checkWorkspaceAccess(workspaceId, userId) |
| 52 | if (!access.exists || !access.hasAccess) { |
| 53 | throw new Error(`Workspace ${workspaceId} not found`) |
| 54 | } |
| 55 | |
| 56 | if (level === 'read') return |
| 57 | |
| 58 | if (level === 'admin') { |
| 59 | if (!access.canAdmin) { |
| 60 | throw new Error('Admin access required for this workspace') |
| 61 | } |
| 62 | return |
| 63 | } |
| 64 | |
| 65 | if (!access.canWrite) { |
| 66 | throw new Error('Write or admin access required for this workspace') |
| 67 | } |
| 68 | } |
no test coverage detected