( userId: string, workflowId: string )
| 12 | * @returns Promise<{ hasAccess: boolean; userPermission: PermissionType | null; workspaceId?: string }> |
| 13 | */ |
| 14 | export async function verifyWorkflowAccess( |
| 15 | userId: string, |
| 16 | workflowId: string |
| 17 | ): Promise<{ |
| 18 | hasAccess: boolean |
| 19 | userPermission: PermissionType | null |
| 20 | workspaceId?: string |
| 21 | }> { |
| 22 | try { |
| 23 | const result = await authorizeWorkflowByWorkspacePermission({ |
| 24 | workflowId, |
| 25 | userId, |
| 26 | action: 'read', |
| 27 | }) |
| 28 | return { |
| 29 | hasAccess: result.allowed, |
| 30 | userPermission: result.workspacePermission, |
| 31 | workspaceId: result.workflow?.workspaceId ?? undefined, |
| 32 | } |
| 33 | } catch (error) { |
| 34 | logger.error('Error verifying workflow access', { error, workflowId, userId }) |
| 35 | return { hasAccess: false, userPermission: null } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Helper function to create consistent permission error messages |
no test coverage detected