fix: Create separate calendar events to hide organizer (#21555)
* Add notes to `EventManager.create` * Create `CalendarServiceEvent` * Generate calendar description and remove attendees if event is private in `CalendarManager` * Process event for reschedule method * Refactor calendar services * Clean up comment * Type fixes * Type fix * Type fix
This commit is contained in:
1 parent
e5868837d5
commit
6f1eaaa02e
10 files changed
+121
-94
No files matched your search
@@ -1,9 +1,10 @@
|
|||||||
import { getLocation, getRichDescription } from "@calcom/lib/CalEventParser";
|
import { getLocation } from "@calcom/lib/CalEventParser";
|
||||||
import logger from "@calcom/lib/logger";
|
import logger from "@calcom/lib/logger";
|
||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
import type { BufferedBusyTime } from "@calcom/types/BufferedBusyTime";
|
import type { BufferedBusyTime } from "@calcom/types/BufferedBusyTime";
|
||||||
import type {
|
import type {
|
||||||
Calendar,
|
Calendar,
|
||||||
|
CalendarServiceEvent,
|
||||||
CalendarEvent,
|
CalendarEvent,
|
||||||
EventBusyDate,
|
EventBusyDate,
|
||||||
IntegrationCalendar,
|
IntegrationCalendar,
|
||||||
@@ -130,7 +131,7 @@ export default class FeishuCalendarService implements Calendar {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
async createEvent(event: CalendarEvent, credentialId: number): Promise<NewCalendarEventType> {
|
async createEvent(event: CalendarServiceEvent, credentialId: number): Promise<NewCalendarEventType> {
|
||||||
let eventId = "";
|
let eventId = "";
|
||||||
let eventRespData;
|
let eventRespData;
|
||||||
const mainHostDestinationCalendar = event.destinationCalendar
|
const mainHostDestinationCalendar = event.destinationCalendar
|
||||||
@@ -200,7 +201,7 @@ export default class FeishuCalendarService implements Calendar {
|
|||||||
* @param event
|
* @param event
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async updateEvent(uid: string, event: CalendarEvent, externalCalendarId?: string) {
|
async updateEvent(uid: string, event: CalendarServiceEvent, externalCalendarId?: string) {
|
||||||
const eventId = uid;
|
const eventId = uid;
|
||||||
let eventRespData;
|
let eventRespData;
|
||||||
const mainHostDestinationCalendar = event.destinationCalendar?.find(
|
const mainHostDestinationCalendar = event.destinationCalendar?.find(
|
||||||
@@ -372,10 +373,10 @@ export default class FeishuCalendarService implements Calendar {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private translateEvent = (event: CalendarEvent): FeishuEvent => {
|
private translateEvent = (event: CalendarServiceEvent): FeishuEvent => {
|
||||||
const feishuEvent: FeishuEvent = {
|
const feishuEvent: FeishuEvent = {
|
||||||
summary: event.title,
|
summary: event.title,
|
||||||
description: getRichDescription(event),
|
description: event.calendarDescription,
|
||||||
start_time: {
|
start_time: {
|
||||||
timestamp: parseEventTime2Timestamp(event.startTime),
|
timestamp: parseEventTime2Timestamp(event.startTime),
|
||||||
timezone: event.organizer.timeZone,
|
timezone: event.organizer.timeZone,
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ import type { FreeBusyArgs } from "@calcom/features/calendar-cache/calendar-cach
|
|||||||
import { getTimeMax, getTimeMin } from "@calcom/features/calendar-cache/lib/datesForCache";
|
import { getTimeMax, getTimeMin } from "@calcom/features/calendar-cache/lib/datesForCache";
|
||||||
import { getLocation, getRichDescription } from "@calcom/lib/CalEventParser";
|
import { getLocation, getRichDescription } from "@calcom/lib/CalEventParser";
|
||||||
import { uniqueBy } from "@calcom/lib/array";
|
import { uniqueBy } from "@calcom/lib/array";
|
||||||
import { formatCalEvent } from "@calcom/lib/formatCalendarEvent";
|
|
||||||
import logger from "@calcom/lib/logger";
|
import logger from "@calcom/lib/logger";
|
||||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||||
import { SelectedCalendarRepository } from "@calcom/lib/server/repository/selectedCalendar";
|
import { SelectedCalendarRepository } from "@calcom/lib/server/repository/selectedCalendar";
|
||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
import type {
|
import type {
|
||||||
Calendar,
|
Calendar,
|
||||||
|
CalendarServiceEvent,
|
||||||
CalendarEvent,
|
CalendarEvent,
|
||||||
EventBusyDate,
|
EventBusyDate,
|
||||||
IntegrationCalendar,
|
IntegrationCalendar,
|
||||||
@@ -168,75 +168,70 @@ export default class GoogleCalendarService implements Calendar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createEvent(
|
async createEvent(
|
||||||
calEventRaw: CalendarEvent,
|
calEvent: CalendarServiceEvent,
|
||||||
credentialId: number,
|
credentialId: number,
|
||||||
externalCalendarId?: string
|
externalCalendarId?: string
|
||||||
): Promise<NewCalendarEventType> {
|
): Promise<NewCalendarEventType> {
|
||||||
this.log.debug("Creating event");
|
this.log.debug("Creating event");
|
||||||
const formattedCalEvent = formatCalEvent(calEventRaw);
|
|
||||||
|
|
||||||
const payload: calendar_v3.Schema$Event = {
|
const payload: calendar_v3.Schema$Event = {
|
||||||
summary: formattedCalEvent.title,
|
summary: calEvent.title,
|
||||||
description: getRichDescription(formattedCalEvent),
|
description: calEvent.calendarDescription,
|
||||||
start: {
|
start: {
|
||||||
dateTime: formattedCalEvent.startTime,
|
dateTime: calEvent.startTime,
|
||||||
timeZone: formattedCalEvent.organizer.timeZone,
|
timeZone: calEvent.organizer.timeZone,
|
||||||
},
|
},
|
||||||
end: {
|
end: {
|
||||||
dateTime: formattedCalEvent.endTime,
|
dateTime: calEvent.endTime,
|
||||||
timeZone: formattedCalEvent.organizer.timeZone,
|
timeZone: calEvent.organizer.timeZone,
|
||||||
},
|
},
|
||||||
attendees: this.getAttendees({ event: formattedCalEvent, hostExternalCalendarId: externalCalendarId }),
|
attendees: this.getAttendees({ event: calEvent, hostExternalCalendarId: externalCalendarId }),
|
||||||
reminders: {
|
reminders: {
|
||||||
useDefault: true,
|
useDefault: true,
|
||||||
},
|
},
|
||||||
guestsCanSeeOtherGuests: !!formattedCalEvent.seatsPerTimeSlot
|
guestsCanSeeOtherGuests: !!calEvent.seatsPerTimeSlot ? calEvent.seatsShowAttendees : true,
|
||||||
? formattedCalEvent.seatsShowAttendees
|
iCalUID: calEvent.iCalUID,
|
||||||
: true,
|
|
||||||
iCalUID: formattedCalEvent.iCalUID,
|
|
||||||
};
|
};
|
||||||
if (calEventRaw.hideCalendarEventDetails) {
|
if (calEvent.hideCalendarEventDetails) {
|
||||||
payload.visibility = "private";
|
payload.visibility = "private";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (formattedCalEvent.location) {
|
if (calEvent.location) {
|
||||||
payload["location"] = getLocation(formattedCalEvent);
|
payload["location"] = getLocation(calEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (formattedCalEvent.recurringEvent) {
|
if (calEvent.recurringEvent) {
|
||||||
const rule = new RRule({
|
const rule = new RRule({
|
||||||
freq: formattedCalEvent.recurringEvent.freq,
|
freq: calEvent.recurringEvent.freq,
|
||||||
interval: formattedCalEvent.recurringEvent.interval,
|
interval: calEvent.recurringEvent.interval,
|
||||||
count: formattedCalEvent.recurringEvent.count,
|
count: calEvent.recurringEvent.count,
|
||||||
});
|
});
|
||||||
|
|
||||||
payload["recurrence"] = [rule.toString()];
|
payload["recurrence"] = [rule.toString()];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (formattedCalEvent.conferenceData && formattedCalEvent.location === MeetLocationType) {
|
if (calEvent.conferenceData && calEvent.location === MeetLocationType) {
|
||||||
payload["conferenceData"] = formattedCalEvent.conferenceData;
|
payload["conferenceData"] = calEvent.conferenceData;
|
||||||
}
|
}
|
||||||
const calendar = await this.authedCalendar();
|
const calendar = await this.authedCalendar();
|
||||||
// Find in formattedCalEvent.destinationCalendar the one with the same credentialId
|
// Find in formattedCalEvent.destinationCalendar the one with the same credentialId
|
||||||
|
|
||||||
const selectedCalendar =
|
const selectedCalendar =
|
||||||
externalCalendarId ??
|
externalCalendarId ??
|
||||||
(formattedCalEvent.destinationCalendar?.find((cal) => cal.credentialId === credentialId)?.externalId ||
|
(calEvent.destinationCalendar?.find((cal) => cal.credentialId === credentialId)?.externalId ||
|
||||||
"primary");
|
"primary");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let event: calendar_v3.Schema$Event | undefined;
|
let event: calendar_v3.Schema$Event | undefined;
|
||||||
let recurringEventId = null;
|
let recurringEventId = null;
|
||||||
if (formattedCalEvent.existingRecurringEvent) {
|
if (calEvent.existingRecurringEvent) {
|
||||||
recurringEventId = formattedCalEvent.existingRecurringEvent.recurringEventId;
|
recurringEventId = calEvent.existingRecurringEvent.recurringEventId;
|
||||||
const recurringEventInstances = await calendar.events.instances({
|
const recurringEventInstances = await calendar.events.instances({
|
||||||
calendarId: selectedCalendar,
|
calendarId: selectedCalendar,
|
||||||
eventId: formattedCalEvent.existingRecurringEvent.recurringEventId,
|
eventId: calEvent.existingRecurringEvent.recurringEventId,
|
||||||
});
|
});
|
||||||
if (recurringEventInstances.data.items) {
|
if (recurringEventInstances.data.items) {
|
||||||
const calComEventStartTime = dayjs(formattedCalEvent.startTime)
|
const calComEventStartTime = dayjs(calEvent.startTime).tz(calEvent.organizer.timeZone).format();
|
||||||
.tz(formattedCalEvent.organizer.timeZone)
|
|
||||||
.format();
|
|
||||||
for (let i = 0; i < recurringEventInstances.data.items.length; i++) {
|
for (let i = 0; i < recurringEventInstances.data.items.length; i++) {
|
||||||
const instance = recurringEventInstances.data.items[i];
|
const instance = recurringEventInstances.data.items[i];
|
||||||
const instanceStartTime = dayjs(instance.start?.dateTime)
|
const instanceStartTime = dayjs(instance.start?.dateTime)
|
||||||
@@ -260,10 +255,8 @@ export default class GoogleCalendarService implements Calendar {
|
|||||||
calendarId: selectedCalendar,
|
calendarId: selectedCalendar,
|
||||||
eventId: event.id || "",
|
eventId: event.id || "",
|
||||||
requestBody: {
|
requestBody: {
|
||||||
location: getLocation(formattedCalEvent),
|
location: getLocation(calEvent),
|
||||||
description: getRichDescription({
|
description: calEvent.calendarDescription,
|
||||||
...formattedCalEvent,
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -290,7 +283,7 @@ export default class GoogleCalendarService implements Calendar {
|
|||||||
eventId: event.id || "",
|
eventId: event.id || "",
|
||||||
requestBody: {
|
requestBody: {
|
||||||
description: getRichDescription({
|
description: getRichDescription({
|
||||||
...formattedCalEvent,
|
...calEvent,
|
||||||
additionalInformation: { hangoutLink: event.hangoutLink },
|
additionalInformation: { hangoutLink: event.hangoutLink },
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
@@ -340,43 +333,38 @@ export default class GoogleCalendarService implements Calendar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateEvent(uid: string, event: CalendarEvent, externalCalendarId: string): Promise<any> {
|
async updateEvent(uid: string, event: CalendarServiceEvent, externalCalendarId: string): Promise<any> {
|
||||||
const formattedCalEvent = formatCalEvent(event);
|
|
||||||
|
|
||||||
const payload: calendar_v3.Schema$Event = {
|
const payload: calendar_v3.Schema$Event = {
|
||||||
summary: formattedCalEvent.title,
|
summary: event.title,
|
||||||
description: getRichDescription(formattedCalEvent),
|
description: event.calendarDescription,
|
||||||
start: {
|
start: {
|
||||||
dateTime: formattedCalEvent.startTime,
|
dateTime: event.startTime,
|
||||||
timeZone: formattedCalEvent.organizer.timeZone,
|
timeZone: event.organizer.timeZone,
|
||||||
},
|
},
|
||||||
end: {
|
end: {
|
||||||
dateTime: formattedCalEvent.endTime,
|
dateTime: event.endTime,
|
||||||
timeZone: formattedCalEvent.organizer.timeZone,
|
timeZone: event.organizer.timeZone,
|
||||||
},
|
},
|
||||||
attendees: this.getAttendees({ event: formattedCalEvent, hostExternalCalendarId: externalCalendarId }),
|
attendees: this.getAttendees({ event, hostExternalCalendarId: externalCalendarId }),
|
||||||
reminders: {
|
reminders: {
|
||||||
useDefault: true,
|
useDefault: true,
|
||||||
},
|
},
|
||||||
guestsCanSeeOtherGuests: !!formattedCalEvent.seatsPerTimeSlot
|
guestsCanSeeOtherGuests: !!event.seatsPerTimeSlot ? event.seatsShowAttendees : true,
|
||||||
? formattedCalEvent.seatsShowAttendees
|
|
||||||
: true,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (formattedCalEvent.location) {
|
if (event.location) {
|
||||||
payload["location"] = getLocation(formattedCalEvent);
|
payload["location"] = getLocation(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (formattedCalEvent.conferenceData && formattedCalEvent.location === MeetLocationType) {
|
if (event.conferenceData && event.location === MeetLocationType) {
|
||||||
payload["conferenceData"] = formattedCalEvent.conferenceData;
|
payload["conferenceData"] = event.conferenceData;
|
||||||
}
|
}
|
||||||
|
|
||||||
const calendar = await this.authedCalendar();
|
const calendar = await this.authedCalendar();
|
||||||
|
|
||||||
const selectedCalendar =
|
const selectedCalendar =
|
||||||
(externalCalendarId
|
(externalCalendarId
|
||||||
? formattedCalEvent.destinationCalendar?.find((cal) => cal.externalId === externalCalendarId)
|
? event.destinationCalendar?.find((cal) => cal.externalId === externalCalendarId)?.externalId
|
||||||
?.externalId
|
|
||||||
: undefined) || "primary";
|
: undefined) || "primary";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -401,7 +389,7 @@ export default class GoogleCalendarService implements Calendar {
|
|||||||
eventId: evt.data.id || "",
|
eventId: evt.data.id || "",
|
||||||
requestBody: {
|
requestBody: {
|
||||||
description: getRichDescription({
|
description: getRichDescription({
|
||||||
...formattedCalEvent,
|
...event,
|
||||||
additionalInformation: { hangoutLink: evt.data.hangoutLink },
|
additionalInformation: { hangoutLink: evt.data.hangoutLink },
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
@@ -423,7 +411,7 @@ export default class GoogleCalendarService implements Calendar {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.log.error(
|
this.log.error(
|
||||||
"There was an error updating event in google calendar: ",
|
"There was an error updating event in google calendar: ",
|
||||||
safeStringify({ error, event: formattedCalEvent, uid })
|
safeStringify({ error, event, uid })
|
||||||
);
|
);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { getLocation, getRichDescription } from "@calcom/lib/CalEventParser";
|
import { getLocation } from "@calcom/lib/CalEventParser";
|
||||||
import logger from "@calcom/lib/logger";
|
import logger from "@calcom/lib/logger";
|
||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
import type { BufferedBusyTime } from "@calcom/types/BufferedBusyTime";
|
import type { BufferedBusyTime } from "@calcom/types/BufferedBusyTime";
|
||||||
import type {
|
import type {
|
||||||
Calendar,
|
Calendar,
|
||||||
|
CalendarServiceEvent,
|
||||||
CalendarEvent,
|
CalendarEvent,
|
||||||
EventBusyDate,
|
EventBusyDate,
|
||||||
IntegrationCalendar,
|
IntegrationCalendar,
|
||||||
@@ -130,7 +131,7 @@ export default class LarkCalendarService implements Calendar {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
async createEvent(event: CalendarEvent, credentialId: number): Promise<NewCalendarEventType> {
|
async createEvent(event: CalendarServiceEvent, credentialId: number): Promise<NewCalendarEventType> {
|
||||||
let eventId = "";
|
let eventId = "";
|
||||||
let eventRespData;
|
let eventRespData;
|
||||||
const mainHostDestinationCalendar = event.destinationCalendar
|
const mainHostDestinationCalendar = event.destinationCalendar
|
||||||
@@ -200,7 +201,7 @@ export default class LarkCalendarService implements Calendar {
|
|||||||
* @param event
|
* @param event
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async updateEvent(uid: string, event: CalendarEvent, externalCalendarId?: string) {
|
async updateEvent(uid: string, event: CalendarServiceEvent, externalCalendarId?: string) {
|
||||||
const eventId = uid;
|
const eventId = uid;
|
||||||
let eventRespData;
|
let eventRespData;
|
||||||
const mainHostDestinationCalendar = event.destinationCalendar?.find(
|
const mainHostDestinationCalendar = event.destinationCalendar?.find(
|
||||||
@@ -372,10 +373,10 @@ export default class LarkCalendarService implements Calendar {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private translateEvent = (event: CalendarEvent): LarkEvent => {
|
private translateEvent = (event: CalendarServiceEvent): LarkEvent => {
|
||||||
const larkEvent: LarkEvent = {
|
const larkEvent: LarkEvent = {
|
||||||
summary: event.title,
|
summary: event.title,
|
||||||
description: getRichDescription(event),
|
description: event.calendarDescription,
|
||||||
start_time: {
|
start_time: {
|
||||||
timestamp: parseEventTime2Timestamp(event.startTime),
|
timestamp: parseEventTime2Timestamp(event.startTime),
|
||||||
timezone: event.organizer.timeZone,
|
timezone: event.organizer.timeZone,
|
||||||
|
|||||||
@@ -2,18 +2,17 @@ import type { Calendar as OfficeCalendar, User, Event } from "@microsoft/microso
|
|||||||
import type { DefaultBodyType } from "msw";
|
import type { DefaultBodyType } from "msw";
|
||||||
|
|
||||||
import dayjs from "@calcom/dayjs";
|
import dayjs from "@calcom/dayjs";
|
||||||
import { getLocation, getRichDescription } from "@calcom/lib/CalEventParser";
|
import { getLocation } from "@calcom/lib/CalEventParser";
|
||||||
import {
|
import {
|
||||||
CalendarAppDelegationCredentialInvalidGrantError,
|
CalendarAppDelegationCredentialInvalidGrantError,
|
||||||
CalendarAppDelegationCredentialConfigurationError,
|
CalendarAppDelegationCredentialConfigurationError,
|
||||||
} from "@calcom/lib/CalendarAppError";
|
} from "@calcom/lib/CalendarAppError";
|
||||||
import { handleErrorsJson, handleErrorsRaw } from "@calcom/lib/errors";
|
import { handleErrorsJson, handleErrorsRaw } from "@calcom/lib/errors";
|
||||||
import { formatCalEvent } from "@calcom/lib/formatCalendarEvent";
|
|
||||||
import logger from "@calcom/lib/logger";
|
import logger from "@calcom/lib/logger";
|
||||||
import type { BufferedBusyTime } from "@calcom/types/BufferedBusyTime";
|
import type { BufferedBusyTime } from "@calcom/types/BufferedBusyTime";
|
||||||
import type {
|
import type {
|
||||||
Calendar,
|
Calendar,
|
||||||
CalendarEvent,
|
CalendarServiceEvent,
|
||||||
EventBusyDate,
|
EventBusyDate,
|
||||||
IntegrationCalendar,
|
IntegrationCalendar,
|
||||||
NewCalendarEventType,
|
NewCalendarEventType,
|
||||||
@@ -240,7 +239,7 @@ export default class Office365CalendarService implements Calendar {
|
|||||||
return azureUserId ? `/users/${this.azureUserId}` : "/me";
|
return azureUserId ? `/users/${this.azureUserId}` : "/me";
|
||||||
}
|
}
|
||||||
|
|
||||||
async createEvent(event: CalendarEvent, credentialId: number): Promise<NewCalendarEventType> {
|
async createEvent(event: CalendarServiceEvent, credentialId: number): Promise<NewCalendarEventType> {
|
||||||
const mainHostDestinationCalendar = event.destinationCalendar
|
const mainHostDestinationCalendar = event.destinationCalendar
|
||||||
? event.destinationCalendar.find((cal) => cal.credentialId === credentialId) ??
|
? event.destinationCalendar.find((cal) => cal.credentialId === credentialId) ??
|
||||||
event.destinationCalendar[0]
|
event.destinationCalendar[0]
|
||||||
@@ -250,10 +249,9 @@ export default class Office365CalendarService implements Calendar {
|
|||||||
? `${await this.getUserEndpoint()}/calendars/${mainHostDestinationCalendar?.externalId}/events`
|
? `${await this.getUserEndpoint()}/calendars/${mainHostDestinationCalendar?.externalId}/events`
|
||||||
: `${await this.getUserEndpoint()}/calendar/events`;
|
: `${await this.getUserEndpoint()}/calendar/events`;
|
||||||
|
|
||||||
const formattedEvent = formatCalEvent(event);
|
|
||||||
const response = await this.fetcher(eventsUrl, {
|
const response = await this.fetcher(eventsUrl, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(this.translateEvent(formattedEvent)),
|
body: JSON.stringify(this.translateEvent(event)),
|
||||||
});
|
});
|
||||||
|
|
||||||
const responseJson = await handleErrorsJson<NewCalendarEventType & { iCalUId: string }>(response);
|
const responseJson = await handleErrorsJson<NewCalendarEventType & { iCalUId: string }>(response);
|
||||||
@@ -266,7 +264,7 @@ export default class Office365CalendarService implements Calendar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateEvent(uid: string, event: CalendarEvent): Promise<NewCalendarEventType> {
|
async updateEvent(uid: string, event: CalendarServiceEvent): Promise<NewCalendarEventType> {
|
||||||
try {
|
try {
|
||||||
const response = await this.fetcher(`${await this.getUserEndpoint()}/calendar/events/${uid}`, {
|
const response = await this.fetcher(`${await this.getUserEndpoint()}/calendar/events/${uid}`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
@@ -403,12 +401,12 @@ export default class Office365CalendarService implements Calendar {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private translateEvent = (event: CalendarEvent) => {
|
private translateEvent = (event: CalendarServiceEvent) => {
|
||||||
const office365Event: Event = {
|
const office365Event: Event = {
|
||||||
subject: event.title,
|
subject: event.title,
|
||||||
body: {
|
body: {
|
||||||
contentType: "text",
|
contentType: "text",
|
||||||
content: getRichDescription(event),
|
content: event.calendarDescription,
|
||||||
},
|
},
|
||||||
start: {
|
start: {
|
||||||
dateTime: dayjs(event.startTime).tz(event.organizer.timeZone).format("YYYY-MM-DDTHH:mm:ss"),
|
dateTime: dayjs(event.startTime).tz(event.organizer.timeZone).format("YYYY-MM-DDTHH:mm:ss"),
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { stringify } from "querystring";
|
import { stringify } from "querystring";
|
||||||
|
|
||||||
import dayjs from "@calcom/dayjs";
|
import dayjs from "@calcom/dayjs";
|
||||||
import { getLocation, getRichDescription } from "@calcom/lib/CalEventParser";
|
import { getLocation } from "@calcom/lib/CalEventParser";
|
||||||
import logger from "@calcom/lib/logger";
|
import logger from "@calcom/lib/logger";
|
||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
import type {
|
import type {
|
||||||
Calendar,
|
Calendar,
|
||||||
|
CalendarServiceEvent,
|
||||||
CalendarEvent,
|
CalendarEvent,
|
||||||
EventBusyDate,
|
EventBusyDate,
|
||||||
IntegrationCalendar,
|
IntegrationCalendar,
|
||||||
@@ -112,7 +113,7 @@ export default class ZohoCalendarService implements Calendar {
|
|||||||
return this.handleData(response, this.log);
|
return this.handleData(response, this.log);
|
||||||
};
|
};
|
||||||
|
|
||||||
async createEvent(event: CalendarEvent): Promise<NewCalendarEventType> {
|
async createEvent(event: CalendarServiceEvent): Promise<NewCalendarEventType> {
|
||||||
let eventId = "";
|
let eventId = "";
|
||||||
let eventRespData;
|
let eventRespData;
|
||||||
const [mainHostDestinationCalendar] = event.destinationCalendar ?? [];
|
const [mainHostDestinationCalendar] = event.destinationCalendar ?? [];
|
||||||
@@ -158,7 +159,7 @@ export default class ZohoCalendarService implements Calendar {
|
|||||||
* @param event
|
* @param event
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async updateEvent(uid: string, event: CalendarEvent, externalCalendarId?: string) {
|
async updateEvent(uid: string, event: CalendarServiceEvent, externalCalendarId?: string) {
|
||||||
const eventId = uid;
|
const eventId = uid;
|
||||||
let eventRespData;
|
let eventRespData;
|
||||||
const [mainHostDestinationCalendar] = event.destinationCalendar ?? [];
|
const [mainHostDestinationCalendar] = event.destinationCalendar ?? [];
|
||||||
@@ -457,10 +458,10 @@ export default class ZohoCalendarService implements Calendar {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private translateEvent = (event: CalendarEvent) => {
|
private translateEvent = (event: CalendarServiceEvent) => {
|
||||||
const zohoEvent = {
|
const zohoEvent = {
|
||||||
title: event.title,
|
title: event.title,
|
||||||
description: getRichDescription(event),
|
description: event.calendarDescription,
|
||||||
dateandtime: {
|
dateandtime: {
|
||||||
start: dayjs(event.startTime).format("YYYYMMDDTHHmmssZZ"),
|
start: dayjs(event.startTime).format("YYYYMMDDTHHmmssZZ"),
|
||||||
end: dayjs(event.endTime).format("YYYYMMDDTHHmmssZZ"),
|
end: dayjs(event.endTime).format("YYYYMMDDTHHmmssZZ"),
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { getCalendar } from "@calcom/app-store/_utils/getCalendar";
|
|||||||
import { sendCancelledSeatEmailsAndSMS } from "@calcom/emails";
|
import { sendCancelledSeatEmailsAndSMS } from "@calcom/emails";
|
||||||
import sendPayload from "@calcom/features/webhooks/lib/sendOrSchedulePayload";
|
import sendPayload from "@calcom/features/webhooks/lib/sendOrSchedulePayload";
|
||||||
import type { EventPayloadType, EventTypeInfo } from "@calcom/features/webhooks/lib/sendPayload";
|
import type { EventPayloadType, EventTypeInfo } from "@calcom/features/webhooks/lib/sendPayload";
|
||||||
|
import { getRichDescription } from "@calcom/lib/CalEventParser";
|
||||||
import { getAllDelegationCredentialsForUserIncludeServiceAccountKey } from "@calcom/lib/delegationCredential/server";
|
import { getAllDelegationCredentialsForUserIncludeServiceAccountKey } from "@calcom/lib/delegationCredential/server";
|
||||||
import { getDelegationCredentialOrFindRegularCredential } from "@calcom/lib/delegationCredential/server";
|
import { getDelegationCredentialOrFindRegularCredential } from "@calcom/lib/delegationCredential/server";
|
||||||
import { HttpError } from "@calcom/lib/http-error";
|
import { HttpError } from "@calcom/lib/http-error";
|
||||||
@@ -96,6 +97,7 @@ async function cancelAttendeeSeat(
|
|||||||
const updatedEvt = {
|
const updatedEvt = {
|
||||||
...evt,
|
...evt,
|
||||||
attendees: evt.attendees.filter((evtAttendee) => attendee.email !== evtAttendee.email),
|
attendees: evt.attendees.filter((evtAttendee) => attendee.email !== evtAttendee.email),
|
||||||
|
calendarDescription: getRichDescription(evt),
|
||||||
};
|
};
|
||||||
if (reference.type.includes("_video")) {
|
if (reference.type.includes("_video")) {
|
||||||
integrationsToUpdate.push(updateMeeting(credential, updatedEvt, reference));
|
integrationsToUpdate.push(updateMeeting(credential, updatedEvt, reference));
|
||||||
|
|||||||
@@ -5,13 +5,17 @@ import { getCalendar } from "@calcom/app-store/_utils/getCalendar";
|
|||||||
import getApps from "@calcom/app-store/utils";
|
import getApps from "@calcom/app-store/utils";
|
||||||
import dayjs from "@calcom/dayjs";
|
import dayjs from "@calcom/dayjs";
|
||||||
import { getUid } from "@calcom/lib/CalEventParser";
|
import { getUid } from "@calcom/lib/CalEventParser";
|
||||||
|
import { getRichDescription } from "@calcom/lib/CalEventParser";
|
||||||
import { CalendarAppDelegationCredentialError } from "@calcom/lib/CalendarAppError";
|
import { CalendarAppDelegationCredentialError } from "@calcom/lib/CalendarAppError";
|
||||||
|
import { ORGANIZER_EMAIL_EXEMPT_DOMAINS } from "@calcom/lib/constants";
|
||||||
import { buildNonDelegationCredentials } from "@calcom/lib/delegationCredential/clientAndServer";
|
import { buildNonDelegationCredentials } from "@calcom/lib/delegationCredential/clientAndServer";
|
||||||
|
import { formatCalEvent } from "@calcom/lib/formatCalendarEvent";
|
||||||
import logger from "@calcom/lib/logger";
|
import logger from "@calcom/lib/logger";
|
||||||
import { getPiiFreeCalendarEvent, getPiiFreeCredential } from "@calcom/lib/piiFreeData";
|
import { getPiiFreeCalendarEvent, getPiiFreeCredential } from "@calcom/lib/piiFreeData";
|
||||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||||
import type {
|
import type {
|
||||||
CalendarEvent,
|
CalendarEvent,
|
||||||
|
CalendarServiceEvent,
|
||||||
EventBusyDate,
|
EventBusyDate,
|
||||||
IntegrationCalendar,
|
IntegrationCalendar,
|
||||||
NewCalendarEventType,
|
NewCalendarEventType,
|
||||||
@@ -280,10 +284,12 @@ export const getBusyCalendarTimes = async (
|
|||||||
|
|
||||||
export const createEvent = async (
|
export const createEvent = async (
|
||||||
credential: CredentialForCalendarService,
|
credential: CredentialForCalendarService,
|
||||||
calEvent: CalendarEvent,
|
originalEvent: CalendarEvent,
|
||||||
externalId?: string
|
externalId?: string
|
||||||
): Promise<EventResult<NewCalendarEventType>> => {
|
): Promise<EventResult<NewCalendarEventType>> => {
|
||||||
const uid: string = getUid(calEvent);
|
// Some calendar libraries may edit the original event so let's clone it
|
||||||
|
const formattedEvent = formatCalEvent(originalEvent);
|
||||||
|
const uid: string = getUid(formattedEvent);
|
||||||
const calendar = await getCalendar(credential);
|
const calendar = await getCalendar(credential);
|
||||||
let success = true;
|
let success = true;
|
||||||
let calError: string | undefined = undefined;
|
let calError: string | undefined = undefined;
|
||||||
@@ -291,14 +297,16 @@ export const createEvent = async (
|
|||||||
log.debug(
|
log.debug(
|
||||||
"Creating calendar event",
|
"Creating calendar event",
|
||||||
safeStringify({
|
safeStringify({
|
||||||
calEvent: getPiiFreeCalendarEvent(calEvent),
|
calEvent: getPiiFreeCalendarEvent(formattedEvent),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
// Check if the disabledNotes flag is set to true
|
// Check if the disabledNotes flag is set to true
|
||||||
if (calEvent.hideCalendarNotes) {
|
if (formattedEvent.hideCalendarNotes) {
|
||||||
calEvent.additionalNotes = "Notes have been hidden by the organizer"; // TODO: i18n this string?
|
formattedEvent.additionalNotes = "Notes have been hidden by the organizer"; // TODO: i18n this string?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const calEvent = processEvent(formattedEvent);
|
||||||
|
|
||||||
const externalCalendarIdWhenDelegationCredentialIsChosen = credential.delegatedToId
|
const externalCalendarIdWhenDelegationCredentialIsChosen = credential.delegatedToId
|
||||||
? externalId
|
? externalId
|
||||||
: undefined;
|
: undefined;
|
||||||
@@ -369,10 +377,12 @@ export const createEvent = async (
|
|||||||
|
|
||||||
export const updateEvent = async (
|
export const updateEvent = async (
|
||||||
credential: CredentialForCalendarService,
|
credential: CredentialForCalendarService,
|
||||||
calEvent: CalendarEvent,
|
rawCalEvent: CalendarEvent,
|
||||||
bookingRefUid: string | null,
|
bookingRefUid: string | null,
|
||||||
externalCalendarId: string | null
|
externalCalendarId: string | null
|
||||||
): Promise<EventResult<NewCalendarEventType>> => {
|
): Promise<EventResult<NewCalendarEventType>> => {
|
||||||
|
const formattedEvent = formatCalEvent(rawCalEvent);
|
||||||
|
const calEvent = processEvent(formattedEvent);
|
||||||
const uid = getUid(calEvent);
|
const uid = getUid(calEvent);
|
||||||
const calendar = await getCalendar(credential);
|
const calendar = await getCalendar(credential);
|
||||||
let success = false;
|
let success = false;
|
||||||
@@ -479,3 +489,25 @@ export const deleteEvent = async ({
|
|||||||
|
|
||||||
return Promise.resolve({});
|
return Promise.resolve({});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process the calendar event by generating description and removing attendees if needed
|
||||||
|
*/
|
||||||
|
const processEvent = (calEvent: CalendarEvent): CalendarServiceEvent => {
|
||||||
|
// Generate the calendar event description
|
||||||
|
const calendarEvent: CalendarServiceEvent = {
|
||||||
|
...calEvent,
|
||||||
|
calendarDescription: getRichDescription(calEvent),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Determine if the calendar event should include attendees
|
||||||
|
const isOrganizerExempt = ORGANIZER_EMAIL_EXEMPT_DOMAINS?.split(",")
|
||||||
|
.filter((domain) => domain.trim() !== "")
|
||||||
|
.some((domain) => calEvent.organizer.email.toLowerCase().endsWith(domain.toLowerCase()));
|
||||||
|
|
||||||
|
if (calEvent.hideOrganizerEmail && !isOrganizerExempt) {
|
||||||
|
calEvent.attendees = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return calendarEvent;
|
||||||
|
};
|
||||||
@@ -21,6 +21,7 @@ import sanitizeCalendarObject from "@calcom/lib/sanitizeCalendarObject";
|
|||||||
import type { Person as AttendeeInCalendarEvent } from "@calcom/types/Calendar";
|
import type { Person as AttendeeInCalendarEvent } from "@calcom/types/Calendar";
|
||||||
import type {
|
import type {
|
||||||
Calendar,
|
Calendar,
|
||||||
|
CalendarServiceEvent,
|
||||||
CalendarEvent,
|
CalendarEvent,
|
||||||
CalendarEventType,
|
CalendarEventType,
|
||||||
EventBusyDate,
|
EventBusyDate,
|
||||||
@@ -32,7 +33,6 @@ import type { CredentialPayload } from "@calcom/types/Credential";
|
|||||||
|
|
||||||
import { getLocation, getRichDescription } from "./CalEventParser";
|
import { getLocation, getRichDescription } from "./CalEventParser";
|
||||||
import { symmetricDecrypt } from "./crypto";
|
import { symmetricDecrypt } from "./crypto";
|
||||||
import { formatCalEvent } from "./formatCalendarEvent";
|
|
||||||
import logger from "./logger";
|
import logger from "./logger";
|
||||||
|
|
||||||
const TIMEZONE_FORMAT = "YYYY-MM-DDTHH:mm:ss[Z]";
|
const TIMEZONE_FORMAT = "YYYY-MM-DDTHH:mm:ss[Z]";
|
||||||
@@ -140,10 +140,9 @@ export default abstract class BaseCalendarService implements Calendar {
|
|||||||
return attendees;
|
return attendees;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createEvent(eventRaw: CalendarEvent, credentialId: number): Promise<NewCalendarEventType> {
|
async createEvent(event: CalendarServiceEvent, credentialId: number): Promise<NewCalendarEventType> {
|
||||||
try {
|
try {
|
||||||
const calendars = await this.listCalendars(eventRaw);
|
const calendars = await this.listCalendars(event);
|
||||||
const event = formatCalEvent(eventRaw);
|
|
||||||
const uid = uuidv4();
|
const uid = uuidv4();
|
||||||
|
|
||||||
// We create local ICS files
|
// We create local ICS files
|
||||||
@@ -153,7 +152,7 @@ export default abstract class BaseCalendarService implements Calendar {
|
|||||||
start: convertDate(event.startTime),
|
start: convertDate(event.startTime),
|
||||||
duration: getDuration(event.startTime, event.endTime),
|
duration: getDuration(event.startTime, event.endTime),
|
||||||
title: event.title,
|
title: event.title,
|
||||||
description: getRichDescription(event),
|
description: event.calendarDescription,
|
||||||
location: getLocation(event),
|
location: getLocation(event),
|
||||||
organizer: { email: event.organizer.email, name: event.organizer.name },
|
organizer: { email: event.organizer.email, name: event.organizer.name },
|
||||||
attendees: this.getAttendees(event),
|
attendees: this.getAttendees(event),
|
||||||
|
|||||||
@@ -180,6 +180,7 @@ export default class EventManager {
|
|||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
public async create(event: CalendarEvent): Promise<CreateUpdateResult> {
|
public async create(event: CalendarEvent): Promise<CreateUpdateResult> {
|
||||||
|
// TODO this method shouldn't be modifying the event object that's passed in
|
||||||
const evt = processLocation(event);
|
const evt = processLocation(event);
|
||||||
|
|
||||||
// Fallback to cal video if no location is set
|
// Fallback to cal video if no location is set
|
||||||
@@ -259,7 +260,7 @@ export default class EventManager {
|
|||||||
return result.type.includes("_calendar");
|
return result.type.includes("_calendar");
|
||||||
};
|
};
|
||||||
|
|
||||||
const createdCRMEvents = await this.createAllCRMEvents(clonedCalEvent);
|
const createdCRMEvents = await this.createAllCRMEvents(evt);
|
||||||
|
|
||||||
results.push(...createdCRMEvents);
|
results.push(...createdCRMEvents);
|
||||||
|
|
||||||
|
|||||||
Vendored
+6
-2
@@ -256,17 +256,21 @@ export interface IntegrationCalendar extends Ensure<Partial<_SelectedCalendar>,
|
|||||||
*/
|
*/
|
||||||
export type SelectedCalendarEventTypeIds = (number | null)[];
|
export type SelectedCalendarEventTypeIds = (number | null)[];
|
||||||
|
|
||||||
|
export interface CalendarServiceEvent extends CalendarEvent {
|
||||||
|
calendarDescription: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Calendar {
|
export interface Calendar {
|
||||||
getCredentialId?(): number;
|
getCredentialId?(): number;
|
||||||
createEvent(
|
createEvent(
|
||||||
event: CalendarEvent,
|
event: CalendarServiceEvent,
|
||||||
credentialId: number,
|
credentialId: number,
|
||||||
externalCalendarId?: string
|
externalCalendarId?: string
|
||||||
): Promise<NewCalendarEventType>;
|
): Promise<NewCalendarEventType>;
|
||||||
|
|
||||||
updateEvent(
|
updateEvent(
|
||||||
uid: string,
|
uid: string,
|
||||||
event: CalendarEvent,
|
event: CalendarServiceEvent,
|
||||||
externalCalendarId?: string | null
|
externalCalendarId?: string | null
|
||||||
): Promise<NewCalendarEventType | NewCalendarEventType[]>;
|
): Promise<NewCalendarEventType | NewCalendarEventType[]>;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user