calcom/cal.com

[CAL-4398] Feature: Update existing BookingReferences to new Credential on Credential `reconnect`

Opened this issue · 2 comments

Is your proposal related to a problem?

When connecting a new Credential, we should check the BookingReference and detect whether the new Credential reconnects the access of the Booking to an integration. If so we can update the credentialId with the created Credential.

CAL-4398

Hi @emrysal , I am trying to work on this issue.
Can you please give more clarification with regards to - "in which scenario exactly do we need to update CredentialId in BookingReference, when new Credential is added?"

Consider this scenario -

  1. A Google Calendar is added and connected. New Credential Row is created in Credential table. On Creating a new booking, a new row is added in BookingReference Table with CredentialId connected.
  2. Now if i try to add one more Google Calendar (with different google account) , A second Credential Row is created in Credential table for google_calendar type.
  3. The BookingReference created in Step1 would still should use the first Calendar or 1st CredentialId only right. Is updating BookingReference required in this scenario.

May be should we check in case of Calendar Apps, that new credential is added for same calendar, and update old BookingReferences with this new CredentialId?

Please correct me with my understanding.

Hi @emrysal,
Have raised PR for this feature, please have look and share your thoughts.
Approach:

  1. Leveraging Repository pattern for credential creation and selectedCalendar creation. In the entire codebase whereever directly prisma was used for credential and selectedCalendar creation, its replaced with newly added Repository functions.
  2. When a new Credential is created, its reconnected with previously orphaned BookingReferences, i.e BookingReferences that have credentialId has null , due to a Credential deletion (caused by disconnecting an App).
  3. The approach used to identify right BookingReferences to be connected is - the combination of type , userId and selectedCalendars (for CalendarApps) of the new Credential being created is matched with type (EventManager populates this column in BookingReference from integration type which is the same used for Credential creation) , booking -> userId, externalCalendarId correspondingly.
  4. google-meet being a special case, EventManager connects the google-calendar credential to google-meet, in same way this is also handled.