Skip to content

Commit 4222529

Browse files
committed
address comments
1 parent b126290 commit 4222529

4 files changed

Lines changed: 19 additions & 11 deletions

File tree

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,21 @@ export async function PATCH(request: NextRequest, { params }: { params: Promise<
168168
}
169169
})
170170

171+
const isOrgScoped = inv.kind === 'organization'
172+
const primaryWorkspaceId = inv.grants[0]?.workspaceId ?? null
171173
recordAudit({
172-
workspaceId: null,
174+
workspaceId: isOrgScoped ? null : primaryWorkspaceId,
173175
actorId: session.user.id,
174176
actorName: session.user.name ?? undefined,
175177
actorEmail: session.user.email ?? undefined,
176-
action: AuditAction.ORG_INVITATION_UPDATED,
177-
resourceType: AuditResourceType.ORGANIZATION,
178-
resourceId: inv.organizationId ?? inv.id,
179-
description: `Updated invitation for ${inv.email}`,
178+
action: isOrgScoped ? AuditAction.ORG_INVITATION_UPDATED : AuditAction.INVITATION_UPDATED,
179+
resourceType: isOrgScoped ? AuditResourceType.ORGANIZATION : AuditResourceType.WORKSPACE,
180+
resourceId: isOrgScoped ? (inv.organizationId ?? inv.id) : (primaryWorkspaceId ?? inv.id),
181+
description: `Updated ${inv.kind} invitation for ${inv.email}`,
180182
metadata: {
181183
invitationId: id,
182184
targetEmail: inv.email,
185+
kind: inv.kind,
183186
roleUpdate: role ?? null,
184187
grantUpdates: grantsToApply,
185188
},

apps/sim/app/api/organizations/[id]/invitations/route.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,15 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
395395
}
396396

397397
if (failedInvitations.length > 0) {
398-
return NextResponse.json({
399-
success: false,
400-
error: 'Some invitation emails failed to send.',
401-
message: `${sentInvitations.length} invitation(s) sent, ${failedInvitations.length} failed`,
402-
data: responseData,
403-
})
398+
return NextResponse.json(
399+
{
400+
success: false,
401+
error: 'Some invitation emails failed to send.',
402+
message: `${sentInvitations.length} invitation(s) sent, ${failedInvitations.length} failed`,
403+
data: responseData,
404+
},
405+
{ status: 207 }
406+
)
404407
}
405408

406409
return NextResponse.json({

apps/sim/lib/audit/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export const AuditAction = {
7373
INVITATION_REJECTED: 'invitation.rejected',
7474
INVITATION_RESENT: 'invitation.resent',
7575
INVITATION_REVOKED: 'invitation.revoked',
76+
INVITATION_UPDATED: 'invitation.updated',
7677

7778
// Knowledge Base Connectors
7879
CONNECTOR_CREATED: 'connector.created',

packages/testing/src/mocks/audit.mock.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export const auditMock = {
7777
INVITATION_REJECTED: 'invitation.rejected',
7878
INVITATION_RESENT: 'invitation.resent',
7979
INVITATION_REVOKED: 'invitation.revoked',
80+
INVITATION_UPDATED: 'invitation.updated',
8081
CONNECTOR_CREATED: 'connector.created',
8182
CONNECTOR_UPDATED: 'connector.updated',
8283
CONNECTOR_DELETED: 'connector.deleted',

0 commit comments

Comments
 (0)