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 prisma from "@calcom/prisma";
|
||||
import type { BufferedBusyTime } from "@calcom/types/BufferedBusyTime";
|
||||
import type {
|
||||
Calendar,
|
||||
CalendarServiceEvent,
|
||||
CalendarEvent,
|
||||
EventBusyDate,
|
||||
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 eventRespData;
|
||||
const mainHostDestinationCalendar = event.destinationCalendar
|
||||
@@ -200,7 +201,7 @@ export default class FeishuCalendarService implements Calendar {
|
||||
* @param event
|
||||
* @returns
|
||||
*/
|
||||
async updateEvent(uid: string, event: CalendarEvent, externalCalendarId?: string) {
|
||||
async updateEvent(uid: string, event: CalendarServiceEvent, externalCalendarId?: string) {
|
||||
const eventId = uid;
|
||||
let eventRespData;
|
||||
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 = {
|
||||
summary: event.title,
|
||||
description: getRichDescription(event),
|
||||
description: event.calendarDescription,
|
||||
start_time: {
|
||||
timestamp: parseEventTime2Timestamp(event.startTime),
|
||||
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 { getLocation, getRichDescription } from "@calcom/lib/CalEventParser";
|
||||
import { uniqueBy } from "@calcom/lib/array";
|
||||
import { formatCalEvent } from "@calcom/lib/formatCalendarEvent";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { SelectedCalendarRepository } from "@calcom/lib/server/repository/selectedCalendar";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type {
|
||||
Calendar,
|
||||
CalendarServiceEvent,
|
||||
CalendarEvent,
|
||||
EventBusyDate,
|
||||
IntegrationCalendar,
|
||||
@@ -168,75 +168,70 @@ export default class GoogleCalendarService implements Calendar {
|
||||
}
|
||||
|
||||
async createEvent(
|
||||
calEventRaw: CalendarEvent,
|
||||
calEvent: CalendarServiceEvent,
|
||||
credentialId: number,
|
||||
externalCalendarId?: string
|
||||
): Promise<NewCalendarEventType> {
|
||||
this.log.debug("Creating event");
|
||||
const formattedCalEvent = formatCalEvent(calEventRaw);
|
||||
|
||||
const payload: calendar_v3.Schema$Event = {
|
||||
summary: formattedCalEvent.title,
|
||||
description: getRichDescription(formattedCalEvent),
|
||||
summary: calEvent.title,
|
||||
description: calEvent.calendarDescription,
|
||||
start: {
|
||||
dateTime: formattedCalEvent.startTime,
|
||||
timeZone: formattedCalEvent.organizer.timeZone,
|
||||
dateTime: calEvent.startTime,
|
||||
timeZone: calEvent.organizer.timeZone,
|
||||
},
|
||||
end: {
|
||||
dateTime: formattedCalEvent.endTime,
|
||||
timeZone: formattedCalEvent.organizer.timeZone,
|
||||
dateTime: calEvent.endTime,
|
||||
timeZone: calEvent.organizer.timeZone,
|
||||
},
|
||||
attendees: this.getAttendees({ event: formattedCalEvent, hostExternalCalendarId: externalCalendarId }),
|
||||
attendees: this.getAttendees({ event: calEvent, hostExternalCalendarId: externalCalendarId }),
|
||||
reminders: {
|
||||
useDefault: true,
|
||||
},
|
||||
guestsCanSeeOtherGuests: !!formattedCalEvent.seatsPerTimeSlot
|
||||
? formattedCalEvent.seatsShowAttendees
|
||||
: true,
|
||||
iCalUID: formattedCalEvent.iCalUID,
|
||||
guestsCanSeeOtherGuests: !!calEvent.seatsPerTimeSlot ? calEvent.seatsShowAttendees : true,
|
||||
iCalUID: calEvent.iCalUID,
|
||||
};
|
||||
if (calEventRaw.hideCalendarEventDetails) {
|
||||
if (calEvent.hideCalendarEventDetails) {
|
||||
payload.visibility = "private";
|
||||
}
|
||||
|
||||
if (formattedCalEvent.location) {
|
||||
payload["location"] = getLocation(formattedCalEvent);
|
||||
if (calEvent.location) {
|
||||
payload["location"] = getLocation(calEvent);
|
||||
}
|
||||
|
||||
if (formattedCalEvent.recurringEvent) {
|
||||
if (calEvent.recurringEvent) {
|
||||
const rule = new RRule({
|
||||
freq: formattedCalEvent.recurringEvent.freq,
|
||||
interval: formattedCalEvent.recurringEvent.interval,
|
||||
count: formattedCalEvent.recurringEvent.count,
|
||||
freq: calEvent.recurringEvent.freq,
|
||||
interval: calEvent.recurringEvent.interval,
|
||||
count: calEvent.recurringEvent.count,
|
||||
});
|
||||
|
||||
payload["recurrence"] = [rule.toString()];
|
||||
}
|
||||
|
||||
if (formattedCalEvent.conferenceData && formattedCalEvent.location === MeetLocationType) {
|
||||
payload["conferenceData"] = formattedCalEvent.conferenceData;
|
||||
if (calEvent.conferenceData && calEvent.location === MeetLocationType) {
|
||||
payload["conferenceData"] = calEvent.conferenceData;
|
||||
}
|
||||
const calendar = await this.authedCalendar();
|
||||
// Find in formattedCalEvent.destinationCalendar the one with the same credentialId
|
||||
|
||||
const selectedCalendar =
|
||||
externalCalendarId ??
|
||||
(formattedCalEvent.destinationCalendar?.find((cal) => cal.credentialId === credentialId)?.externalId ||
|
||||
(calEvent.destinationCalendar?.find((cal) => cal.credentialId === credentialId)?.externalId ||
|
||||
"primary");
|
||||
|
||||
try {
|
||||
let event: calendar_v3.Schema$Event | undefined;
|
||||
let recurringEventId = null;
|
||||
if (formattedCalEvent.existingRecurringEvent) {
|
||||
recurringEventId = formattedCalEvent.existingRecurringEvent.recurringEventId;
|
||||
if (calEvent.existingRecurringEvent) {
|
||||
recurringEventId = calEvent.existingRecurringEvent.recurringEventId;
|
||||
const recurringEventInstances = await calendar.events.instances({
|
||||
calendarId: selectedCalendar,
|
||||
eventId: formattedCalEvent.existingRecurringEvent.recurringEventId,
|
||||
eventId: calEvent.existingRecurringEvent.recurringEventId,
|
||||
});
|
||||
if (recurringEventInstances.data.items) {
|
||||
const calComEventStartTime = dayjs(formattedCalEvent.startTime)
|
||||
.tz(formattedCalEvent.organizer.timeZone)
|
||||
.format();
|
||||
const calComEventStartTime = dayjs(calEvent.startTime).tz(calEvent.organizer.timeZone).format();
|
||||
for (let i = 0; i < recurringEventInstances.data.items.length; i++) {
|
||||
const instance = recurringEventInstances.data.items[i];
|
||||
const instanceStartTime = dayjs(instance.start?.dateTime)
|
||||
@@ -260,10 +255,8 @@ export default class GoogleCalendarService implements Calendar {
|
||||
calendarId: selectedCalendar,
|
||||
eventId: event.id || "",
|
||||
requestBody: {
|
||||
location: getLocation(formattedCalEvent),
|
||||
description: getRichDescription({
|
||||
...formattedCalEvent,
|
||||
}),
|
||||
location: getLocation(calEvent),
|
||||
description: calEvent.calendarDescription,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -290,7 +283,7 @@ export default class GoogleCalendarService implements Calendar {
|
||||
eventId: event.id || "",
|
||||
requestBody: {
|
||||
description: getRichDescription({
|
||||
...formattedCalEvent,
|
||||
...calEvent,
|
||||
additionalInformation: { hangoutLink: event.hangoutLink },
|
||||
}),
|
||||
},
|
||||
@@ -340,43 +333,38 @@ export default class GoogleCalendarService implements Calendar {
|
||||
}
|
||||
}
|
||||
|
||||
async updateEvent(uid: string, event: CalendarEvent, externalCalendarId: string): Promise<any> {
|
||||
const formattedCalEvent = formatCalEvent(event);
|
||||
|
||||
async updateEvent(uid: string, event: CalendarServiceEvent, externalCalendarId: string): Promise<any> {
|
||||
const payload: calendar_v3.Schema$Event = {
|
||||
summary: formattedCalEvent.title,
|
||||
description: getRichDescription(formattedCalEvent),
|
||||
summary: event.title,
|
||||
description: event.calendarDescription,
|
||||
start: {
|
||||
dateTime: formattedCalEvent.startTime,
|
||||
timeZone: formattedCalEvent.organizer.timeZone,
|
||||
dateTime: event.startTime,
|
||||
timeZone: event.organizer.timeZone,
|
||||
},
|
||||
end: {
|
||||
dateTime: formattedCalEvent.endTime,
|
||||
timeZone: formattedCalEvent.organizer.timeZone,
|
||||
dateTime: event.endTime,
|
||||
timeZone: event.organizer.timeZone,
|
||||
},
|
||||
attendees: this.getAttendees({ event: formattedCalEvent, hostExternalCalendarId: externalCalendarId }),
|
||||
attendees: this.getAttendees({ event, hostExternalCalendarId: externalCalendarId }),
|
||||
reminders: {
|
||||
useDefault: true,
|
||||
},
|
||||
guestsCanSeeOtherGuests: !!formattedCalEvent.seatsPerTimeSlot
|
||||
? formattedCalEvent.seatsShowAttendees
|
||||
: true,
|
||||
guestsCanSeeOtherGuests: !!event.seatsPerTimeSlot ? event.seatsShowAttendees : true,
|
||||
};
|
||||
|
||||
if (formattedCalEvent.location) {
|
||||
payload["location"] = getLocation(formattedCalEvent);
|
||||
if (event.location) {
|
||||
payload["location"] = getLocation(event);
|
||||
}
|
||||
|
||||
if (formattedCalEvent.conferenceData && formattedCalEvent.location === MeetLocationType) {
|
||||
payload["conferenceData"] = formattedCalEvent.conferenceData;
|
||||
if (event.conferenceData && event.location === MeetLocationType) {
|
||||
payload["conferenceData"] = event.conferenceData;
|
||||
}
|
||||
|
||||
const calendar = await this.authedCalendar();
|
||||
|
||||
const selectedCalendar =
|
||||
(externalCalendarId
|
||||
? formattedCalEvent.destinationCalendar?.find((cal) => cal.externalId === externalCalendarId)
|
||||
?.externalId
|
||||
? event.destinationCalendar?.find((cal) => cal.externalId === externalCalendarId)?.externalId
|
||||
: undefined) || "primary";
|
||||
|
||||
try {
|
||||
@@ -401,7 +389,7 @@ export default class GoogleCalendarService implements Calendar {
|
||||
eventId: evt.data.id || "",
|
||||
requestBody: {
|
||||
description: getRichDescription({
|
||||
...formattedCalEvent,
|
||||
...event,
|
||||
additionalInformation: { hangoutLink: evt.data.hangoutLink },
|
||||
}),
|
||||
},
|
||||
@@ -423,7 +411,7 @@ export default class GoogleCalendarService implements Calendar {
|
||||
} catch (error) {
|
||||
this.log.error(
|
||||
"There was an error updating event in google calendar: ",
|
||||
safeStringify({ error, event: formattedCalEvent, uid })
|
||||
safeStringify({ error, event, uid })
|
||||
);
|
||||
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 prisma from "@calcom/prisma";
|
||||
import type { BufferedBusyTime } from "@calcom/types/BufferedBusyTime";
|
||||
import type {
|
||||
Calendar,
|
||||
CalendarServiceEvent,
|
||||
CalendarEvent,
|
||||
EventBusyDate,
|
||||
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 eventRespData;
|
||||
const mainHostDestinationCalendar = event.destinationCalendar
|
||||
@@ -200,7 +201,7 @@ export default class LarkCalendarService implements Calendar {
|
||||
* @param event
|
||||
* @returns
|
||||
*/
|
||||
async updateEvent(uid: string, event: CalendarEvent, externalCalendarId?: string) {
|
||||
async updateEvent(uid: string, event: CalendarServiceEvent, externalCalendarId?: string) {
|
||||
const eventId = uid;
|
||||
let eventRespData;
|
||||
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 = {
|
||||
summary: event.title,
|
||||
description: getRichDescription(event),
|
||||
description: event.calendarDescription,
|
||||
start_time: {
|
||||
timestamp: parseEventTime2Timestamp(event.startTime),
|
||||
timezone: event.organizer.timeZone,
|
||||
|
||||
@@ -2,18 +2,17 @@ import type { Calendar as OfficeCalendar, User, Event } from "@microsoft/microso
|
||||
import type { DefaultBodyType } from "msw";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { getLocation, getRichDescription } from "@calcom/lib/CalEventParser";
|
||||
import { getLocation } from "@calcom/lib/CalEventParser";
|
||||
import {
|
||||
CalendarAppDelegationCredentialInvalidGrantError,
|
||||
CalendarAppDelegationCredentialConfigurationError,
|
||||
} from "@calcom/lib/CalendarAppError";
|
||||
import { handleErrorsJson, handleErrorsRaw } from "@calcom/lib/errors";
|
||||
import { formatCalEvent } from "@calcom/lib/formatCalendarEvent";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import type { BufferedBusyTime } from "@calcom/types/BufferedBusyTime";
|
||||
import type {
|
||||
Calendar,
|
||||
CalendarEvent,
|
||||
CalendarServiceEvent,
|
||||
EventBusyDate,
|
||||
IntegrationCalendar,
|
||||
NewCalendarEventType,
|
||||
@@ -240,7 +239,7 @@ export default class Office365CalendarService implements Calendar {
|
||||
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
|
||||
? event.destinationCalendar.find((cal) => cal.credentialId === credentialId) ??
|
||||
event.destinationCalendar[0]
|
||||
@@ -250,10 +249,9 @@ export default class Office365CalendarService implements Calendar {
|
||||
? `${await this.getUserEndpoint()}/calendars/${mainHostDestinationCalendar?.externalId}/events`
|
||||
: `${await this.getUserEndpoint()}/calendar/events`;
|
||||
|
||||
const formattedEvent = formatCalEvent(event);
|
||||
const response = await this.fetcher(eventsUrl, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(this.translateEvent(formattedEvent)),
|
||||
body: JSON.stringify(this.translateEvent(event)),
|
||||
});
|
||||
|
||||
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 {
|
||||
const response = await this.fetcher(`${await this.getUserEndpoint()}/calendar/events/${uid}`, {
|
||||
method: "PATCH",
|
||||
@@ -403,12 +401,12 @@ export default class Office365CalendarService implements Calendar {
|
||||
});
|
||||
}
|
||||
|
||||
private translateEvent = (event: CalendarEvent) => {
|
||||
private translateEvent = (event: CalendarServiceEvent) => {
|
||||
const office365Event: Event = {
|
||||
subject: event.title,
|
||||
body: {
|
||||
contentType: "text",
|
||||
content: getRichDescription(event),
|
||||
content: event.calendarDescription,
|
||||
},
|
||||
start: {
|
||||
dateTime: dayjs(event.startTime).tz(event.organizer.timeZone).format("YYYY-MM-DDTHH:mm:ss"),
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { stringify } from "querystring";
|
||||
|
||||
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 prisma from "@calcom/prisma";
|
||||
import type {
|
||||
Calendar,
|
||||
CalendarServiceEvent,
|
||||
CalendarEvent,
|
||||
EventBusyDate,
|
||||
IntegrationCalendar,
|
||||
@@ -112,7 +113,7 @@ export default class ZohoCalendarService implements Calendar {
|
||||
return this.handleData(response, this.log);
|
||||
};
|
||||
|
||||
async createEvent(event: CalendarEvent): Promise<NewCalendarEventType> {
|
||||
async createEvent(event: CalendarServiceEvent): Promise<NewCalendarEventType> {
|
||||
let eventId = "";
|
||||
let eventRespData;
|
||||
const [mainHostDestinationCalendar] = event.destinationCalendar ?? [];
|
||||
@@ -158,7 +159,7 @@ export default class ZohoCalendarService implements Calendar {
|
||||
* @param event
|
||||
* @returns
|
||||
*/
|
||||
async updateEvent(uid: string, event: CalendarEvent, externalCalendarId?: string) {
|
||||
async updateEvent(uid: string, event: CalendarServiceEvent, externalCalendarId?: string) {
|
||||
const eventId = uid;
|
||||
let eventRespData;
|
||||
const [mainHostDestinationCalendar] = event.destinationCalendar ?? [];
|
||||
@@ -457,10 +458,10 @@ export default class ZohoCalendarService implements Calendar {
|
||||
return data;
|
||||
}
|
||||
|
||||
private translateEvent = (event: CalendarEvent) => {
|
||||
private translateEvent = (event: CalendarServiceEvent) => {
|
||||
const zohoEvent = {
|
||||
title: event.title,
|
||||
description: getRichDescription(event),
|
||||
description: event.calendarDescription,
|
||||
dateandtime: {
|
||||
start: dayjs(event.startTime).format("YYYYMMDDTHHmmssZZ"),
|
||||
end: dayjs(event.endTime).format("YYYYMMDDTHHmmssZZ"),
|
||||
|
||||
Reference in new issue
Block a user