Skip to content

Commit 39c014a

Browse files
PlaneInABottletest
authored andcommitted
fix: align workflow audit metadata helpers
Use the shared audit actor helper consistently so workflow deletion matches deploy behavior and remove the redundant deploy wrapper raised in review.
1 parent 5499177 commit 39c014a

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ async function validateLifecycleAdminAccess(
6262
}
6363
}
6464

65-
function getLifecycleAuditActor(auth: AuthResult | null | undefined) {
66-
return getAuditActorMetadata(auth)
67-
}
68-
6965
export async function GET(request: NextRequest, { params }: { params: Promise<{ id: string }> }) {
7066
const requestId = generateRequestId()
7167
const { id } = await params
@@ -307,7 +303,7 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
307303
// Sync MCP tools with the latest parameter schema
308304
await syncMcpToolsForWorkflow({ workflowId: id, requestId, context: 'deploy' })
309305

310-
const { actorName, actorEmail } = getLifecycleAuditActor(auth)
306+
const { actorName, actorEmail } = getAuditActorMetadata(auth)
311307

312308
recordAudit({
313309
workspaceId: workflowData?.workspaceId || null,
@@ -432,7 +428,7 @@ export async function DELETE(
432428
// Silently fail
433429
}
434430

435-
const { actorName, actorEmail } = getLifecycleAuditActor(auth)
431+
const { actorName, actorEmail } = getAuditActorMetadata(auth)
436432

437433
recordAudit({
438434
workspaceId: workflowData?.workspaceId || null,

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,13 @@ describe('Workflow By ID API Route', () => {
385385

386386
mockValidateWorkflowAccess.mockResolvedValue({
387387
workflow: mockWorkflow,
388-
auth: { success: true, userId: 'api-user-1', authType: 'api_key' },
388+
auth: {
389+
success: true,
390+
userId: 'api-user-1',
391+
authType: 'api_key',
392+
userName: 'API Key Actor',
393+
userEmail: null,
394+
},
389395
})
390396
mockGetWorkflowById.mockResolvedValue(mockWorkflow)
391397
mockAuthorizeWorkflowByWorkspacePermission.mockResolvedValue({
@@ -414,6 +420,13 @@ describe('Workflow By ID API Route', () => {
414420

415421
expect(response.status).toBe(200)
416422
expect(mockAuthorizeWorkflowByWorkspacePermission).not.toHaveBeenCalled()
423+
expect(auditMock.recordAudit).toHaveBeenCalledWith(
424+
expect.objectContaining({
425+
actorId: 'api-user-1',
426+
actorName: undefined,
427+
actorEmail: undefined,
428+
})
429+
)
417430
})
418431

419432
it('should prevent deletion of the last workflow in workspace', async () => {

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { createLogger } from '@sim/logger'
44
import { and, eq, isNull, ne } from 'drizzle-orm'
55
import { type NextRequest, NextResponse } from 'next/server'
66
import { z } from 'zod'
7+
import { getAuditActorMetadata } from '@/lib/audit/actor-metadata'
78
import { AuditAction, AuditResourceType, recordAudit } from '@/lib/audit/log'
89
import { AuthType, checkHybridAuth, checkSessionOrInternalAuth } from '@/lib/auth/hybrid'
910
import { generateRequestId } from '@/lib/core/utils/request'
@@ -253,11 +254,13 @@ export async function DELETE(
253254
const elapsed = Date.now() - startTime
254255
logger.info(`[${requestId}] Successfully archived workflow ${workflowId} in ${elapsed}ms`)
255256

257+
const { actorName, actorEmail } = getAuditActorMetadata(auth)
258+
256259
recordAudit({
257260
workspaceId: workflowData.workspaceId || null,
258261
actorId: userId,
259-
actorName: auth.userName,
260-
actorEmail: auth.userEmail,
262+
actorName,
263+
actorEmail,
261264
action: AuditAction.WORKFLOW_DELETED,
262265
resourceType: AuditResourceType.WORKFLOW,
263266
resourceId: workflowId,

0 commit comments

Comments
 (0)