fix: hide cal branding for orgs/teams (#27643)
* fix: hide branding for teams * fix: remove unused organizationId and username fields from profiles select Addresses Cubic AI review feedback (confidence 9/10) to select only the profile fields that are actually used. The organizationId and username fields were fetched but never referenced in this function. Co-Authored-By: unknown <> * fix: unit tests * fix: add prisma named export to test mock Co-Authored-By: [email protected] <[email protected]> * Add tests: packages/features/profile/lib/hideBranding.test.ts Generated by Paragon from proposal for PR #27643 * chore: implement cubic feedback * fix: merge conflicts * fix: unit tests * fixup * refactor: implement DI pattern for event type service * fix: atoms build --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
39 files changed
+1129
-154
No files matched your search
@@ -1,6 +1,10 @@
|
||||
import { sendScheduledEmailsAndSMS } from "@calcom/emails/email-manager";
|
||||
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
|
||||
import { scheduleNoShowTriggers } from "@calcom/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers";
|
||||
import {
|
||||
type EventTypeBrandingData,
|
||||
getEventTypeService,
|
||||
} from "@calcom/features/eventtypes/di/EventTypeService.container";
|
||||
import { isPrismaObjOrUndefined } from "@calcom/lib/isPrismaObj";
|
||||
import { getTranslation } from "@calcom/i18n/server";
|
||||
import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
|
||||
@@ -9,9 +13,7 @@ import { BookingStatus } from "@calcom/prisma/enums";
|
||||
import { bookingMetadataSchema, EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
import type { TConnectAndJoinInputSchema } from "./connectAndJoin.schema";
|
||||
|
||||
type Options = {
|
||||
@@ -32,6 +34,18 @@ export const Handler = async ({ ctx, input }: Options) => {
|
||||
|
||||
const tOrganizer = await getTranslation(user?.locale ?? "en", "common");
|
||||
|
||||
const userBrandingInfo = await prisma.user.findUnique({
|
||||
where: { id: user.id },
|
||||
select: {
|
||||
hideBranding: true,
|
||||
profiles: {
|
||||
select: {
|
||||
organization: { select: { hideBranding: true } },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const instantMeetingToken = await prisma.instantMeetingToken.findUnique({
|
||||
select: {
|
||||
expires: true,
|
||||
@@ -135,6 +149,8 @@ export const Handler = async ({ ctx, input }: Options) => {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
hideBranding: true,
|
||||
parent: { select: { hideBranding: true } },
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -221,6 +237,21 @@ export const Handler = async ({ ctx, input }: Options) => {
|
||||
members: [],
|
||||
}
|
||||
: undefined,
|
||||
hideBranding: updatedBooking.eventTypeId
|
||||
? await getEventTypeService().shouldHideBrandingForEventType(updatedBooking.eventTypeId, {
|
||||
team: updatedBooking.eventType?.team
|
||||
? {
|
||||
hideBranding: updatedBooking.eventType.team.hideBranding,
|
||||
parent: updatedBooking.eventType.team.parent,
|
||||
}
|
||||
: null,
|
||||
owner: {
|
||||
id: user.id,
|
||||
hideBranding: userBrandingInfo?.hideBranding ?? null,
|
||||
profiles: userBrandingInfo?.profiles ?? [],
|
||||
},
|
||||
} satisfies EventTypeBrandingData)
|
||||
: false,
|
||||
};
|
||||
|
||||
const eventTypeMetadata = EventTypeMetaDataSchema.parse(updatedBooking?.eventType?.metadata);
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import type { NextApiRequest } from "next";
|
||||
|
||||
import { sendEmailVerificationByCode } from "@calcom/features/auth/lib/verifyEmail";
|
||||
import { getEventTypeService } from "@calcom/features/eventtypes/di/EventTypeService.container";
|
||||
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
|
||||
import getIP from "@calcom/lib/getIP";
|
||||
import { hashEmail, piiHasher } from "@calcom/lib/server/PiiHasher";
|
||||
|
||||
import type { NextApiRequest } from "next";
|
||||
import type { TRPCContext } from "../../../createContext";
|
||||
import type { TSendVerifyEmailCodeSchema } from "./sendVerifyEmailCode.schema";
|
||||
|
||||
@@ -30,10 +29,17 @@ export const sendVerifyEmailCode = async ({
|
||||
identifier: `sendVerifyEmailCode:${identifier}`,
|
||||
});
|
||||
|
||||
let hideBranding = false;
|
||||
if (input.eventTypeId) {
|
||||
const eventTypeService = getEventTypeService();
|
||||
hideBranding = await eventTypeService.shouldHideBrandingForEventType(input.eventTypeId);
|
||||
}
|
||||
|
||||
return await sendEmailVerificationByCode({
|
||||
email: input.email,
|
||||
username: input.username,
|
||||
language: input.language,
|
||||
isVerifyingEmail: input.isVerifyingEmail,
|
||||
hideBranding,
|
||||
});
|
||||
};
|
||||
@@ -5,6 +5,7 @@ export type TSendVerifyEmailCodeSchema = {
|
||||
username?: string;
|
||||
language: string;
|
||||
isVerifyingEmail?: boolean;
|
||||
eventTypeId?: number;
|
||||
};
|
||||
|
||||
export const ZSendVerifyEmailCodeSchema: z.ZodType<TSendVerifyEmailCodeSchema> = z.object({
|
||||
@@ -12,4 +13,5 @@ export const ZSendVerifyEmailCodeSchema: z.ZodType<TSendVerifyEmailCodeSchema> =
|
||||
username: z.string().optional(),
|
||||
language: z.string(),
|
||||
isVerifyingEmail: z.boolean().optional(),
|
||||
eventTypeId: z.number().optional(),
|
||||
});
|
||||
@@ -8,6 +8,10 @@ import { BookingEmailSmsHandler } from "@calcom/features/bookings/lib/BookingEma
|
||||
import EventManager from "@calcom/features/bookings/lib/EventManager";
|
||||
import { BookingRepository } from "@calcom/features/bookings/repositories/BookingRepository";
|
||||
import { getFeaturesRepository } from "@calcom/features/di/containers/FeaturesRepository";
|
||||
import {
|
||||
type EventTypeBrandingData,
|
||||
getEventTypeService,
|
||||
} from "@calcom/features/eventtypes/di/EventTypeService.container";
|
||||
import { PermissionCheckService } from "@calcom/features/pbac/services/permission-check.service";
|
||||
import { UserRepository } from "@calcom/features/users/repositories/UserRepository";
|
||||
import { extractBaseEmail } from "@calcom/lib/extract-base-email";
|
||||
@@ -23,10 +27,7 @@ import { TRPCError } from "@trpc/server";
|
||||
import type { TrpcSessionUser } from "../../../types";
|
||||
import type { TAddGuestsInputSchema } from "./addGuests.schema";
|
||||
|
||||
export type TUser = Pick<
|
||||
NonNullable<TrpcSessionUser>,
|
||||
"id" | "email" | "organizationId" | "uuid"
|
||||
> &
|
||||
export type TUser = Pick<NonNullable<TrpcSessionUser>, "id" | "email" | "organizationId" | "uuid"> &
|
||||
Partial<Pick<NonNullable<TrpcSessionUser>, "profile">>;
|
||||
|
||||
type AddGuestsOptions = {
|
||||
@@ -79,9 +80,7 @@ export const addGuestsHandler = async ({
|
||||
);
|
||||
|
||||
// Capture new attendee emails after update for audit logging
|
||||
const newAttendeeEmails = bookingAttendees.attendees.map(
|
||||
(attendee) => attendee.email
|
||||
);
|
||||
const newAttendeeEmails = bookingAttendees.attendees.map((attendee) => attendee.email);
|
||||
|
||||
const attendeesList = await prepareAttendeesList(bookingAttendees.attendees);
|
||||
|
||||
@@ -97,10 +96,7 @@ export const addGuestsHandler = async ({
|
||||
const featuresRepository = getFeaturesRepository();
|
||||
const organizationId = user.organizationId ?? null;
|
||||
const isBookingAuditEnabled = organizationId
|
||||
? await featuresRepository.checkIfTeamHasFeature(
|
||||
organizationId,
|
||||
"booking-audit"
|
||||
)
|
||||
? await featuresRepository.checkIfTeamHasFeature(organizationId, "booking-audit")
|
||||
: false;
|
||||
|
||||
await bookingEventHandlerService.onAttendeeAdded({
|
||||
@@ -119,9 +115,7 @@ export const addGuestsHandler = async ({
|
||||
|
||||
export async function getBooking(bookingId: number) {
|
||||
const bookingRepository = new BookingRepository(prisma);
|
||||
const booking = await bookingRepository.findByIdIncludeDestinationCalendar(
|
||||
bookingId
|
||||
);
|
||||
const booking = await bookingRepository.findByIdIncludeDestinationCalendar(bookingId);
|
||||
|
||||
if (!booking || !booking.user) {
|
||||
throw new TRPCError({ code: "NOT_FOUND", message: "booking_not_found" });
|
||||
@@ -130,14 +124,9 @@ export async function getBooking(bookingId: number) {
|
||||
return booking;
|
||||
}
|
||||
|
||||
export async function validateUserPermissions(
|
||||
booking: Booking,
|
||||
user: TUser
|
||||
): Promise<void> {
|
||||
export async function validateUserPermissions(booking: Booking, user: TUser): Promise<void> {
|
||||
const isOrganizer = booking.userId === user.id;
|
||||
const isAttendee = !!booking.attendees.find(
|
||||
(attendee) => attendee.email === user.email
|
||||
);
|
||||
const isAttendee = !!booking.attendees.find((attendee) => attendee.email === user.email);
|
||||
|
||||
let hasBookingUpdatePermission = false;
|
||||
if (booking.eventType?.teamId) {
|
||||
@@ -163,9 +152,7 @@ export function validateGuestsFieldEnabled(booking: Booking): void {
|
||||
? eventTypeBookingFields.parse(booking.eventType.bookingFields)
|
||||
: [];
|
||||
|
||||
const guestsBookingField = parsedBookingFields.find(
|
||||
(field) => field.name === "guests"
|
||||
);
|
||||
const guestsBookingField = parsedBookingFields.find((field) => field.name === "guests");
|
||||
if (guestsBookingField?.hidden) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
@@ -184,10 +171,17 @@ export async function getOrganizerData(userId: number | null) {
|
||||
id: userId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
email: true,
|
||||
timeZone: true,
|
||||
locale: true,
|
||||
hideBranding: true,
|
||||
profiles: {
|
||||
select: {
|
||||
organization: { select: { hideBranding: true } },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -206,30 +200,20 @@ function deduplicateGuestEmails(guests: string[]): string[] {
|
||||
|
||||
function getBlacklistedEmails(): string[] {
|
||||
return process.env.BLACKLISTED_GUEST_EMAILS
|
||||
? process.env.BLACKLISTED_GUEST_EMAILS.split(",").map((email) =>
|
||||
email.toLowerCase()
|
||||
)
|
||||
? process.env.BLACKLISTED_GUEST_EMAILS.split(",").map((email) => email.toLowerCase())
|
||||
: [];
|
||||
}
|
||||
|
||||
async function getEmailVerificationRequirements(
|
||||
guestEmails: string[]
|
||||
): Promise<Map<string, boolean>> {
|
||||
async function getEmailVerificationRequirements(guestEmails: string[]): Promise<Map<string, boolean>> {
|
||||
const userRepo = new UserRepository(prisma);
|
||||
const guestUsers =
|
||||
await userRepo.findManyByEmailsWithEmailVerificationSettings({
|
||||
emails: guestEmails,
|
||||
});
|
||||
const guestUsers = await userRepo.findManyByEmailsWithEmailVerificationSettings({
|
||||
emails: guestEmails,
|
||||
});
|
||||
|
||||
const emailToRequiresVerification = new Map<string, boolean>();
|
||||
for (const user of guestUsers) {
|
||||
const matchedBase = extractBaseEmail(
|
||||
user.matchedEmail ?? user.email
|
||||
).toLowerCase();
|
||||
emailToRequiresVerification.set(
|
||||
matchedBase,
|
||||
user.requiresBookerEmailVerification === true
|
||||
);
|
||||
const matchedBase = extractBaseEmail(user.matchedEmail ?? user.email).toLowerCase();
|
||||
emailToRequiresVerification.set(matchedBase, user.requiresBookerEmailVerification === true);
|
||||
}
|
||||
|
||||
return emailToRequiresVerification;
|
||||
@@ -256,12 +240,8 @@ export async function sanitizeAndFilterGuests(
|
||||
const guestEmails = guests.map((guest) => guest.email);
|
||||
const deduplicatedGuests = deduplicateGuestEmails(guestEmails);
|
||||
const blacklistedGuestEmails = getBlacklistedEmails();
|
||||
const guestEmailsLowerCase = deduplicatedGuests.map((email) =>
|
||||
extractBaseEmail(email).toLowerCase()
|
||||
);
|
||||
const emailToRequiresVerification = await getEmailVerificationRequirements(
|
||||
guestEmailsLowerCase
|
||||
);
|
||||
const guestEmailsLowerCase = deduplicatedGuests.map((email) => extractBaseEmail(email).toLowerCase());
|
||||
const emailToRequiresVerification = await getEmailVerificationRequirements(guestEmailsLowerCase);
|
||||
|
||||
// Create a map of email to guest object for easy lookup
|
||||
const emailToGuestMap = new Map(
|
||||
@@ -272,8 +252,7 @@ export async function sanitizeAndFilterGuests(
|
||||
const baseGuestEmail = extractBaseEmail(email).toLowerCase();
|
||||
return (
|
||||
!booking.attendees.some(
|
||||
(attendee) =>
|
||||
extractBaseEmail(attendee.email).toLowerCase() === baseGuestEmail
|
||||
(attendee) => extractBaseEmail(attendee.email).toLowerCase() === baseGuestEmail
|
||||
) &&
|
||||
!blacklistedGuestEmails.includes(baseGuestEmail) &&
|
||||
!emailToRequiresVerification.get(baseGuestEmail)
|
||||
@@ -339,9 +318,7 @@ export async function buildCalendarEvent(
|
||||
attendeesList: Awaited<ReturnType<typeof prepareAttendeesList>>
|
||||
): Promise<CalendarEvent> {
|
||||
const tOrganizer = await getTranslation(organizer.locale ?? "en", "common");
|
||||
const videoCallReference = booking.references.find((reference) =>
|
||||
reference.type.includes("_video")
|
||||
);
|
||||
const videoCallReference = booking.references.find((reference) => reference.type.includes("_video"));
|
||||
|
||||
const evt: CalendarEvent = {
|
||||
title: booking.title || "",
|
||||
@@ -364,12 +341,24 @@ export async function buildCalendarEvent(
|
||||
destinationCalendar: booking?.destinationCalendar
|
||||
? [booking?.destinationCalendar]
|
||||
: booking?.user?.destinationCalendar
|
||||
? [booking?.user?.destinationCalendar]
|
||||
: [],
|
||||
? [booking?.user?.destinationCalendar]
|
||||
: [],
|
||||
seatsPerTimeSlot: booking.eventType?.seatsPerTimeSlot,
|
||||
seatsShowAttendees: booking.eventType?.seatsShowAttendees,
|
||||
customReplyToEmail: booking.eventType?.customReplyToEmail,
|
||||
organizationId: booking.user?.profiles?.[0]?.organizationId ?? null,
|
||||
hideBranding: booking.eventTypeId
|
||||
? await getEventTypeService().shouldHideBrandingForEventType(booking.eventTypeId, {
|
||||
team: booking.eventType?.team
|
||||
? { hideBranding: booking.eventType.team.hideBranding, parent: booking.eventType.team.parent }
|
||||
: null,
|
||||
owner: {
|
||||
id: organizer.id,
|
||||
hideBranding: organizer.hideBranding,
|
||||
profiles: organizer.profiles ?? [],
|
||||
},
|
||||
} satisfies EventTypeBrandingData)
|
||||
: false,
|
||||
};
|
||||
|
||||
if (videoCallReference) {
|
||||
@@ -384,10 +373,7 @@ export async function buildCalendarEvent(
|
||||
return evt;
|
||||
}
|
||||
|
||||
export async function updateCalendarEvent(
|
||||
booking: Booking,
|
||||
evt: CalendarEvent
|
||||
): Promise<void> {
|
||||
export async function updateCalendarEvent(booking: Booking, evt: CalendarEvent): Promise<void> {
|
||||
if (!booking.user) {
|
||||
throw new TRPCError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
@@ -395,9 +381,7 @@ export async function updateCalendarEvent(
|
||||
});
|
||||
}
|
||||
|
||||
const credentials = await getUsersCredentialsIncludeServiceAccountKey(
|
||||
booking.user
|
||||
);
|
||||
const credentials = await getUsersCredentialsIncludeServiceAccountKey(booking.user);
|
||||
|
||||
const eventManager = new EventManager({
|
||||
...booking.user,
|
||||
@@ -419,9 +403,7 @@ export async function sendGuestNotifications(
|
||||
await emailsAndSmsHandler.handleAddGuests({
|
||||
evt,
|
||||
eventType: {
|
||||
metadata: eventTypeMetaDataSchemaWithTypedApps.parse(
|
||||
booking?.eventType?.metadata
|
||||
),
|
||||
metadata: eventTypeMetaDataSchemaWithTypedApps.parse(booking?.eventType?.metadata),
|
||||
schedulingType: booking.eventType?.schedulingType || null,
|
||||
},
|
||||
newGuests: uniqueGuests,
|
||||
|
||||
@@ -19,6 +19,10 @@ import { getBookerBaseUrl } from "@calcom/features/ee/organizations/lib/getBooke
|
||||
import { workflowSelect } from "@calcom/features/ee/workflows/lib/getAllWorkflows";
|
||||
import { getAllWorkflowsFromEventType } from "@calcom/features/ee/workflows/lib/getAllWorkflowsFromEventType";
|
||||
import { WorkflowService } from "@calcom/features/ee/workflows/lib/service/WorkflowService";
|
||||
import {
|
||||
type EventTypeBrandingData,
|
||||
getEventTypeService,
|
||||
} from "@calcom/features/eventtypes/di/EventTypeService.container";
|
||||
import type { GetSubscriberOptions } from "@calcom/features/webhooks/lib/getWebhooks";
|
||||
import type { EventPayloadType, EventTypeInfo } from "@calcom/features/webhooks/lib/sendPayload";
|
||||
import getOrgIdFromMemberOrTeamId from "@calcom/lib/getOrgIdFromMemberOrTeamId";
|
||||
@@ -168,6 +172,8 @@ export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => {
|
||||
id: true,
|
||||
name: true,
|
||||
parentId: true,
|
||||
hideBranding: true,
|
||||
parent: { select: { hideBranding: true } },
|
||||
},
|
||||
},
|
||||
workflows: {
|
||||
@@ -198,6 +204,12 @@ export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => {
|
||||
name: true,
|
||||
destinationCalendar: true,
|
||||
locale: true,
|
||||
hideBranding: true,
|
||||
profiles: {
|
||||
select: {
|
||||
organization: { select: { hideBranding: true } },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
id: true,
|
||||
@@ -352,6 +364,18 @@ export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => {
|
||||
details: booking.assignmentReason[0].reasonString ?? null,
|
||||
}
|
||||
: null,
|
||||
hideBranding: booking.eventType?.id
|
||||
? await getEventTypeService().shouldHideBrandingForEventType(booking.eventType.id, {
|
||||
team: booking.eventType.team
|
||||
? { hideBranding: booking.eventType.team.hideBranding, parent: booking.eventType.team.parent }
|
||||
: null,
|
||||
owner: {
|
||||
id: user.id,
|
||||
hideBranding: user.hideBranding,
|
||||
profiles: user.profiles ?? [],
|
||||
},
|
||||
} satisfies EventTypeBrandingData)
|
||||
: false,
|
||||
};
|
||||
|
||||
const recurringEvent = parseRecurringEvent(booking.eventType?.recurringEvent);
|
||||
@@ -564,7 +588,7 @@ export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => {
|
||||
slug: booking.eventType?.slug as string,
|
||||
},
|
||||
},
|
||||
hideBranding: !!booking.eventType?.owner?.hideBranding,
|
||||
hideBranding: evt.hideBranding,
|
||||
triggers: [WorkflowTriggerEvents.BOOKING_REJECTED],
|
||||
creditCheckFn: creditService.hasAvailableCredits.bind(creditService),
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user