Skip to content

Commit b42eb3d

Browse files
authored
feat(room-booking): add support for accepting recurring event instances (#585)
1 parent 4854a5d commit b42eb3d

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

drivers/place/room_booking_approval.cr

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,47 @@ class Place::RoomBookingApproval < PlaceOS::Driver
6565
calendar.accept_event(calendar_id: calendar_id, event_id: event_id, user_id: user_id, notify: notify, comment: comment)
6666
end
6767

68+
@[Security(Level::Support)]
69+
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)
70+
logger.debug { "accepting recurring event #{recurring_event_id} on #{calendar_id}" }
71+
72+
# Get the original event to find its ical_uid
73+
original_event = calendar.get_event(calendar_id, recurring_event_id, user_id)
74+
unless original_event.ical_uid
75+
logger.error { "Event #{recurring_event_id} has no ical_uid, cannot find recurring instances" }
76+
return
77+
end
78+
79+
# Use provided dates or default to now and 1 year ahead
80+
now = Time.utc
81+
start_time = period_start || now.to_unix
82+
end_time = period_end || (now + 1.year).to_unix
83+
84+
# Find all instances of this recurring event
85+
recurring_instances = calendar.list_events(
86+
calendar_id: calendar_id,
87+
period_start: start_time,
88+
period_end: end_time,
89+
user_id: user_id,
90+
include_cancelled: false,
91+
ical_uid: original_event.ical_uid
92+
)
93+
94+
# Accept each instance
95+
accepted_count = 0
96+
recurring_instances.each do |event|
97+
begin
98+
calendar.accept_event(calendar_id, event.id, user_id: user_id, notify: notify, comment: comment)
99+
accepted_count += 1
100+
logger.debug { "Accepted recurring event instance #{event.id}" }
101+
rescue error
102+
logger.warn(exception: error) { "Failed to accept recurring event instance #{event.id}" }
103+
end
104+
end
105+
106+
logger.info { "Accepted #{accepted_count} instances of recurring event #{recurring_event_id}" }
107+
end
108+
68109
@[Security(Level::Support)]
69110
def decline_event(calendar_id : String, event_id : String, user_id : String? = nil, notify : Bool = false, comment : String? = nil)
70111
calendar.decline_event(calendar_id: calendar_id, event_id: event_id, user_id: user_id, notify: notify, comment: comment)

0 commit comments

Comments
 (0)