@@ -4,7 +4,7 @@ import { z } from 'zod'
44import { getSession } from '@/lib/auth'
55import { createLogger } from '@/lib/logs/console-logger'
66import { db } from '@/db'
7- import { workflow , workflowExecutionBlocks , workflowExecutionLogs } from '@/db/schema'
7+ import { permissions , workflow , workflowExecutionBlocks , workflowExecutionLogs } from '@/db/schema'
88
99const logger = createLogger ( 'EnhancedLogsAPI' )
1010
@@ -74,11 +74,24 @@ export async function GET(request: NextRequest) {
7474 const { searchParams } = new URL ( request . url )
7575 const params = QueryParamsSchema . parse ( Object . fromEntries ( searchParams . entries ( ) ) )
7676
77- // Get user's workflows
77+ // Get workflows that user can access through direct ownership OR workspace permissions
7878 const userWorkflows = await db
7979 . select ( { id : workflow . id , folderId : workflow . folderId } )
8080 . from ( workflow )
81- . where ( eq ( workflow . userId , userId ) )
81+ . leftJoin (
82+ permissions ,
83+ and (
84+ eq ( permissions . entityType , 'workspace' ) ,
85+ eq ( permissions . entityId , workflow . workspaceId ) ,
86+ eq ( permissions . userId , userId )
87+ )
88+ )
89+ . where (
90+ or (
91+ eq ( workflow . userId , userId ) ,
92+ and ( eq ( permissions . userId , userId ) , eq ( permissions . entityType , 'workspace' ) )
93+ )
94+ )
8295
8396 const userWorkflowIds = userWorkflows . map ( ( w ) => w . id )
8497
0 commit comments