fix: Use only the first connected calendar as fallback to create event (#11668)

pull/11474/head^2
Hariom Balhara 2023-10-03 23:15:18 +05:30 committed by GitHub
parent bb052a24bc
commit a186b130cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 8 deletions

View File

@ -231,7 +231,7 @@ export const createEvent = async (
log.debug(
"Creating calendar event",
JSON.stringify({
safeStringify({
calEvent: getPiiFreeCalendarEvent(calEvent),
})
);
@ -267,11 +267,20 @@ export const createEvent = async (
})
: undefined;
if (!creationResult) {
logger.silly("createEvent failed", { success, uid, creationResult, originalEvent: calEvent, calError });
logger.error(
"createEvent failed",
safeStringify({
success,
uid,
creationResult,
originalEvent: getPiiFreeCalendarEvent(calEvent),
calError,
})
);
}
log.debug(
"Created calendar event",
JSON.stringify({
safeStringify({
calEvent: getPiiFreeCalendarEvent(calEvent),
creationResult,
})

View File

@ -10,7 +10,7 @@ import { appKeysSchema as calVideoKeysSchema } from "@calcom/app-store/dailyvide
import { getEventLocationTypeFromApp, MeetLocationType } from "@calcom/app-store/locations";
import getApps from "@calcom/app-store/utils";
import logger from "@calcom/lib/logger";
import { getPiiFreeUser } from "@calcom/lib/piiFreeData";
import { getPiiFreeDestinationCalendar, getPiiFreeUser, getPiiFreeCredential } from "@calcom/lib/piiFreeData";
import { safeStringify } from "@calcom/lib/safeStringify";
import prisma from "@calcom/prisma";
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
@ -399,13 +399,21 @@ export default class EventManager {
const destinationCalendarCredentials = this.calendarCredentials.filter(
(c) => c.type === destination.integration
);
createdEvents = createdEvents.concat(
await Promise.all(destinationCalendarCredentials.map(async (c) => await createEvent(c, event)))
// It might not be the first connected calendar as it seems that the order is not guaranteed to be ascending of credentialId.
const firstCalendarCredential = destinationCalendarCredentials[0];
log.warn(
"No credentialId found for destination calendar, falling back to first found calendar",
safeStringify({
destination: getPiiFreeDestinationCalendar(destination),
firstConnectedCalendar: getPiiFreeCredential(firstCalendarCredential),
})
);
createdEvents.push(await createEvent(firstCalendarCredential, event));
}
}
} else {
log.silly(
log.warn(
"No destination Calendar found, falling back to first connected calendar",
safeStringify({
calendarCredentials: this.calendarCredentials,

View File

@ -78,11 +78,11 @@ export function getPiiFreeDestinationCalendar(destinationCalendar: Partial<Desti
return {
integration: destinationCalendar.integration,
userId: destinationCalendar.userId,
credentialId: destinationCalendar.credentialId,
/**
* Let's just get a boolean value for PII sensitive fields so that we atleast know if it's present or not
*/
externalId: !!destinationCalendar.externalId,
credentialId: !!destinationCalendar.credentialId,
};
}