Skip to content

Commit 97a4b34

Browse files
committed
fix perms issue
1 parent 433d5b3 commit 97a4b34

File tree

14 files changed

+50
-182
lines changed

14 files changed

+50
-182
lines changed

.cursor/debug.log

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{"location":"persistence/utils.ts:loadWorkflowFromNormalizedTables","message":"Loaded edges from DB","data":{"edgeCount":1,"edges":[{"id":"edge-1","source":"block-1","target":"block-2"}],"rawEdges":[{"id":"edge-1","sourceBlockId":"block-1","targetBlockId":"block-2"}]},"timestamp":1767171471369,"sessionId":"debug-session","hypothesisId":"C"}
2+
{"location":"persistence/utils.ts:loadWorkflowFromNormalizedTables","message":"Loaded edges from DB","data":{"edgeCount":1,"edges":[{"id":"edge-1","source":"block-1","target":"block-2"}],"rawEdges":[{"id":"edge-1","sourceBlockId":"block-1","targetBlockId":"block-2"}]},"timestamp":1767171471424,"sessionId":"debug-session","hypothesisId":"C"}
3+
{"location":"persistence/utils.ts:loadWorkflowFromNormalizedTables","message":"Loaded edges from DB","data":{"edgeCount":0,"edges":[],"rawEdges":[]},"timestamp":1767171471443,"sessionId":"debug-session","hypothesisId":"C"}
4+
{"location":"persistence/utils.ts:loadWorkflowFromNormalizedTables","message":"Loaded edges from DB","data":{"edgeCount":0,"edges":[],"rawEdges":[]},"timestamp":1767171471634,"sessionId":"debug-session","hypothesisId":"C"}
5+
{"location":"persistence/utils.ts:loadWorkflowFromNormalizedTables","message":"Loaded edges from DB","data":{"edgeCount":0,"edges":[],"rawEdges":[]},"timestamp":1767171471659,"sessionId":"debug-session","hypothesisId":"C"}
6+
{"location":"persistence/utils.ts:loadWorkflowFromNormalizedTables","message":"Loaded edges from DB","data":{"edgeCount":0,"edges":[],"rawEdges":[]},"timestamp":1767171471677,"sessionId":"debug-session","hypothesisId":"C"}
7+
{"location":"persistence/utils.ts:loadWorkflowFromNormalizedTables","message":"Loaded edges from DB","data":{"edgeCount":0,"edges":[],"rawEdges":[]},"timestamp":1767171471723,"sessionId":"debug-session","hypothesisId":"C"}
8+
{"location":"persistence/utils.ts:loadWorkflowFromNormalizedTables","message":"Loaded edges from DB","data":{"edgeCount":0,"edges":[],"rawEdges":[]},"timestamp":1767171471742,"sessionId":"debug-session","hypothesisId":"C"}

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -721,14 +721,17 @@ const WorkflowContent = React.memo(() => {
721721

722722
/** Creates a standardized edge object for workflow connections. */
723723
const createEdgeObject = useCallback(
724-
(sourceId: string, targetId: string, sourceHandle: string): Edge => ({
725-
id: crypto.randomUUID(),
726-
source: sourceId,
727-
target: targetId,
728-
sourceHandle,
729-
targetHandle: 'target',
730-
type: 'workflowEdge',
731-
}),
724+
(sourceId: string, targetId: string, sourceHandle: string): Edge => {
725+
const edge = {
726+
id: crypto.randomUUID(),
727+
source: sourceId,
728+
target: targetId,
729+
sourceHandle,
730+
targetHandle: 'target',
731+
type: 'workflowEdge',
732+
}
733+
return edge
734+
},
732735
[]
733736
)
734737

apps/sim/hooks/use-collaborative-workflow.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,6 @@ export function useCollaborativeWorkflow() {
350350
case 'remove':
351351
variablesStore.deleteVariable(payload.variableId)
352352
break
353-
case 'duplicate':
354-
variablesStore.duplicateVariable(payload.sourceVariableId, payload.id)
355-
break
356353
}
357354
} else if (target === 'workflow') {
358355
switch (operation) {
@@ -1309,25 +1306,6 @@ export function useCollaborativeWorkflow() {
13091306
[executeQueuedOperation, variablesStore, cancelOperationsForVariable]
13101307
)
13111308

1312-
const collaborativeDuplicateVariable = useCallback(
1313-
(variableId: string) => {
1314-
const newId = crypto.randomUUID()
1315-
const sourceVariable = useVariablesStore.getState().variables[variableId]
1316-
if (!sourceVariable) return null
1317-
1318-
executeQueuedOperation(
1319-
'duplicate',
1320-
'variable',
1321-
{ sourceVariableId: variableId, id: newId },
1322-
() => {
1323-
variablesStore.duplicateVariable(variableId, newId)
1324-
}
1325-
)
1326-
return newId
1327-
},
1328-
[executeQueuedOperation, variablesStore]
1329-
)
1330-
13311309
const collaborativeBatchAddBlocks = useCallback(
13321310
(
13331311
blocks: BlockState[],
@@ -1550,7 +1528,6 @@ export function useCollaborativeWorkflow() {
15501528
collaborativeUpdateVariable,
15511529
collaborativeAddVariable,
15521530
collaborativeDeleteVariable,
1553-
collaborativeDuplicateVariable,
15541531

15551532
// Collaborative loop/parallel operations
15561533
collaborativeUpdateLoopType,

apps/sim/hooks/use-undo-redo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ export function useUndoRedo() {
356356
break
357357
}
358358
case 'batch-add-blocks': {
359-
const batchAddOp = entry.operation as BatchRemoveBlocksOperation
359+
const batchAddOp = entry.operation as BatchAddBlocksOperation
360360
const { blockSnapshots, edgeSnapshots, subBlockValues } = batchAddOp.data
361361

362362
const blocksToAdd = blockSnapshots.filter((b) => !workflowStore.blocks[b.id])

apps/sim/socket/database/operations.ts

Lines changed: 17 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,20 @@ async function handleBlocksOperationTx(
598598

599599
const blockIdsArray = Array.from(allBlocksToDelete)
600600

601+
// Collect parent IDs BEFORE deleting blocks
602+
const parentIds = new Set<string>()
603+
for (const id of ids) {
604+
const parentInfo = await tx
605+
.select({ parentId: sql<string | null>`${workflowBlocks.data}->>'parentId'` })
606+
.from(workflowBlocks)
607+
.where(and(eq(workflowBlocks.id, id), eq(workflowBlocks.workflowId, workflowId)))
608+
.limit(1)
609+
610+
if (parentInfo.length > 0 && parentInfo[0].parentId) {
611+
parentIds.add(parentInfo[0].parentId)
612+
}
613+
}
614+
601615
// Clean up external webhooks
602616
const webhooksToCleanup = await tx
603617
.select({
@@ -653,17 +667,9 @@ async function handleBlocksOperationTx(
653667
and(eq(workflowBlocks.workflowId, workflowId), inArray(workflowBlocks.id, blockIdsArray))
654668
)
655669

656-
// Update parent subflow node lists
657-
for (const id of ids) {
658-
const parentInfo = await tx
659-
.select({ parentId: sql<string | null>`${workflowBlocks.data}->>'parentId'` })
660-
.from(workflowBlocks)
661-
.where(and(eq(workflowBlocks.id, id), eq(workflowBlocks.workflowId, workflowId)))
662-
.limit(1)
663-
664-
if (parentInfo.length > 0 && parentInfo[0].parentId) {
665-
await updateSubflowNodeList(tx, workflowId, parentInfo[0].parentId)
666-
}
670+
// Update parent subflow node lists using pre-collected parent IDs
671+
for (const parentId of parentIds) {
672+
await updateSubflowNodeList(tx, workflowId, parentId)
667673
}
668674

669675
logger.info(
@@ -905,53 +911,6 @@ async function handleVariableOperationTx(
905911
break
906912
}
907913

908-
case 'duplicate': {
909-
if (!payload.sourceVariableId || !payload.id) {
910-
throw new Error('Missing required fields for duplicate variable operation')
911-
}
912-
913-
const sourceVariable = currentVariables[payload.sourceVariableId]
914-
if (!sourceVariable) {
915-
throw new Error(`Source variable ${payload.sourceVariableId} not found`)
916-
}
917-
918-
// Create duplicated variable with unique name
919-
const baseName = `${sourceVariable.name} (copy)`
920-
let uniqueName = baseName
921-
let nameIndex = 1
922-
923-
// Ensure name uniqueness
924-
const existingNames = Object.values(currentVariables).map((v: any) => v.name)
925-
while (existingNames.includes(uniqueName)) {
926-
uniqueName = `${baseName} (${nameIndex})`
927-
nameIndex++
928-
}
929-
930-
const duplicatedVariable = {
931-
...sourceVariable,
932-
id: payload.id,
933-
name: uniqueName,
934-
}
935-
936-
const updatedVariables = {
937-
...currentVariables,
938-
[payload.id]: duplicatedVariable,
939-
}
940-
941-
await tx
942-
.update(workflow)
943-
.set({
944-
variables: updatedVariables,
945-
updatedAt: new Date(),
946-
})
947-
.where(eq(workflow.id, workflowId))
948-
949-
logger.debug(
950-
`Duplicated variable ${payload.sourceVariableId} -> ${payload.id} (${uniqueName}) in workflow ${workflowId}`
951-
)
952-
break
953-
}
954-
955914
default:
956915
logger.warn(`Unknown variable operation: ${operation}`)
957916
throw new Error(`Unsupported variable operation: ${operation}`)

apps/sim/socket/handlers/operations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export function setupOperationsHandlers(
184184
return
185185
}
186186

187-
if (target === 'variable' && ['add', 'remove', 'duplicate'].includes(operation)) {
187+
if (target === 'variable' && ['add', 'remove'].includes(operation)) {
188188
// Persist first, then broadcast
189189
await persistWorkflowOperation(workflowId, {
190190
operation,

apps/sim/socket/middleware/permissions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const logger = createLogger('SocketPermissions')
99
// Define operation permissions based on role
1010
const ROLE_PERMISSIONS: Record<string, string[]> = {
1111
admin: [
12+
'add',
13+
'remove',
1214
'update',
1315
'update-position',
1416
'batch-update-positions',
@@ -24,6 +26,8 @@ const ROLE_PERMISSIONS: Record<string, string[]> = {
2426
'replace-state',
2527
],
2628
write: [
29+
'add',
30+
'remove',
2731
'update',
2832
'update-position',
2933
'batch-update-positions',

apps/sim/socket/validation/schemas.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,6 @@ export const VariableOperationSchema = z.union([
112112
timestamp: z.number(),
113113
operationId: z.string().optional(),
114114
}),
115-
z.object({
116-
operation: z.literal('duplicate'),
117-
target: z.literal('variable'),
118-
payload: z.object({
119-
sourceVariableId: z.string(),
120-
id: z.string(),
121-
}),
122-
timestamp: z.number(),
123-
operationId: z.string().optional(),
124-
}),
125115
])
126116

127117
export const WorkflowStateOperationSchema = z.object({

apps/sim/stores/panel/variables/store.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -283,39 +283,6 @@ export const useVariablesStore = create<VariablesStore>()(
283283
})
284284
},
285285

286-
duplicateVariable: (id, providedId?: string) => {
287-
const state = get()
288-
if (!state.variables[id]) return ''
289-
290-
const variable = state.variables[id]
291-
const newId = providedId || crypto.randomUUID()
292-
293-
const workflowVariables = get().getVariablesByWorkflowId(variable.workflowId)
294-
const baseName = `${variable.name} (copy)`
295-
let uniqueName = baseName
296-
let nameIndex = 1
297-
298-
while (workflowVariables.some((v) => v.name === uniqueName)) {
299-
uniqueName = `${baseName} (${nameIndex})`
300-
nameIndex++
301-
}
302-
303-
set((state) => ({
304-
variables: {
305-
...state.variables,
306-
[newId]: {
307-
id: newId,
308-
workflowId: variable.workflowId,
309-
name: uniqueName,
310-
type: variable.type,
311-
value: variable.value,
312-
},
313-
},
314-
}))
315-
316-
return newId
317-
},
318-
319286
getVariablesByWorkflowId: (workflowId) => {
320287
return Object.values(get().variables).filter((variable) => variable.workflowId === workflowId)
321288
},

apps/sim/stores/panel/variables/types.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ export interface VariablesStore {
4343

4444
deleteVariable: (id: string) => void
4545

46-
/**
47-
* Duplicates a variable with a "(copy)" suffix, ensuring name uniqueness
48-
* Optionally accepts a predetermined ID for collaborative operations
49-
*/
50-
duplicateVariable: (id: string, providedId?: string) => string
51-
5246
/**
5347
* Returns all variables for a specific workflow
5448
*/

0 commit comments

Comments
 (0)