From ce26ba37687d160dbb3fc0a453be6ba10a980491 Mon Sep 17 00:00:00 2001 From: Mia Bennett Date: Mon, 6 Oct 2025 11:55:43 +0930 Subject: [PATCH] feat(room-booking): add support for accepting recurring event instances --- drivers/place/room_booking_approval.cr | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/place/room_booking_approval.cr b/drivers/place/room_booking_approval.cr index d7c7c8d610b..2d5f1d8d04a 100644 --- a/drivers/place/room_booking_approval.cr +++ b/drivers/place/room_booking_approval.cr @@ -65,6 +65,47 @@ class Place::RoomBookingApproval < PlaceOS::Driver calendar.accept_event(calendar_id: calendar_id, event_id: event_id, user_id: user_id, notify: notify, comment: comment) end + @[Security(Level::Support)] + def accept_recurring_event(calendar_id : String, recurring_event_id : String, user_id : String? = nil, period_start : Int64? = nil, period_end : Int64? = nil, notify : Bool = false, comment : String? = nil) + logger.debug { "accepting recurring event #{recurring_event_id} on #{calendar_id}" } + + # Get the original event to find its ical_uid + original_event = calendar.get_event(calendar_id, recurring_event_id, user_id) + unless original_event.ical_uid + logger.error { "Event #{recurring_event_id} has no ical_uid, cannot find recurring instances" } + return + end + + # Use provided dates or default to now and 1 year ahead + now = Time.utc + start_time = period_start || now.to_unix + end_time = period_end || (now + 1.year).to_unix + + # Find all instances of this recurring event + recurring_instances = calendar.list_events( + calendar_id: calendar_id, + period_start: start_time, + period_end: end_time, + user_id: user_id, + include_cancelled: false, + ical_uid: original_event.ical_uid + ) + + # Accept each instance + accepted_count = 0 + recurring_instances.each do |event| + begin + calendar.accept_event(calendar_id, event.id, user_id: user_id, notify: notify, comment: comment) + accepted_count += 1 + logger.debug { "Accepted recurring event instance #{event.id}" } + rescue error + logger.warn(exception: error) { "Failed to accept recurring event instance #{event.id}" } + end + end + + logger.info { "Accepted #{accepted_count} instances of recurring event #{recurring_event_id}" } + end + @[Security(Level::Support)] def decline_event(calendar_id : String, event_id : String, user_id : String? = nil, notify : Bool = false, comment : String? = nil) calendar.decline_event(calendar_id: calendar_id, event_id: event_id, user_id: user_id, notify: notify, comment: comment)