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
@@ -5,13 +5,17 @@ import { getCalendar } from "@calcom/app-store/_utils/getCalendar";
|
||||
import getApps from "@calcom/app-store/utils";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { getUid } from "@calcom/lib/CalEventParser";
|
||||
import { getRichDescription } from "@calcom/lib/CalEventParser";
|
||||
import { CalendarAppDelegationCredentialError } from "@calcom/lib/CalendarAppError";
|
||||
import { ORGANIZER_EMAIL_EXEMPT_DOMAINS } from "@calcom/lib/constants";
|
||||
import { buildNonDelegationCredentials } from "@calcom/lib/delegationCredential/clientAndServer";
|
||||
import { formatCalEvent } from "@calcom/lib/formatCalendarEvent";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { getPiiFreeCalendarEvent, getPiiFreeCredential } from "@calcom/lib/piiFreeData";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import type {
|
||||
CalendarEvent,
|
||||
CalendarServiceEvent,
|
||||
EventBusyDate,
|
||||
IntegrationCalendar,
|
||||
NewCalendarEventType,
|
||||
@@ -280,10 +284,12 @@ export const getBusyCalendarTimes = async (
|
||||
|
||||
export const createEvent = async (
|
||||
credential: CredentialForCalendarService,
|
||||
calEvent: CalendarEvent,
|
||||
originalEvent: CalendarEvent,
|
||||
externalId?: string
|
||||
): 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);
|
||||
let success = true;
|
||||
let calError: string | undefined = undefined;
|
||||
@@ -291,14 +297,16 @@ export const createEvent = async (
|
||||
log.debug(
|
||||
"Creating calendar event",
|
||||
safeStringify({
|
||||
calEvent: getPiiFreeCalendarEvent(calEvent),
|
||||
calEvent: getPiiFreeCalendarEvent(formattedEvent),
|
||||
})
|
||||
);
|
||||
// Check if the disabledNotes flag is set to true
|
||||
if (calEvent.hideCalendarNotes) {
|
||||
calEvent.additionalNotes = "Notes have been hidden by the organizer"; // TODO: i18n this string?
|
||||
if (formattedEvent.hideCalendarNotes) {
|
||||
formattedEvent.additionalNotes = "Notes have been hidden by the organizer"; // TODO: i18n this string?
|
||||
}
|
||||
|
||||
const calEvent = processEvent(formattedEvent);
|
||||
|
||||
const externalCalendarIdWhenDelegationCredentialIsChosen = credential.delegatedToId
|
||||
? externalId
|
||||
: undefined;
|
||||
@@ -369,10 +377,12 @@ export const createEvent = async (
|
||||
|
||||
export const updateEvent = async (
|
||||
credential: CredentialForCalendarService,
|
||||
calEvent: CalendarEvent,
|
||||
rawCalEvent: CalendarEvent,
|
||||
bookingRefUid: string | null,
|
||||
externalCalendarId: string | null
|
||||
): Promise<EventResult<NewCalendarEventType>> => {
|
||||
const formattedEvent = formatCalEvent(rawCalEvent);
|
||||
const calEvent = processEvent(formattedEvent);
|
||||
const uid = getUid(calEvent);
|
||||
const calendar = await getCalendar(credential);
|
||||
let success = false;
|
||||
@@ -479,3 +489,25 @@ export const deleteEvent = async ({
|
||||
|
||||
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 {
|
||||
Calendar,
|
||||
CalendarServiceEvent,
|
||||
CalendarEvent,
|
||||
CalendarEventType,
|
||||
EventBusyDate,
|
||||
@@ -32,7 +33,6 @@ import type { CredentialPayload } from "@calcom/types/Credential";
|
||||
|
||||
import { getLocation, getRichDescription } from "./CalEventParser";
|
||||
import { symmetricDecrypt } from "./crypto";
|
||||
import { formatCalEvent } from "./formatCalendarEvent";
|
||||
import logger from "./logger";
|
||||
|
||||
const TIMEZONE_FORMAT = "YYYY-MM-DDTHH:mm:ss[Z]";
|
||||
@@ -140,10 +140,9 @@ export default abstract class BaseCalendarService implements Calendar {
|
||||
return attendees;
|
||||
}
|
||||
|
||||
async createEvent(eventRaw: CalendarEvent, credentialId: number): Promise<NewCalendarEventType> {
|
||||
async createEvent(event: CalendarServiceEvent, credentialId: number): Promise<NewCalendarEventType> {
|
||||
try {
|
||||
const calendars = await this.listCalendars(eventRaw);
|
||||
const event = formatCalEvent(eventRaw);
|
||||
const calendars = await this.listCalendars(event);
|
||||
const uid = uuidv4();
|
||||
|
||||
// We create local ICS files
|
||||
@@ -153,7 +152,7 @@ export default abstract class BaseCalendarService implements Calendar {
|
||||
start: convertDate(event.startTime),
|
||||
duration: getDuration(event.startTime, event.endTime),
|
||||
title: event.title,
|
||||
description: getRichDescription(event),
|
||||
description: event.calendarDescription,
|
||||
location: getLocation(event),
|
||||
organizer: { email: event.organizer.email, name: event.organizer.name },
|
||||
attendees: this.getAttendees(event),
|
||||
|
||||
@@ -180,6 +180,7 @@ export default class EventManager {
|
||||
* @param event
|
||||
*/
|
||||
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);
|
||||
|
||||
// Fallback to cal video if no location is set
|
||||
@@ -259,7 +260,7 @@ export default class EventManager {
|
||||
return result.type.includes("_calendar");
|
||||
};
|
||||
|
||||
const createdCRMEvents = await this.createAllCRMEvents(clonedCalEvent);
|
||||
const createdCRMEvents = await this.createAllCRMEvents(evt);
|
||||
|
||||
results.push(...createdCRMEvents);
|
||||
|
||||
|
||||
Reference in new issue
Block a user