Skip to content

Comments

feat: Add booking audit log viewer with filtering and permissions#25152

Merged
hariombalhara merged 2 commits intobooking-audit-more-infrafrom
booking-audit-viewer
Dec 6, 2025
Merged

feat: Add booking audit log viewer with filtering and permissions#25152
hariombalhara merged 2 commits intobooking-audit-more-infrafrom
booking-audit-viewer

Conversation

@hariombalhara
Copy link
Member

@hariombalhara hariombalhara commented Nov 14, 2025

What does this PR do?

This PR implements a booking audit log viewer as part of the Booking Audit Stack. It adds:

  1. New tRPC endpoint (viewer.bookings.getAuditLogs) that fetches audit logs for a specific booking with permission checks
  2. New page at /booking/logs/[bookinguid] to display the audit history
  3. UI component with search, filtering by action type/actor, and expandable log details

Permission model: Only the booking owner, attendees, or team admins/owners can view audit logs for a booking.

Link to Devin run: https://app.devin.ai/sessions/1526633c2f714bcb88952e8cbcda9cfa
Requested by: hariom@cal.com (@hariombalhara)

Key Implementation Details

Backend (getAuditLogs.handler.ts)

  • Fetches booking and verifies user has permission (owner, attendee, or team admin/owner)
  • Retrieves all bookingAudit records for the booking UID
  • Enriches actor information by looking up user details when userUuid is present
  • Returns logs ordered by timestamp (descending)

Frontend (booking-logs-view.tsx)

  • Displays audit logs with icons, timestamps, and actor information
  • Supports filtering by action type and actor type
  • Search functionality across action names and actor names
  • Expandable details showing full log data as JSON
  • Loading and error states

Human Review Checklist

⚠️ Critical areas to review:

  1. Permission logic (getAuditLogs.handler.ts:44-81): Verify the permission checks cover all scenarios:

    • Is the booking owner check sufficient?
    • Should organization admins have access?
    • Are there any edge cases with team memberships?
  2. Performance (getAuditLogs.handler.ts:108-142): The handler uses Promise.all to enrich actor data in a loop. For bookings with many audit logs, this could be slow:

    • Should we add pagination?
    • Can we optimize the actor enrichment with a single query?
  3. Type safety: The enriched audit logs modify the structure from Prisma's return type. Verify TypeScript catches any type mismatches.

  4. Internationalization: Some UI strings are hardcoded (e.g., "Booking History", action display names). Verify all user-facing text uses the translation system.

  5. UI edge cases: The component hasn't been tested with:

    • Very large audit log datasets
    • Empty states (no logs)
    • Long JSON data in expandable sections
    • Mobile responsiveness

How should this be tested?

Prerequisites:

  • Database with bookingAudit records populated
  • Test users with different roles (booking owner, attendee, team admin, unrelated user)

Test scenarios:

  1. Navigate to /booking/logs/{valid-booking-uid} as the booking owner → should see audit logs
  2. Try accessing as an attendee → should see audit logs
  3. Try accessing as a team admin/owner → should see audit logs
  4. Try accessing as an unrelated user → should get 403 Forbidden error
  5. Try accessing with invalid booking UID → should get 404 Not Found error
  6. Test search functionality with various terms
  7. Test filtering by action type and actor type
  8. Expand/collapse log details to verify JSON rendering
  9. Test with booking that has 0 audit logs → should show "No audit logs found"

Environment variables:

  • Standard Cal.com development environment
  • No additional variables required

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

Checklist

  • I haven't read the contributing guide
  • My code doesn't follow the style guidelines of this project
  • I haven't commented my code, particularly in hard-to-understand areas
  • I haven't checked if my changes generate no new warnings

@vercel
Copy link

vercel bot commented Nov 14, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
cal-companion Error Error Nov 30, 2025 9:17am
2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
cal Ignored Ignored Nov 30, 2025 9:17am
cal-eu Ignored Ignored Nov 30, 2025 9:17am

@keithwillcode keithwillcode added core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO labels Nov 14, 2025
Copy link
Member Author

hariombalhara commented Nov 14, 2025

@hariombalhara hariombalhara changed the title feat: Add getAuditLogs API endpoint for booking audit display feat: [Booking Audit Stack - 4] Add getAuditLogs API endpoint for booking audit display Nov 14, 2025
@hariombalhara hariombalhara changed the title feat: [Booking Audit Stack - 4] Add getAuditLogs API endpoint for booking audit display feat: [Booking Audit Stack - 4] Add BookingAudit viewer Nov 14, 2025
@hariombalhara hariombalhara mentioned this pull request Nov 14, 2025
3 tasks
@hariombalhara hariombalhara force-pushed the booking-audit-more-infra branch from 2b6d061 to cc51d6f Compare November 14, 2025 12:28
@hariombalhara hariombalhara force-pushed the booking-audit-viewer branch 2 times, most recently from 50f570c to 1b3298e Compare November 14, 2025 12:39
@hariombalhara hariombalhara force-pushed the booking-audit-more-infra branch from cc51d6f to 1a35c20 Compare November 14, 2025 12:39
@hariombalhara hariombalhara force-pushed the booking-audit-more-infra branch from 1a35c20 to 137a356 Compare November 15, 2025 04:41
@hariombalhara hariombalhara force-pushed the booking-audit-more-infra branch from 137a356 to f81a44f Compare November 15, 2025 11:08
@hariombalhara hariombalhara force-pushed the booking-audit-viewer branch 2 times, most recently from d324464 to 2c09499 Compare November 15, 2025 11:13
@hariombalhara hariombalhara force-pushed the booking-audit-more-infra branch from f81a44f to 616bc4c Compare November 15, 2025 11:13
@hariombalhara hariombalhara force-pushed the booking-audit-more-infra branch from 616bc4c to 88398f4 Compare November 15, 2025 12:56
@hariombalhara hariombalhara changed the base branch from graphite-base/25152 to booking-audit-more-infra November 29, 2025 09:41
@hariombalhara hariombalhara force-pushed the booking-audit-more-infra branch from 2a72799 to c6a4033 Compare November 29, 2025 11:55
@pull-request-size pull-request-size bot added size/M and removed size/L labels Nov 29, 2025
@hariombalhara hariombalhara changed the base branch from booking-audit-more-infra to graphite-base/25152 November 29, 2025 12:13
@hariombalhara hariombalhara changed the base branch from graphite-base/25152 to booking-audit-consumer-producer November 29, 2025 12:13
@hariombalhara hariombalhara force-pushed the booking-audit-consumer-producer branch from a561adf to e81c326 Compare November 29, 2025 12:33
@hariombalhara hariombalhara force-pushed the booking-audit-consumer-producer branch from e81c326 to fde380a Compare November 30, 2025 09:08
Base automatically changed from booking-audit-consumer-producer to booking-audit-more-infra December 6, 2025 06:24
@hariombalhara hariombalhara merged commit 0ce15a5 into booking-audit-more-infra Dec 6, 2025
11 of 13 checks passed
@hariombalhara hariombalhara deleted the booking-audit-viewer branch December 6, 2025 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants