Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions apps/sim/app/api/workflows/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { type NextRequest, NextResponse } from 'next/server'
import { z } from 'zod'
import { getSession } from '@/lib/auth'
import { createLogger } from '@/lib/logs/console/logger'
import { getUserEntityPermissions } from '@/lib/permissions/utils'
import { generateRequestId } from '@/lib/utils'
import { verifyWorkspaceMembership } from './utils'

Expand Down Expand Up @@ -94,6 +95,24 @@ export async function POST(req: NextRequest) {
const body = await req.json()
const { name, description, color, workspaceId, folderId } = CreateWorkflowSchema.parse(body)

if (workspaceId) {
const workspacePermission = await getUserEntityPermissions(
session.user.id,
'workspace',
workspaceId
)

if (!workspacePermission || workspacePermission === 'read') {
logger.warn(
`[${requestId}] User ${session.user.id} attempted to create workflow in workspace ${workspaceId} without write permissions`
)
return NextResponse.json(
{ error: 'Write or Admin access required to create workflows in this workspace' },
{ status: 403 }
)
}
}

const workflowId = crypto.randomUUID()
const now = new Date()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,12 @@ export function CreateMenu({ onCreateWorkflow, isCreatingWorkflow = false }: Cre
>
{/* New Workflow */}
<button
className={cn(menuItemClassName, isCreatingWorkflow && 'cursor-not-allowed opacity-50')}
className={cn(
menuItemClassName,
(isCreatingWorkflow || !userPermissions.canEdit) && 'cursor-not-allowed opacity-50'
)}
onClick={handleCreateWorkflow}
disabled={isCreatingWorkflow}
disabled={isCreatingWorkflow || !userPermissions.canEdit}
>
<Plus className={iconClassName} />
<span className={textClassName}>
Expand All @@ -335,27 +338,31 @@ export function CreateMenu({ onCreateWorkflow, isCreatingWorkflow = false }: Cre

{/* New Folder */}
<button
className={cn(menuItemClassName, isCreating && 'cursor-not-allowed opacity-50')}
className={cn(
menuItemClassName,
(isCreating || !userPermissions.canEdit) && 'cursor-not-allowed opacity-50'
)}
onClick={handleCreateFolder}
disabled={isCreating}
disabled={isCreating || !userPermissions.canEdit}
>
<Folder className={iconClassName} />
<span className={textClassName}>{isCreating ? 'Creating...' : 'New folder'}</span>
</button>

{/* Import Workflow */}
{userPermissions.canEdit && (
<button
className={cn(menuItemClassName, isImporting && 'cursor-not-allowed opacity-50')}
onClick={handleImportWorkflow}
disabled={isImporting}
>
<Download className={iconClassName} />
<span className={textClassName}>
{isImporting ? 'Importing...' : 'Import workflow'}
</span>
</button>
)}
<button
className={cn(
menuItemClassName,
(isImporting || !userPermissions.canEdit) && 'cursor-not-allowed opacity-50'
)}
onClick={handleImportWorkflow}
disabled={isImporting || !userPermissions.canEdit}
>
<Download className={iconClassName} />
<span className={textClassName}>
{isImporting ? 'Importing...' : 'Import workflow'}
</span>
</button>
</PopoverContent>
</Popover>

Expand Down