Skip to content

Commit 38c8356

Browse files
committed
address more comments
1 parent 1dc9b35 commit 38c8356

3 files changed

Lines changed: 20 additions & 20 deletions

File tree

apps/sim/app/api/workflows/[id]/deploy/route.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import {
1212
createErrorResponse,
1313
createSuccessResponse,
1414
} from '@/app/api/workflows/utils'
15+
import {
16+
PublicApiNotAllowedError,
17+
validatePublicApiAllowed,
18+
} from '@/ee/access-control/utils/permission-check'
1519

1620
const logger = createLogger('WorkflowDeployAPI')
1721

@@ -154,9 +158,6 @@ export const PATCH = withRouteHandler(
154158
}
155159

156160
if (isPublicApi) {
157-
const { validatePublicApiAllowed, PublicApiNotAllowedError } = await import(
158-
'@/ee/access-control/utils/permission-check'
159-
)
160161
try {
161162
await validatePublicApiAllowed(session?.user?.id, workflowData?.workspaceId ?? undefined)
162163
} catch (err) {

apps/sim/app/api/workflows/[id]/execute/route.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import { db } from '@sim/db'
2+
import { workflow as workflowTable } from '@sim/db/schema'
13
import { createLogger } from '@sim/logger'
24
import { toError } from '@sim/utils/errors'
35
import { generateId, isValidUuid } from '@sim/utils/id'
6+
import { eq } from 'drizzle-orm'
47
import { type NextRequest, NextResponse } from 'next/server'
58
import { z } from 'zod'
69
import { AuthType, checkHybridAuth, hasExternalApiCredentials } from '@/lib/auth/hybrid'
@@ -48,6 +51,10 @@ import {
4851
workflowHasResponseBlock,
4952
} from '@/lib/workflows/utils'
5053
import { executeWorkflowJob, type WorkflowExecutionPayload } from '@/background/workflow-execution'
54+
import {
55+
PublicApiNotAllowedError,
56+
validatePublicApiAllowed,
57+
} from '@/ee/access-control/utils/permission-check'
5158
import { normalizeName } from '@/executor/constants'
5259
import { ExecutionSnapshot } from '@/executor/execution/snapshot'
5360
import type {
@@ -312,9 +319,7 @@ async function handleExecutePost(
312319
return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 })
313320
}
314321

315-
const { db: dbClient, workflow: workflowTable } = await import('@sim/db')
316-
const { eq } = await import('drizzle-orm')
317-
const [wf] = await dbClient
322+
const [wf] = await db
318323
.select({
319324
isPublicApi: workflowTable.isPublicApi,
320325
isDeployed: workflowTable.isDeployed,
@@ -325,23 +330,17 @@ async function handleExecutePost(
325330
.where(eq(workflowTable.id, workflowId))
326331
.limit(1)
327332

328-
if (!wf?.isPublicApi || !wf.isDeployed) {
329-
return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 })
330-
}
331-
332-
const { isPublicApiDisabled } = await import('@/lib/core/config/feature-flags')
333-
if (isPublicApiDisabled) {
333+
if (!wf?.isPublicApi || !wf.isDeployed || !wf.workspaceId) {
334334
return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 })
335335
}
336336

337-
if (wf.workspaceId) {
338-
const { getUserPermissionConfig } = await import(
339-
'@/ee/access-control/utils/permission-check'
340-
)
341-
const ownerConfig = await getUserPermissionConfig(wf.userId, wf.workspaceId)
342-
if (ownerConfig?.disablePublicApi) {
337+
try {
338+
await validatePublicApiAllowed(wf.userId, wf.workspaceId)
339+
} catch (err) {
340+
if (err instanceof PublicApiNotAllowedError) {
343341
return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 })
344342
}
343+
throw err
345344
}
346345

347346
userId = wf.userId

apps/sim/ee/access-control/utils/permission-check.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
getAllowedIntegrationsFromEnv,
88
isAccessControlEnabled,
99
isHosted,
10+
isInvitationsDisabled,
11+
isPublicApiDisabled,
1012
} from '@/lib/core/config/feature-flags'
1113
import {
1214
DEFAULT_PERMISSION_GROUP_CONFIG,
@@ -302,7 +304,6 @@ export async function validateInvitationsAllowed(
302304
userId: string | undefined,
303305
workspaceId?: string
304306
): Promise<void> {
305-
const { isInvitationsDisabled } = await import('@/lib/core/config/feature-flags')
306307
if (isInvitationsDisabled) {
307308
logger.warn('Invitations blocked by feature flag')
308309
throw new InvitationsNotAllowedError()
@@ -333,7 +334,6 @@ export async function validatePublicApiAllowed(
333334
userId: string | undefined,
334335
workspaceId?: string
335336
): Promise<void> {
336-
const { isPublicApiDisabled } = await import('@/lib/core/config/feature-flags')
337337
if (isPublicApiDisabled) {
338338
logger.warn('Public API blocked by feature flag')
339339
throw new PublicApiNotAllowedError()

0 commit comments

Comments
 (0)