-
Notifications
You must be signed in to change notification settings - Fork 12k
feat: Add Actor pattern foundation for booking audit logging #24503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
hariombalhara
wants to merge
2
commits into
feat/booking-audit-log
from
devin/booking-audit-integration-1760614786
+140
−1
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /** | ||
| * Represents the entity that performed a booking action | ||
| */ | ||
| export type Actor = { | ||
| /** | ||
| * The type of actor performing the action | ||
| */ | ||
| type: "User" | "System" | "Attendee"; | ||
|
|
||
| /** | ||
| * The user ID if the actor is a User or Attendee | ||
| * Null if the actor is the System | ||
| */ | ||
| userId?: number | null; | ||
|
|
||
| /** | ||
| * Additional metadata about the actor | ||
| * e.g., email for Attendee, automation name for System | ||
| */ | ||
| metadata?: { | ||
| email?: string; | ||
| name?: string; | ||
| automationName?: string; | ||
| [key: string]: unknown; | ||
| }; | ||
| }; | ||
|
|
||
| /** | ||
| * Creates an Actor representing a User | ||
| */ | ||
| export function createUserActor(userId: number, metadata?: Actor["metadata"]): Actor { | ||
| return { | ||
| type: "User", | ||
| userId, | ||
| metadata, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Creates an Actor representing the System | ||
| */ | ||
| export function createSystemActor(metadata?: Actor["metadata"]): Actor { | ||
| return { | ||
| type: "System", | ||
| userId: null, | ||
| metadata, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Creates an Actor representing an Attendee | ||
| */ | ||
| export function createAttendeeActor(email: string, metadata?: Actor["metadata"]): Actor { | ||
| return { | ||
| type: "Attendee", | ||
| userId: null, | ||
| metadata: { | ||
| ...metadata, | ||
| email, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Extracts the user ID from an actor if available | ||
| */ | ||
| export function getActorUserId(actor?: Actor): number | null | undefined { | ||
| return actor?.userId; | ||
| } | ||
|
|
||
| /** | ||
| * Converts an actor to the string representation needed for audit logs | ||
| */ | ||
| export function actorToAuditString(actor?: Actor): string | null { | ||
| if (!actor) return null; | ||
|
|
||
| if (actor.type === "User") { | ||
| return `User:${actor.userId}`; | ||
| } | ||
|
|
||
| if (actor.type === "Attendee" && actor.metadata?.email) { | ||
| return `Attendee:${actor.metadata.email}`; | ||
| } | ||
|
|
||
| if (actor.type === "System") { | ||
| return actor.metadata?.automationName ? `System:${actor.metadata.automationName}` : "System"; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import type { Prisma } from "@prisma/client"; | ||
|
|
||
| import { PrismaBookingAuditRepository } from "@calcom/lib/server/repository/PrismaBookingAuditRepository"; | ||
| import type { BookingAuditType, BookingAuditAction } from "@calcom/prisma/enums"; | ||
|
|
||
| import type { Actor } from "../types/actor"; | ||
| import { getActorUserId } from "../types/actor"; | ||
|
|
||
| const auditRepository = new PrismaBookingAuditRepository(); | ||
|
|
||
| export async function logBookingAudit({ | ||
| bookingId, | ||
| actor, | ||
| type, | ||
| action, | ||
| data, | ||
| }: { | ||
| bookingId: string | number; | ||
| actor?: Actor; | ||
| type: BookingAuditType; | ||
| action?: BookingAuditAction; | ||
| data?: Prisma.InputJsonValue; | ||
| }): Promise<void> { | ||
| const userId = getActorUserId(actor); | ||
|
|
||
| await auditRepository.create({ | ||
| bookingId: String(bookingId), | ||
| userId: userId ? String(userId) : null, | ||
| type, | ||
| action, | ||
| data, | ||
| }); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule violated: Avoid Logging Sensitive Information
Audit log serialization must not expose attendee emails. Returning
Attendee:${actor.metadata.email}records PII directly into logs, violating the policy against logging sensitive data. Replace this with a non-PII identifier (e.g., just "Attendee") or a hashed token.Prompt for AI agents