11import { db } from '@sim/db'
2- import { permissions , workflow , workflowExecutionLogs } from '@sim/db/schema'
2+ import { workflow , workflowExecutionLogs } from '@sim/db/schema'
33import { createLogger } from '@sim/logger'
44import { generateId } from '@sim/utils/id'
5- import { and , eq } from 'drizzle-orm'
5+ import { eq } from 'drizzle-orm'
66import { type NextRequest , NextResponse } from 'next/server'
77import { v1GetLogContract } from '@/lib/api/contracts/v1/logs'
88import { parseRequest } from '@/lib/api/server'
99import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
1010import { createApiResponse , getUserLimits } from '@/app/api/v1/logs/meta'
11- import { checkRateLimit , createRateLimitResponse } from '@/app/api/v1/middleware'
11+ import {
12+ checkRateLimit ,
13+ createRateLimitResponse ,
14+ validateWorkspaceAccess ,
15+ } from '@/app/api/v1/middleware'
1216
1317const logger = createLogger ( 'V1LogDetailsAPI' )
1418
@@ -37,6 +41,7 @@ export const GET = withRouteHandler(
3741 . select ( {
3842 id : workflowExecutionLogs . id ,
3943 workflowId : workflowExecutionLogs . workflowId ,
44+ workspaceId : workflowExecutionLogs . workspaceId ,
4045 executionId : workflowExecutionLogs . executionId ,
4146 stateSnapshotId : workflowExecutionLogs . stateSnapshotId ,
4247 level : workflowExecutionLogs . level ,
@@ -59,14 +64,6 @@ export const GET = withRouteHandler(
5964 } )
6065 . from ( workflowExecutionLogs )
6166 . leftJoin ( workflow , eq ( workflowExecutionLogs . workflowId , workflow . id ) )
62- . innerJoin (
63- permissions ,
64- and (
65- eq ( permissions . entityType , 'workspace' ) ,
66- eq ( permissions . entityId , workflowExecutionLogs . workspaceId ) ,
67- eq ( permissions . userId , userId )
68- )
69- )
7067 . where ( eq ( workflowExecutionLogs . id , id ) )
7168 . limit ( 1 )
7269
@@ -75,6 +72,9 @@ export const GET = withRouteHandler(
7572 return NextResponse . json ( { error : 'Log not found' } , { status : 404 } )
7673 }
7774
75+ const accessError = await validateWorkspaceAccess ( rateLimit , userId , log . workspaceId )
76+ if ( accessError ) return accessError
77+
7878 const workflowSummary = {
7979 id : log . workflowId ,
8080 name : log . workflowName || 'Deleted Workflow' ,
0 commit comments