Skip to content

Commit 4433100

Browse files
improvement(logs): make perms workspace scoped (#759)
1 parent 92a998d commit 4433100

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

apps/sim/app/api/logs/enhanced/route.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { z } from 'zod'
44
import { getSession } from '@/lib/auth'
55
import { createLogger } from '@/lib/logs/console-logger'
66
import { db } from '@/db'
7-
import { workflow, workflowExecutionBlocks, workflowExecutionLogs } from '@/db/schema'
7+
import { permissions, workflow, workflowExecutionBlocks, workflowExecutionLogs } from '@/db/schema'
88

99
const 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

Comments
 (0)