@@ -6,9 +6,8 @@ import { getErrorMessage } from '@sim/utils/errors'
66import { assertWorkflowMutable , WorkflowLockedError } from '@sim/workflow-authz'
77import { isWorkflowBlockProtected } from '@sim/workflow-types/workflow'
88import { and , eq } from 'drizzle-orm'
9- import { evictRevokedSocket } from '@/handlers/eviction'
109import type { AuthenticatedSocket } from '@/middleware/auth'
11- import { authorizeSocketOperation } from '@/middleware/permissions'
10+ import { checkRolePermission } from '@/middleware/permissions'
1211import type { IRoomManager } from '@/rooms'
1312
1413const logger = createLogger ( 'SubblocksHandlers' )
@@ -137,44 +136,18 @@ export function setupSubblocksHandlers(socket: AuthenticatedSocket, roomManager:
137136 return
138137 }
139138
140- const authorization = await authorizeSocketOperation ( {
141- roomManager,
142- workflowId,
143- socketId : socket . id ,
144- userId : session . userId ,
145- presence : userPresence ,
146- operation : SUBBLOCK_OPERATIONS . UPDATE ,
147- } )
148-
149- if ( authorization . accessRevoked ) {
150- socket . emit ( 'operation-forbidden' , {
151- type : 'ACCESS_REVOKED' ,
152- message : authorization . reason || 'Access to this workflow has been revoked' ,
153- operation : SUBBLOCK_OPERATIONS . UPDATE ,
154- target : 'subblock' ,
155- } )
156- if ( operationId ) {
157- socket . emit ( 'operation-failed' , {
158- operationId,
159- error : authorization . reason || 'Access revoked' ,
160- retryable : false ,
161- } )
162- }
163- await evictRevokedSocket ( roomManager , socket , workflowId )
164- return
165- }
166-
167- if ( ! authorization . allowed ) {
139+ const permissionCheck = checkRolePermission ( userPresence . role , SUBBLOCK_OPERATIONS . UPDATE )
140+ if ( ! permissionCheck . allowed ) {
168141 socket . emit ( 'operation-forbidden' , {
169142 type : 'INSUFFICIENT_PERMISSIONS' ,
170- message : authorization . reason || 'Insufficient permissions' ,
143+ message : permissionCheck . reason || 'Insufficient permissions' ,
171144 operation : SUBBLOCK_OPERATIONS . UPDATE ,
172145 target : 'subblock' ,
173146 } )
174147 if ( operationId ) {
175148 socket . emit ( 'operation-failed' , {
176149 operationId,
177- error : authorization . reason || 'Insufficient permissions' ,
150+ error : permissionCheck . reason || 'Insufficient permissions' ,
178151 retryable : false ,
179152 } )
180153 }
0 commit comments