Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 3 additions & 4 deletions apps/sim/app/api/credentials/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { getSession } from '@/lib/auth'
import { encryptSecret } from '@/lib/core/security/encryption'
import { getCredentialActorContext } from '@/lib/credentials/access'
import {
deleteWorkspaceEnvCredentials,
syncPersonalEnvCredentialsForUser,
syncWorkspaceEnvCredentials,
} from '@/lib/credentials/environment'
import { captureServerEvent } from '@/lib/posthog/server'

Expand Down Expand Up @@ -317,10 +317,9 @@ export async function DELETE(
set: { variables: current, updatedAt: new Date() },
})

await syncWorkspaceEnvCredentials({
await deleteWorkspaceEnvCredentials({
workspaceId: access.credential.workspaceId,
envKeys: Object.keys(current),
actingUserId: session.user.id,
removedKeys: [access.credential.envKey],
})

captureServerEvent(
Expand Down
18 changes: 7 additions & 11 deletions apps/sim/app/api/workspaces/[id]/environment/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { AuditAction, AuditResourceType, recordAudit } from '@/lib/audit/log'
import { getSession } from '@/lib/auth'
import { encryptSecret } from '@/lib/core/security/encryption'
import { generateRequestId } from '@/lib/core/utils/request'
import { syncWorkspaceEnvCredentials } from '@/lib/credentials/environment'
import {
createWorkspaceEnvCredentials,
deleteWorkspaceEnvCredentials,
} from '@/lib/credentials/environment'
import { getPersonalAndWorkspaceEnv } from '@/lib/environment/utils'
import { getUserEntityPermissions, getWorkspaceById } from '@/lib/workspaces/permissions/utils'

Expand Down Expand Up @@ -126,11 +129,8 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
set: { variables: merged, updatedAt: new Date() },
})

await syncWorkspaceEnvCredentials({
workspaceId,
envKeys: Object.keys(merged),
actingUserId: userId,
})
const newKeys = Object.keys(variables).filter((k) => !(k in existingEncrypted))
await createWorkspaceEnvCredentials({ workspaceId, newKeys, actingUserId: userId })

recordAudit({
workspaceId,
Expand Down Expand Up @@ -215,11 +215,7 @@ export async function DELETE(
set: { variables: current, updatedAt: new Date() },
})

await syncWorkspaceEnvCredentials({
workspaceId,
envKeys: Object.keys(current),
actingUserId: userId,
})
await deleteWorkspaceEnvCredentials({ workspaceId, removedKeys: keys })

recordAudit({
workspaceId,
Expand Down
Loading
Loading