feat: Add Actor pattern foundation for booking audit logging#24503
feat: Add Actor pattern foundation for booking audit logging#24503hariombalhara wants to merge 2 commits intofeat/booking-audit-logfrom
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
9ba3f1d to
fb0bf72
Compare
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
There was a problem hiding this comment.
4 issues found across 27 files
Prompt for AI agents (all 4 issues)
Understand the root cause of the following 4 issues and fix them.
<file name="packages/prisma/schema.prisma">
<violation number="1" location="packages/prisma/schema.prisma:2640">
Rule violated: **Prevent Direct NOW() Usage in Database Queries**
`BookingAudit.timestamp` uses `now()` as the default, which issues a timezone-less `NOW()` at the database layer. The ``Prevent Direct NOW() Usage in Database Queries`` guideline requires explicit UTC handling to avoid inconsistent audit timelines. Please switch to a UTC-aware expression.</violation>
</file>
<file name="apps/web/modules/bookings/views/bookings-single-view.tsx">
<violation number="1" location="apps/web/modules/bookings/views/bookings-single-view.tsx:697">
Removing the `whitespace-pre-line` class means multiline booking notes will now collapse into a single paragraph, so any attendee-entered line breaks are lost. Please keep `whitespace-pre-line` so the additional notes preserve their formatting.</violation>
</file>
<file name="packages/prisma/migrations/20250730030812_init_booking_audit/migration.sql">
<violation number="1" location="packages/prisma/migrations/20250730030812_init_booking_audit/migration.sql:10">
Please add an index on bookingId so audit lookups for a specific booking avoid full-table scans.</violation>
</file>
<file name="packages/features/bookings/lib/types/actor.ts">
<violation number="1" location="packages/features/bookings/lib/types/actor.ts:82">
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.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
| userId String? | ||
| type BookingAuditType | ||
| action BookingAuditAction? | ||
| timestamp DateTime @default(now()) |
There was a problem hiding this comment.
Rule violated: Prevent Direct NOW() Usage in Database Queries
BookingAudit.timestamp uses now() as the default, which issues a timezone-less NOW() at the database layer. The Prevent Direct NOW() Usage in Database Queries guideline requires explicit UTC handling to avoid inconsistent audit timelines. Please switch to a UTC-aware expression.
Prompt for AI agents
Address the following comment on packages/prisma/schema.prisma at line 2640:
<comment>`BookingAudit.timestamp` uses `now()` as the default, which issues a timezone-less `NOW()` at the database layer. The ``Prevent Direct NOW() Usage in Database Queries`` guideline requires explicit UTC handling to avoid inconsistent audit timelines. Please switch to a UTC-aware expression.</comment>
<file context>
@@ -2594,6 +2594,53 @@ model RolePermission {
+ userId String?
+ type BookingAuditType
+ action BookingAuditAction?
+ timestamp DateTime @default(now())
+ data Json?
+}
</file context>
| timestamp DateTime @default(now()) | |
| timestamp DateTime @default(dbgenerated("timezone('utc', now())")) |
| <div className="mt-9 font-medium">{t("additional_notes")}</div> | ||
| <div className="col-span-2 mb-2 mt-9"> | ||
| <p className="whitespace-pre-line break-words">{bookingInfo.description}</p> | ||
| <p className="break-words">{bookingInfo.description}</p> |
There was a problem hiding this comment.
Removing the whitespace-pre-line class means multiline booking notes will now collapse into a single paragraph, so any attendee-entered line breaks are lost. Please keep whitespace-pre-line so the additional notes preserve their formatting.
Prompt for AI agents
Address the following comment on apps/web/modules/bookings/views/bookings-single-view.tsx at line 697:
<comment>Removing the `whitespace-pre-line` class means multiline booking notes will now collapse into a single paragraph, so any attendee-entered line breaks are lost. Please keep `whitespace-pre-line` so the additional notes preserve their formatting.</comment>
<file context>
@@ -694,7 +694,7 @@ export default function Success(props: PageProps) {
<div className="mt-9 font-medium">{t("additional_notes")}</div>
<div className="col-span-2 mb-2 mt-9">
- <p className="whitespace-pre-line break-words">{bookingInfo.description}</p>
+ <p className="break-words">{bookingInfo.description}</p>
</div>
</>
</file context>
| <p className="break-words">{bookingInfo.description}</p> | |
| <p className="whitespace-pre-line break-words">{bookingInfo.description}</p> |
| -- CreateTable | ||
| CREATE TABLE "BookingAudit" ( | ||
| "id" TEXT NOT NULL, | ||
| "bookingId" TEXT NOT NULL, |
There was a problem hiding this comment.
Please add an index on bookingId so audit lookups for a specific booking avoid full-table scans.
Prompt for AI agents
Address the following comment on packages/prisma/migrations/20250730030812_init_booking_audit/migration.sql at line 10:
<comment>Please add an index on bookingId so audit lookups for a specific booking avoid full-table scans.</comment>
<file context>
@@ -0,0 +1,18 @@
+-- CreateTable
+CREATE TABLE "BookingAudit" (
+ "id" TEXT NOT NULL,
+ "bookingId" TEXT NOT NULL,
+ "userId" TEXT,
+ "type" "BookingAuditType" NOT NULL,
</file context>
| } | ||
|
|
||
| if (actor.type === "Attendee" && actor.metadata?.email) { | ||
| return `Attendee:${actor.metadata.email}`; |
There was a problem hiding this comment.
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
Address the following comment on packages/features/bookings/lib/types/actor.ts at line 82:
<comment>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.</comment>
<file context>
@@ -0,0 +1,90 @@
+ }
+
+ if (actor.type === "Attendee" && actor.metadata?.email) {
+ return `Attendee:${actor.metadata.email}`;
+ }
+
</file context>
| return `Attendee:${actor.metadata.email}`; | |
| return "Attendee"; |
fb0bf72 to
a9b00d4
Compare
- Define Actor type to represent who performs booking actions (User/System/Attendee) - Add helper functions for creating and working with actors - Integrate actor parameter into CancelBookingInput for cancellation tracking - Create comprehensive documentation for actor pattern implementation - Foundation for passing actor through all booking services for audit logging Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>
- Create logBookingAudit utility function for centralized audit logging - Add Actor type import to CreateBookingMeta - Update CreateBookingMeta to include optional actor parameter - Actor parameter enables audit logging for who performed booking actions - All actor parameters are optional for backward compatibility Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>
2c6ca7b to
dae9452
Compare
What does this PR do?
This PR integrates the existing
BookingAuditServiceinto the booking lifecycle to log all booking creation, cancellation, and confirmation events. This builds upon the audit logging infrastructure added in the base branch (PR #22817).Key Changes:
BookingAuditServicecalls tohandleNewBookingfor logging booking creationBookingAuditServicecalls tohandleCancelBookingfor logging cancellationsBookingAuditServicecalls tohandleConfirmationfor logging confirmationsBookingAuditmodel)Actortype definition and optional parameter support in booking typesImportant Notes:
BookingAudittable and related infrastructure exist from the base branchuserIddirectlyLink to Devin run: https://app.devin.ai/sessions/f3897a417558498991625bf1e8e03fe2
Requested by: @hariombalhara (hariom@cal.com)
Mandatory Tasks
How should this be tested?
Prerequisites:
feat/booking-audit-log) migrations have been run to create theBookingAudittablenpx prisma generatefrompackages/prisma/to regenerate Prisma client with BookingAudit typesTest Scenarios:
BookingAuditrecord is created with typeRECORD_CREATEDand actionACCEPTEDBookingAuditrecord is created with typeRECORD_UPDATEDand actionCANCELLEDBookingAuditrecord is created with typeRECORD_UPDATEDand actionACCEPTEDDatabase Query to Verify:
Known Limitations:
Review Checklist
Critical Items to Review:
Type Safety Concerns:
npx prisma generate