From 4d49fb0636cda834ba49c44a4ec85b5d581b5d16 Mon Sep 17 00:00:00 2001 From: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Date: Tue, 31 Oct 2023 22:05:23 +0530 Subject: [PATCH] fix: cal video recording email (#12079) * fix: cal video recording email * fix: add check for recording * chore: remove logs * chore: change message --------- Co-authored-by: Peer Richelsen --- .../components/booking/BookingListItem.tsx | 35 +++++------ apps/web/pages/api/recorded-daily-video.ts | 60 +++++++++++++++++-- apps/web/public/static/locales/en/common.json | 1 + ...er-daily-video-download-recording-email.ts | 5 ++ .../ee/video/ViewRecordingsDialog.tsx | 2 +- 5 files changed, 80 insertions(+), 23 deletions(-) diff --git a/apps/web/components/booking/BookingListItem.tsx b/apps/web/components/booking/BookingListItem.tsx index f600c6e697..32bb2ca515 100644 --- a/apps/web/components/booking/BookingListItem.tsx +++ b/apps/web/components/booking/BookingListItem.tsx @@ -141,17 +141,6 @@ function BookingListItem(booking: BookingItemProps) { : []), ]; - const showRecordingActions: ActionType[] = [ - { - id: "view_recordings", - label: t("view_recordings"), - onClick: () => { - setViewRecordingsDialogIsOpen(true); - }, - disabled: mutation.isLoading, - }, - ]; - let bookedActions: ActionType[] = [ { id: "cancel", @@ -270,11 +259,21 @@ function BookingListItem(booking: BookingItemProps) { const bookingLink = buildBookingLink(); const title = booking.title; - // To be used after we run query on legacy bookings - // const showRecordingsButtons = booking.isRecorded && isPast && isConfirmed; - const showRecordingsButtons = - (booking.location === "integrations:daily" || booking?.location?.trim() === "") && isPast && isConfirmed; + const showRecordingsButtons = !!(booking.isRecorded && isPast && isConfirmed); + const checkForRecordingsButton = + !showRecordingsButtons && (booking.location === "integrations:daily" || booking?.location?.trim() === ""); + + const showRecordingActions: ActionType[] = [ + { + id: checkForRecordingsButton ? "check_for_recordings" : "view_recordings", + label: checkForRecordingsButton ? t("check_for_recordings") : t("view_recordings"), + onClick: () => { + setViewRecordingsDialogIsOpen(true); + }, + disabled: mutation.isLoading, + }, + ]; return ( <> @@ -299,7 +298,7 @@ function BookingListItem(booking: BookingItemProps) { paymentCurrency={booking.payment[0].currency} /> )} - {showRecordingsButtons && ( + {(showRecordingsButtons || checkForRecordingsButton) && ( ) : null} {isPast && isPending && !isConfirmed ? : null} - {showRecordingsButtons && } + {(showRecordingsButtons || checkForRecordingsButton) && ( + + )} {isCancelled && booking.rescheduled && (
diff --git a/apps/web/pages/api/recorded-daily-video.ts b/apps/web/pages/api/recorded-daily-video.ts index 0ce22581a8..c35a9d5c7f 100644 --- a/apps/web/pages/api/recorded-daily-video.ts +++ b/apps/web/pages/api/recorded-daily-video.ts @@ -62,6 +62,46 @@ const triggerWebhook = async ({ await Promise.all(promises); }; +const checkIfUserIsPartOfTheSameTeam = async ( + teamId: number | undefined | null, + userId: number, + userEmail: string | undefined | null +) => { + if (!teamId) return false; + + const getUserQuery = () => { + if (!!userEmail) { + return { + OR: [ + { + id: userId, + }, + { + email: userEmail, + }, + ], + }; + } else { + return { + id: userId, + }; + } + }; + + const team = await prisma.team.findFirst({ + where: { + id: teamId, + members: { + some: { + user: getUserQuery(), + }, + }, + }, + }); + + return !!team; +}; + async function handler(req: NextApiRequest, res: NextApiResponse) { if (!process.env.SENDGRID_API_KEY || !process.env.SENDGRID_EMAIL) { return res.status(405).json({ message: "No SendGrid API key or email" }); @@ -137,12 +177,22 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { const isUserAttendeeOrOrganiser = booking?.user?.id === session.user.id || - attendeesList.find((attendee) => attendee.id === session.user.id); + attendeesList.find( + (attendee) => attendee.id === session.user.id || attendee.email === session.user.email + ); if (!isUserAttendeeOrOrganiser) { - return res.status(403).send({ - message: "Unauthorised", - }); + const isUserMemberOfTheTeam = checkIfUserIsPartOfTheSameTeam( + booking?.eventType?.teamId, + session.user.id, + session.user.email + ); + + if (!isUserMemberOfTheTeam) { + return res.status(403).send({ + message: "Unauthorised", + }); + } } await prisma.booking.update({ @@ -202,7 +252,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { return res.status(403).json({ message: "User does not have team plan to send out emails" }); } catch (err) { - console.warn("something_went_wrong", err); + console.warn("Error in /recorded-daily-video", err); return res.status(500).json({ message: "something went wrong" }); } } diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index f0b6749d7b..f80967618f 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -1296,6 +1296,7 @@ "select_calendars": "Select which calendars you want to check for conflicts to prevent double bookings.", "check_for_conflicts": "Check for conflicts", "view_recordings": "View recordings", + "check_for_recordings":"Check for recordings", "adding_events_to": "Adding events to", "follow_system_preferences": "Follow system preferences", "custom_brand_colors": "Custom brand colors", diff --git a/packages/emails/templates/organizer-daily-video-download-recording-email.ts b/packages/emails/templates/organizer-daily-video-download-recording-email.ts index 60c673ef5c..714ba4f7e4 100644 --- a/packages/emails/templates/organizer-daily-video-download-recording-email.ts +++ b/packages/emails/templates/organizer-daily-video-download-recording-email.ts @@ -50,8 +50,13 @@ export default class OrganizerDailyVideoDownloadRecordingEmail extends BaseEmail return this.getFormattedRecipientTime({ time: this.calEvent.endTime, format }); } + protected getLocale(): string { + return this.calEvent.organizer.language.locale; + } + protected getFormattedDate() { const organizerTimeFormat = this.calEvent.organizer.timeFormat || TimeFormat.TWELVE_HOUR; + return `${this.getOrganizerStart(organizerTimeFormat)} - ${this.getOrganizerEnd( organizerTimeFormat )}, ${this.t(this.getOrganizerStart("dddd").toLowerCase())}, ${this.t( diff --git a/packages/features/ee/video/ViewRecordingsDialog.tsx b/packages/features/ee/video/ViewRecordingsDialog.tsx index 74563b35fd..6134304d25 100644 --- a/packages/features/ee/video/ViewRecordingsDialog.tsx +++ b/packages/features/ee/video/ViewRecordingsDialog.tsx @@ -174,7 +174,7 @@ export const ViewRecordingsDialog = (props: IViewRecordingsDialog) => { return ( - + {roomName ? (