Skip to content

Comments

feat: take into account guest availability when rescheduling#28174

Open
openclaw12-dev wants to merge 1 commit intocalcom:mainfrom
openclaw12-dev:feat/guest-availability-reschedule
Open

feat: take into account guest availability when rescheduling#28174
openclaw12-dev wants to merge 1 commit intocalcom:mainfrom
openclaw12-dev:feat/guest-availability-reschedule

Conversation

@openclaw12-dev
Copy link

@openclaw12-dev openclaw12-dev commented Feb 25, 2026

/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

  1. BookingRepository.ts — Added findBookingAttendeesByUid() to fetch attendee emails and organizer userId from a booking UID.

  2. UserRepository.ts — Added findUsersByEmailsForAvailability() using raw SQL UNION (matching findVerifiedUsersByEmailsRaw pattern) to check both primary and verified secondary emails. No LOWER() (avoids sequential scan), includes locked = FALSE on both legs.

  3. slots/util.ts — Added _getGuestAvailabilityForReschedule() method:

    • Host-vs-guest detection: Checks ctx.session.user.email — if no session (guest via email link) or logged-in user is an attendee → skips guest availability check
    • Fetches original booking attendees
    • Looks up if any are registered Cal.com users (via primary OR secondary email)
    • Filters out the host (avoids double-counting)
    • Fetches the guest's available date ranges
    • Intersects host + guest availability using existing intersect() from date-ranges
    • Non-fatal error handling: if guest lookup fails, falls back to host-only availability
  4. types.ts — Extended ContextForGetSchedule with optional session type for host detection.

  5. Tests (getGuestAvailabilityForReschedule.test.ts) — 331 lines covering:

    • Host-vs-guest distinction: no session → skip, no user email → skip, logged-in attendee → skip, host logged in → proceed
    • Booking not found / empty attendees
    • External (non-Cal.com) attendees
    • Attendee is the host (filtered out)
    • Successful guest availability fetch
    • Multiple attendees (uses first non-host Cal.com user)

How to test

  1. Create two Cal.com users (User A and User B)
  2. User A books User B
  3. User B (host) reschedules → available slots should respect User A's availability
  4. User A (guest) reschedules via email link → should see all of User B's available slots (no restriction)
  5. Book with an external email → reschedule works normally

@openclaw12-dev openclaw12-dev requested a review from a team as a code owner February 25, 2026 14:47
@graphite-app graphite-app bot added the community Created by Linear-GitHub Sync label Feb 25, 2026
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


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.

@github-actions github-actions bot added $200 bookings area: bookings, availability, timezones, double booking Medium priority Created by Linear-GitHub Sync ✨ feature New feature or request 💎 Bounty A bounty on Algora.io 🧹 Improvements Improvements to existing features. Mostly UX/UI labels Feb 25, 2026
@graphite-app
Copy link

graphite-app bot commented Feb 25, 2026

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.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-ai with guidance or docs links (including llms.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),
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Suggested change
guestEmails: guests.map((g) => g.email),
guestUserIds: guests.map((g) => g.id),
Fix with Cubic

…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
@openclaw12-dev openclaw12-dev force-pushed the feat/guest-availability-reschedule branch from d78f6e1 to 65de8ad Compare February 25, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bookings area: bookings, availability, timezones, double booking 🙋 Bounty claim 💎 Bounty A bounty on Algora.io community Created by Linear-GitHub Sync ✨ feature New feature or request 🧹 Improvements Improvements to existing features. Mostly UX/UI Medium priority Created by Linear-GitHub Sync size/XL $200

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CAL-4531] Take into account guest's availability when rescheduling

2 participants