Hide other attendees on event types with seats (#4766)

* Add seatsHideAttendees to schema

* Add migration

* Add frontend option to hide attendees

* Pass hide attendees to email

* Hide attendee names on success email

* Add types for existing attendees

* Hide other attendees if hidden

* Pass seatsHideAttendees to Google Cal

* Add translation

* Reduce redundancy

* Fix type error

* Change toggle to show attendee information

* Minor text change

* Fix type errors

* Update snapshots

* Merge branch 'main' into seats-hide-attendees

* Add back email

* Add close.com specific types

* Add eslint ignore comments

* Merge branch 'seats-hide-attendees' of https://github.com/calcom/cal.com into seats-hide-attendees

* Simplify tests

Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
authored and GitHub committed 2022-10-18 13:41:50 -06:00
1 parent 7f2560e1e3
commit 8fc4d342fd
18 files changed
+125 -30

No files matched your search

@@ -55,7 +55,7 @@ test("retrieve contact IDs: all exist", async () => {
const event = {
attendees,
} as CalendarEvent;
} as { attendees: { email: string; name: string | null; id: string }[] };
CloseCom.prototype.contact = {
search: () => ({ data: attendees }),
@@ -225,7 +225,7 @@ test("prepare data to create custom activity type instance: one attendees, with
attendees,
startTime: now.toISOString(),
additionalNotes: "Some comment!",
} as CalendarEvent;
} as any;
CloseCom.prototype.activity = {
type: {
@@ -82,12 +82,22 @@ export default class GoogleCalendarService implements Calendar {
timeZone: calEventRaw.organizer.timeZone,
},
attendees: [
{ ...calEventRaw.organizer, organizer: true, responseStatus: "accepted" },
...calEventRaw.attendees.map((attendee) => ({ ...attendee, responseStatus: "accepted" })),
{
...calEventRaw.organizer,
id: String(calEventRaw.organizer.id),
organizer: true,
responseStatus: "accepted",
},
// eslint-disable-next-line
...calEventRaw.attendees.map(({ id, ...rest }) => ({
rest,
responseStatus: "accepted",
})),
],
reminders: {
useDefault: true,
},
guestsCanSeeOtherGuests: calEventRaw.seatsShowAttendees,
};
if (calEventRaw.location) {
@@ -160,10 +170,23 @@ export default class GoogleCalendarService implements Calendar {
dateTime: event.endTime,
timeZone: event.organizer.timeZone,
},
attendees: [{ ...event.organizer, organizer: true, responseStatus: "accepted" }, ...event.attendees],
attendees: [
{
...event.organizer,
id: String(event.organizer.id),
organizer: true,
responseStatus: "accepted",
},
// eslint-disable-next-line
...event.attendees.map(({ id, ...rest }) => ({
rest,
responseStatus: "accepted",
})),
],
reminders: {
useDefault: true,
},
guestsCanSeeOtherGuests: event.seatsShowAttendees,
};
if (event.location) {
+4 -3
View File
@@ -84,17 +84,18 @@ export const sendRescheduledEmails = async (calEvent: CalendarEvent) => {
export const sendScheduledSeatsEmails = async (
calEvent: CalendarEvent,
invitee: Person,
newSeat: boolean
newSeat: boolean,
showAttendees: boolean
) => {
const emailsToSend: Promise<unknown>[] = [];
emailsToSend.push(
new Promise((resolve, reject) => {
try {
const scheduledEmail = new AttendeeScheduledEmail(calEvent, invitee);
const scheduledEmail = new AttendeeScheduledEmail(calEvent, invitee, showAttendees);
resolve(scheduledEmail.sendEmail());
} catch (e) {
reject(console.error("AttendeeRescheduledEmail.sendEmail failed", e));
reject(console.error("AttendeeScheduledEmail.sendEmail failed", e));
}
})
);
@@ -12,14 +12,24 @@ import BaseEmail from "./_base-email";
export default class AttendeeScheduledEmail extends BaseEmail {
calEvent: CalendarEvent;
attendee: Person;
showAttendees: boolean | undefined;
t: TFunction;
constructor(calEvent: CalendarEvent, attendee: Person) {
constructor(calEvent: CalendarEvent, attendee: Person, showAttendees?: boolean | undefined) {
super();
this.name = "SEND_BOOKING_CONFIRMATION";
this.calEvent = calEvent;
this.attendee = attendee;
this.showAttendees = showAttendees;
this.t = attendee.language.translate;
if (!this.showAttendees) {
this.calEvent.attendees = [
{
...this.attendee,
},
];
}
}
protected getiCalEventAsString(): string | undefined {
@@ -153,6 +153,7 @@ const getEventTypesFromDB = async (eventTypeId: number) => {
hideCalendarNotes: true,
seatsPerTimeSlot: true,
recurringEvent: true,
seatsShowAttendees: true,
bookingLimits: true,
workflows: {
include: {
@@ -442,6 +443,7 @@ async function handler(req: NextApiRequest & { userId?: number }) {
hideCalendarNotes: eventType.hideCalendarNotes,
requiresConfirmation: eventType.requiresConfirmation ?? false,
eventTypeId: eventType.id,
seatsShowAttendees: !!eventType.seatsShowAttendees,
};
// For seats, if the booking already exists then we want to add the new attendee to the existing booking
@@ -502,7 +504,7 @@ async function handler(req: NextApiRequest & { userId?: number }) {
const newSeat = booking.attendees.length !== 0;
await sendScheduledSeatsEmails(evt, invitee[0], newSeat);
await sendScheduledSeatsEmails(evt, invitee[0], newSeat, !!eventType.seatsShowAttendees);
const credentials = await refreshCredentials(organizerUser.credentials);
const eventManager = new EventManager({ ...organizerUser, credentials });
+1
View File
@@ -76,6 +76,7 @@ const commons = {
currency: "usd",
schedulingType: SchedulingType.COLLECTIVE,
seatsPerTimeSlot: null,
seatsShowAttendees: null,
id: 0,
hideCalendarNotes: false,
recurringEvent: null,
+2 -1
View File
@@ -19,7 +19,7 @@ export const buildPerson = (person?: Partial<Person>): Person => {
email: faker.internet.email(),
timeZone: faker.address.timeZone(),
username: faker.internet.userName(),
id: faker.datatype.uuid(),
id: faker.datatype.number(),
language: {
locale: faker.random.locale(),
translate: (key: string) => key,
@@ -85,6 +85,7 @@ export const buildEventType = (eventType?: Partial<EventType>): EventType => {
beforeEventBuffer: 0,
afterEventBuffer: 0,
seatsPerTimeSlot: null,
seatsShowAttendees: null,
schedulingType: null,
scheduleId: null,
bookingLimits: null,
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "EventType" ADD COLUMN "seatsShowAttendees" BOOLEAN;
+1
View File
@@ -68,6 +68,7 @@ model EventType {
beforeEventBuffer Int @default(0)
afterEventBuffer Int @default(0)
seatsPerTimeSlot Int?
seatsShowAttendees Boolean?
schedulingType SchedulingType?
schedule Schedule? @relation(fields: [scheduleId], references: [id])
scheduleId Int?
+4 -1
View File
@@ -22,7 +22,9 @@ export type Person = {
timeZone: string;
language: { translate: TFunction; locale: string };
username?: string;
id?: string;
id?: number;
bookingId?: number;
locale?: string;
};
export type EventBusyDate = {
@@ -141,6 +143,7 @@ export interface CalendarEvent {
recurrence?: string;
recurringEvent?: RecurringEvent | null;
eventTypeId?: number | null;
seatsShowAttendees?: boolean | null;
}
export interface EntryPoint {