feat: take into account guest availability when rescheduling#28174
feat: take into account guest availability when rescheduling#28174openclaw12-dev wants to merge 1 commit intocalcom:mainfrom
Conversation
|
ec2-user seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Graphite Automations"Send notification to Community team when bounty PR opened" took an action on this PR • (02/25/26)2 teammates were notified to this PR based on Keith Williams's automation. |
There was a problem hiding this comment.
2 issues found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/trpc/server/routers/viewer/slots/util.ts">
<violation number="1" location="packages/trpc/server/routers/viewer/slots/util.ts:1044">
P1: Custom agent: **Avoid Logging Sensitive Information**
Guest email addresses (PII) are logged directly via `guestEmails: guests.map((g) => g.email)`. Avoid logging sensitive information such as emails. Use user IDs or obfuscated identifiers instead.</violation>
</file>
<file name="packages/features/users/repositories/UserRepository.ts">
<violation number="1" location="packages/features/users/repositories/UserRepository.ts:1469">
P2: findUsersByEmailsForAvailability ignores verified SecondaryEmail records, so guests who booked with a secondary email won’t be matched and their availability won’t be intersected during reschedule.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Add one-off context when rerunning by tagging
@cubic-dev-aiwith guidance or docs links (includingllms.txt) - Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| } | ||
|
|
||
| loggerWithEventDetails.debug("Found Cal.com guest user(s) for reschedule", { | ||
| guestEmails: guests.map((g) => g.email), |
There was a problem hiding this comment.
P1: Custom agent: Avoid Logging Sensitive Information
Guest email addresses (PII) are logged directly via guestEmails: guests.map((g) => g.email). Avoid logging sensitive information such as emails. Use user IDs or obfuscated identifiers instead.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/trpc/server/routers/viewer/slots/util.ts, line 1044:
<comment>Guest email addresses (PII) are logged directly via `guestEmails: guests.map((g) => g.email)`. Avoid logging sensitive information such as emails. Use user IDs or obfuscated identifiers instead.</comment>
<file context>
@@ -990,6 +990,102 @@ export class AvailableSlotsService {
+ }
+
+ loggerWithEventDetails.debug("Found Cal.com guest user(s) for reschedule", {
+ guestEmails: guests.map((g) => g.email),
+ });
+
</file context>
| guestEmails: guests.map((g) => g.email), | |
| guestUserIds: guests.map((g) => g.id), |
…m#16378) When a Cal.com host reschedules a booking, the system now checks whether the guest (booker) is also a Cal.com user. If they are, their availability is fetched and intersected with the host's, ensuring only mutually available time slots are shown. ## What changed ### 1. Guest availability lookup during reschedule - New `_getGuestAvailabilityForReschedule` method on `AvailableSlotsService` - Fetches original booking attendees via `BookingRepository.findBookingAttendeesByUid` - Looks up attendees as Cal.com users via `UserRepository.findUsersByEmailsForAvailability` - Fetches guest's availability and returns their date ranges for intersection ### 2. Host-vs-guest reschedule distinction - Only checks guest availability for HOST-initiated reschedules - Skips check when guest reschedules via email link (no session) - Skips check when logged-in user is a booking attendee (guest rescheduling own booking) - Uses session context to distinguish host from guest ### 3. Availability intersection - Uses existing `intersect()` from date-ranges lib to combine host + guest availability - Falls back to host-only availability on error (non-fatal) ### 4. Email lookup with secondary emails - Uses raw SQL UNION query to check both primary and secondary (verified) emails - Follows same performance pattern as `findVerifiedUsersByEmailsRaw` - No LOWER() on columns (emails stored lowercase), avoids sequential scans ## Files changed - `packages/trpc/server/routers/viewer/slots/util.ts` — Core logic - `packages/trpc/server/routers/viewer/slots/types.ts` — Session type extension - `packages/features/bookings/repositories/BookingRepository.ts` — New query method - `packages/features/users/repositories/UserRepository.ts` — New email lookup - `packages/trpc/server/routers/viewer/slots/getGuestAvailabilityForReschedule.test.ts` — Tests ## Tests (11 cases) - Guest self-reschedule via email link (no session) → skipped - Guest self-reschedule while logged in → skipped - Host reschedule with Cal.com guest → availability fetched & returned - Booking not found / empty attendees → null - External guest (not a Cal.com user) → null - Attendee is the host → filtered out - Multiple attendees → first non-host guest used - Empty availability results → null Fixes cal-com/cal.com#16378
d78f6e1 to
65de8ad
Compare
/claim #16378
Fixes #16378
What does this PR do?
When a host reschedules a booking, this PR checks whether any of the attendees (guests/bookers) are registered Cal.com users. If they are, their availability is fetched and intersected with the host's availability so the reschedule picker only shows time slots that work for both parties.
Important: Guest availability is only checked for host-initiated reschedules. When a guest reschedules themselves (via email link or while logged in as an attendee), they can freely pick any slot on the host's calendar — per this comment.
Changes
BookingRepository.ts— AddedfindBookingAttendeesByUid()to fetch attendee emails and organizer userId from a booking UID.UserRepository.ts— AddedfindUsersByEmailsForAvailability()using raw SQL UNION (matchingfindVerifiedUsersByEmailsRawpattern) to check both primary and verified secondary emails. NoLOWER()(avoids sequential scan), includeslocked = FALSEon both legs.slots/util.ts— Added_getGuestAvailabilityForReschedule()method:ctx.session.user.email— if no session (guest via email link) or logged-in user is an attendee → skips guest availability checkintersect()fromdate-rangestypes.ts— ExtendedContextForGetSchedulewith optional session type for host detection.Tests (
getGuestAvailabilityForReschedule.test.ts) — 331 lines covering:How to test