chore: Improves the core booking audit architecture by adding new capabilities and simplifying the existing interfaces. (#25872)

* feat(booking-audit): extract core audit system changes from PR 25125

This PR extracts core audit infrastructure changes without integration changes:

1. New action services introduced:
   - SeatBookedAuditActionService
   - SeatRescheduledAuditActionService

2. Simplification of ActionService interface:
   - Streamlined IAuditActionService interface
   - Reduced TypeScript burden with cleaner type definitions

3. ActionSource support:
   - Added BookingAuditSource enum (API_V1, API_V2, WEBAPP, WEBHOOK, UNKNOWN)
   - Added source and operationId fields to BookingAudit model

4. New AuditAction types:
   - SEAT_BOOKED
   - SEAT_RESCHEDULED
   - APP actor type

5. New BookingAuditAccessService:
   - Permission-based access control for audit logs
   - Added readTeamAuditLogs and readOrgAuditLogs permissions

6. Fixes in the logs viewer flow:
   - Enhanced BookingAuditViewerService with improved filtering
   - Local AttendeeRepository for actor enrichment

Changes are contained within packages/features/booking-audit with minimal
outside changes (permission registry only).

Co-Authored-By: [email protected] <[email protected]>

* refactor(booking-audit): streamline action handling and enhance localization

- Replaced action icon retrieval with a mapping object for improved clarity and performance.
- Introduced constants for actor role labels to simplify role retrieval.
- Added new localization strings for audit log permission errors and organization requirements.
- Updated various service and repository interfaces to enhance type safety and clarity.
- Removed deprecated architecture documentation and adjusted related imports for consistency.

These changes aim to improve code maintainability and user experience in the booking audit system.

* fix(booking-audit): enhance actor role localization and operation ID tracking

- Updated actor role labels in the booking logs view to use lowercase for consistency.
- Improved localization by wrapping actor role display in a translation function.
- Added operationId field to audit logs for better correlation of actions across multiple bookings.
- Enhanced BookingAuditViewerService to include operationId in enriched audit logs.
- Updated integration tests to verify consistent operationId across related audit logs.

These changes aim to improve localization accuracy and facilitate better tracking of user actions in the booking audit system.

* feat: integrate credential repository and enhance app actor handling

- Added CredentialRepository to manage app credentials, including a method to find credentials by ID.
- Updated BookingAudit system to support app actors identified by credential ID, improving actor attribution and audit clarity.
- Introduced a new utility function to map app slugs to display names, enhancing the user experience in audit logs.
- Modified relevant interfaces and types to accommodate the new credential handling and app actor structure.
- Enhanced BookingAuditViewerService to display app names based on credentials, ensuring accurate representation in audit logs.

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Hariom BalharaandDevin AI authored and GitHub committed 2025-12-18 12:46:24 +00:00
1 parent 9019be58ed
commit f1011ddd08
57 files changed
+3808 -1701

No files matched your search

@@ -0,0 +1,30 @@
/*
Warnings:
- Added the required column `operationId` to the `BookingAudit` table without a default value. This is not possible if the table is not empty.
- Added the required column `source` to the `BookingAudit` table without a default value. This is not possible if the table is not empty.
*/
-- CreateEnum
CREATE TYPE "public"."BookingAuditSource" AS ENUM ('api_v1', 'api_v2', 'webapp', 'webhook', 'unknown');
-- AlterEnum
ALTER TYPE "public"."AuditActorType" ADD VALUE 'app';
-- AlterEnum
-- This migration adds more than one value to an enum.
-- With PostgreSQL versions 11 and earlier, this is not possible
-- in a single migration. This can be worked around by creating
-- multiple migrations, each migration adding only one value to
-- the enum.
ALTER TYPE "public"."BookingAuditAction" ADD VALUE 'seat_booked';
ALTER TYPE "public"."BookingAuditAction" ADD VALUE 'seat_rescheduled';
-- AlterTable
ALTER TABLE "public"."BookingAudit" ADD COLUMN "operationId" TEXT NOT NULL,
ADD COLUMN "source" "public"."BookingAuditSource" NOT NULL;
-- CreateIndex
CREATE INDEX "BookingAudit_operationId_idx" ON "public"."BookingAudit"("operationId");
@@ -0,0 +1,14 @@
/*
Warnings:
- A unique constraint covering the columns `[credentialId]` on the table `AuditActor` will be added. If there are existing duplicate values, this will fail.
*/
-- AlterTable
ALTER TABLE "public"."AuditActor" ADD COLUMN "credentialId" INTEGER;
-- CreateIndex
CREATE INDEX "AuditActor_credentialId_idx" ON "public"."AuditActor"("credentialId");
-- CreateIndex
CREATE UNIQUE INDEX "AuditActor_credentialId_key" ON "public"."AuditActor"("credentialId");
+44 -17
View File
@@ -1944,18 +1944,18 @@ model Avatar {
}
model OutOfOfficeEntry {
id Int @id @default(autoincrement())
uuid String @unique
start DateTime
end DateTime
notes String?
showNotePublicly Boolean @default(false)
userId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
toUserId Int?
toUser User? @relation(name: "toUser", fields: [toUserId], references: [id], onDelete: Cascade)
reasonId Int?
reason OutOfOfficeReason? @relation(fields: [reasonId], references: [id], onDelete: SetNull)
id Int @id @default(autoincrement())
uuid String @unique
start DateTime
end DateTime
notes String?
showNotePublicly Boolean @default(false)
userId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
toUserId Int?
toUser User? @relation(name: "toUser", fields: [toUserId], references: [id], onDelete: Cascade)
reasonId Int?
reason OutOfOfficeReason? @relation(fields: [reasonId], references: [id], onDelete: SetNull)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -2719,6 +2719,18 @@ enum BookingAuditAction {
// Rescheduling
RESCHEDULE_REQUESTED @map("reschedule_requested")
// Seat management
SEAT_BOOKED @map("seat_booked")
SEAT_RESCHEDULED @map("seat_rescheduled")
}
enum BookingAuditSource {
API_V1 @map("api_v1")
API_V2 @map("api_v2")
WEBAPP @map("webapp")
WEBHOOK @map("webhook")
UNKNOWN @map("unknown")
}
enum AuditActorType {
@@ -2726,6 +2738,7 @@ enum AuditActorType {
GUEST @map("guest") // Non-registered user
ATTENDEE @map("attendee") // Has Attendee record with us
SYSTEM @map("system") // Automated actions
APP @map("app") // App-triggered actions (payment webhooks, integrations)
}
model AuditActor {
@@ -2734,13 +2747,19 @@ model AuditActor {
// References for different actor types (soft references, no FK constraints)
// These fields intentionally do NOT have foreign key constraints to preserve audit trail integrity:
// - When a User or Attendee is deleted, their AuditActor record persists with these IDs intact
// - When a User, Attendee, or Credential is deleted, their AuditActor record persists with these IDs intact
// - This maintains immutable audit history even after source records are removed
userUuid String? @db.Uuid // For USER type - references User.uuid without FK constraint
attendeeId Int? // For ATTENDEE type - references Attendee.id without FK constraint
// - For APP actors: when credential is deleted, name/email fields are populated to preserve app identity
userUuid String? @db.Uuid // For USER type - references User.uuid without FK constraint
attendeeId Int? // For ATTENDEE type - references Attendee.id without FK constraint
credentialId Int? // For APP type - references Credential.id without FK constraint
// Identity fields - only for GUEST/SYSTEM(System too might not have all) type. Attendee and User maintain their own identity fields.
// They could be set as anonymized for User/Attendee record as well when they are deleted to preserve the audit trail.
// Identity fields - for GUEST/SYSTEM/APP types when source record is deleted
// - GUEST: email/name stored directly
// - SYSTEM: email/name for system identifier
// - APP: email/name used when using appSlug mode (fallback), or preserved when credential deleted
// - USER/ATTENDEE: derive from their tables using userUuid/attendeeId
// These fields can be anonymized when User/Attendee records are deleted to preserve audit trail
email String?
phone String?
name String?
@@ -2751,11 +2770,13 @@ model AuditActor {
// TODO: Add pseudonymizedAt and related fields when we anonymize the data on deletion
@@unique([userUuid])
@@unique([attendeeId])
@@unique([credentialId]) // One actor per credential
@@unique([email]) // Prevent duplicate email actors
@@unique([phone]) // Prevent duplicate phone actors
@@index([email])
@@index([userUuid])
@@index([attendeeId])
@@index([credentialId])
}
model BookingAudit {
@@ -2785,11 +2806,17 @@ model BookingAudit {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
source BookingAuditSource
// Operation ID for correlating related audit logs across different audit types (BookingAudit, UserAudit, etc.) or for bulk operations
operationId String
data Json?
@@index([actorId])
@@index([bookingUid])
@@index([timestamp])
@@index([operationId])
}
enum PhoneNumberSubscriptionStatus {