Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rescheduling in round robin #14109

Merged
merged 8 commits into from Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 13 additions & 7 deletions packages/core/EventManager.ts
Expand Up @@ -115,6 +115,7 @@ export default class EventManager {
*/
public async create(event: CalendarEvent): Promise<CreateUpdateResult> {
const evt = processLocation(event);

// Fallback to cal video if no location is set
if (!evt.location) {
// See if cal video is enabled & has keys
Expand Down Expand Up @@ -328,7 +329,7 @@ export default class EventManager {
rescheduleUid: string,
newBookingId?: number,
changedOrganizer?: boolean,
newDestinationCalendar?: DestinationCalendar[] | null
previousHostDestinationCalendar?: DestinationCalendar[] | null
): Promise<CreateUpdateResult> {
const originalEvt = processLocation(event);
const evt = cloneDeep(originalEvt);
Expand Down Expand Up @@ -380,16 +381,21 @@ export default class EventManager {
if (evt.requiresConfirmation) {
log.debug("RescheduleRequiresConfirmation: Deleting Event and Meeting for previous booking");
// As the reschedule requires confirmation, we can't update the events and meetings to new time yet. So, just delete them and let it be handled when organizer confirms the booking.
await this.deleteEventsAndMeetings({ booking, event });
await this.deleteEventsAndMeetings({
booking,
event: { ...event, destinationCalendar: previousHostDestinationCalendar },
});
} else {
if (changedOrganizer) {
log.debug("RescheduleOrganizerChanged: Deleting Event and Meeting for previous booking");
await this.deleteEventsAndMeetings({ booking, event });
await this.deleteEventsAndMeetings({
booking,
event: { ...event, destinationCalendar: previousHostDestinationCalendar },
});

log.debug("RescheduleOrganizerChanged: Creating Event and Meeting for for new booking");

const newEvent = { ...evt, destinationCalendar: newDestinationCalendar };
const createdEvent = await this.create(newEvent);
Udit-takkar marked this conversation as resolved.
Show resolved Hide resolved
const createdEvent = await this.create(originalEvt);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

create function updates the videoCallData in evt(Calendar event object) like
evt.videoCallData = { ... }

but in reschedule function we passed copy of event object to create function in this line which updated the copy of event but not the original event

results.push(...createdEvent.results);
bookingReferenceChangedOrganizer.push(...createdEvent.referencesToCreate);
} else {
Expand Down Expand Up @@ -453,14 +459,14 @@ export default class EventManager {
const videoReferences = booking.references.filter((reference) => reference.type.includes("_video"));
log.debug("deleteEventsAndMeetings", safeStringify({ calendarReferences, videoReferences }));
const calendarPromises = calendarReferences.map(async (bookingCalendarReference) => {
return await this.deleteCalendarEventForBookingReference({
return this.deleteCalendarEventForBookingReference({
bookingCalendarReference,
event,
});
});

const videoPromises = videoReferences.map(async (bookingVideoReference) => {
return await this.deleteVideoEventForBookingReference({
return this.deleteVideoEventForBookingReference({
bookingVideoReference,
});
});
Expand Down
19 changes: 12 additions & 7 deletions packages/features/bookings/lib/handleNewBooking.ts
Expand Up @@ -1747,26 +1747,30 @@ async function handler(

evt = addVideoCallDataToEvent(originalRescheduledBooking.references, evt);

const newDestinationCalendar = evt.destinationCalendar;

evt.destinationCalendar = originalRescheduledBooking?.destinationCalendar
// If organizer is changed in RR event then we need to delete the previous host destination calendar events
const previousHostDestinationCalendar = originalRescheduledBooking?.destinationCalendar
? [originalRescheduledBooking?.destinationCalendar]
: originalRescheduledBooking?.user?.destinationCalendar
? [originalRescheduledBooking?.user.destinationCalendar]
: evt.destinationCalendar;
: [];

if (changedOrganizer) {
evt.title = getEventName(eventNameObject);
// location might changed and will be new created in eventManager.create (organizer default location)
evt.videoCallData = undefined;
// To prevent "The requested identifier already exists" error while updating event, we need to remove iCalUID
evt.iCalUID = undefined;
} else {
// In case of rescheduling, we need to keep the previous host destination calendar
evt.destinationCalendar = originalRescheduledBooking?.destinationCalendar
? [originalRescheduledBooking?.destinationCalendar]
: evt.destinationCalendar;
}

const updateManager = await eventManager.reschedule(
evt,
originalRescheduledBooking.uid,
undefined,
changedOrganizer,
newDestinationCalendar
previousHostDestinationCalendar
);

// This gets overridden when updating the event - to check if notes have been hidden or not. We just reset this back
Expand Down Expand Up @@ -1864,6 +1868,7 @@ async function handler(
metadata.hangoutLink ||
results[0].createdEvent?.url ||
organizerOrFirstDynamicGroupMemberDefaultLocationUrl ||
getVideoCallUrlFromCalEvent(evt) ||
videoCallUrl;
}

Expand Down