feat: Salesforce skip ownership check if attendee email is a free domain (#17916)
* Add email domain array * Create numbered email domain object * Check email domain * Rename function * Add tests * Frontend enable skip ownership check if free email domain * Backend ignore adding ownership to return records if free email domain check is enabled * feat: Only require confirmation for free email domains (#17917) * Add requiresConfirmationForFreeEmail to db * Add option to event type settings * Get requiresConfirmationForFreeEmail for event type page * Include requiresConfirmationForFreeEmail in fetching event type * Pass bookerEmail to `getRequiresConfirmationFlags` * Add free email domain check to `determineRequiresConfirmation` * Add `requiresConfirmationForFreeEmail` to types * Add severity to Watchlist table * Add migration for watchlist severity * Add `getEmailDomainInWatchlist` method to watchlist repository * Use watchlist repository to check for free email domain * Mock watchlist repository in test * Update test * Rename method * Add severity to blocked list * Move check free email domain to async * Type checks * Adjust for promise returned * Fix tests * Fix * Fix tests
This commit is contained in:
1 parent
a7f24e777b
commit
8dda418127
27 files changed
+4951
-36
No files matched your search
@@ -6,7 +6,7 @@ import { hashPassword } from "@calcom/features/auth/lib/hashPassword";
|
||||
import { sendEmailVerification } from "@calcom/features/auth/lib/verifyEmail";
|
||||
import { createOrUpdateMemberships } from "@calcom/features/auth/signup/utils/createOrUpdateMemberships";
|
||||
import { prefillAvatar } from "@calcom/features/auth/signup/utils/prefillAvatar";
|
||||
import { checkIfEmailInWatchlistController } from "@calcom/features/watchlist/operations/check-if-email-in-watchlist.controller";
|
||||
import { checkIfEmailIsBlockedInWatchlistController } from "@calcom/features/watchlist/operations/check-if-email-in-watchlist.controller";
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { getLocaleFromRequest } from "@calcom/lib/getLocaleFromRequest";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
@@ -39,7 +39,7 @@ async function handler(req: RequestWithUsernameStatus, res: NextApiResponse) {
|
||||
})
|
||||
.parse(req.body);
|
||||
|
||||
const shouldLockByDefault = await checkIfEmailInWatchlistController(_email);
|
||||
const shouldLockByDefault = await checkIfEmailIsBlockedInWatchlistController(_email);
|
||||
|
||||
log.debug("handler", { email: _email });
|
||||
|
||||
|
||||
@@ -759,12 +759,13 @@ async function handler(
|
||||
const tOrganizer = await getTranslation(organizerUser?.locale ?? "en", "common");
|
||||
const allCredentials = await getAllCredentials(organizerUser, eventType);
|
||||
|
||||
const { userReschedulingIsOwner, isConfirmedByDefault } = getRequiresConfirmationFlags({
|
||||
const { userReschedulingIsOwner, isConfirmedByDefault } = await getRequiresConfirmationFlags({
|
||||
eventType,
|
||||
bookingStartTime: reqBody.start,
|
||||
userId,
|
||||
originalRescheduledBookingOrganizerId: originalRescheduledBooking?.user?.id,
|
||||
paymentAppData,
|
||||
bookerEmail,
|
||||
});
|
||||
|
||||
// If the Organizer himself is rescheduling, the booker should be sent the communication in his timezone and locale.
|
||||
|
||||
@@ -56,6 +56,7 @@ export const getEventTypesFromDB = async (eventTypeId: number) => {
|
||||
periodCountCalendarDays: true,
|
||||
lockTimeZoneToggleOnBookingPage: true,
|
||||
requiresConfirmation: true,
|
||||
requiresConfirmationForFreeEmail: true,
|
||||
requiresBookerEmailVerification: true,
|
||||
maxLeadThreshold: true,
|
||||
minimumBookingNotice: true,
|
||||
|
||||
@@ -1,24 +1,30 @@
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { checkIfFreeEmailDomain } from "@calcom/lib/freeEmailDomainCheck/checkIfFreeEmailDomain";
|
||||
|
||||
import type { getEventTypeResponse } from "./getEventTypesFromDB";
|
||||
|
||||
type EventType = Pick<getEventTypeResponse, "metadata" | "requiresConfirmation">;
|
||||
type EventType = Pick<
|
||||
getEventTypeResponse,
|
||||
"metadata" | "requiresConfirmation" | "requiresConfirmationForFreeEmail"
|
||||
>;
|
||||
type PaymentAppData = { price: number };
|
||||
|
||||
export function getRequiresConfirmationFlags({
|
||||
export async function getRequiresConfirmationFlags({
|
||||
eventType,
|
||||
bookingStartTime,
|
||||
userId,
|
||||
paymentAppData,
|
||||
originalRescheduledBookingOrganizerId,
|
||||
bookerEmail,
|
||||
}: {
|
||||
eventType: EventType;
|
||||
bookingStartTime: string;
|
||||
userId: number | undefined;
|
||||
paymentAppData: PaymentAppData;
|
||||
originalRescheduledBookingOrganizerId: number | undefined;
|
||||
bookerEmail: string;
|
||||
}) {
|
||||
const requiresConfirmation = determineRequiresConfirmation(eventType, bookingStartTime);
|
||||
const requiresConfirmation = await determineRequiresConfirmation(eventType, bookingStartTime, bookerEmail);
|
||||
const userReschedulingIsOwner = isUserReschedulingOwner(userId, originalRescheduledBookingOrganizerId);
|
||||
const isConfirmedByDefault = determineIsConfirmedByDefault(
|
||||
requiresConfirmation,
|
||||
@@ -38,9 +44,18 @@ export function getRequiresConfirmationFlags({
|
||||
};
|
||||
}
|
||||
|
||||
function determineRequiresConfirmation(eventType: EventType, bookingStartTime: string): boolean {
|
||||
async function determineRequiresConfirmation(
|
||||
eventType: EventType,
|
||||
bookingStartTime: string,
|
||||
bookerEmail: string
|
||||
): Promise<boolean> {
|
||||
let requiresConfirmation = eventType?.requiresConfirmation;
|
||||
const rcThreshold = eventType?.metadata?.requiresConfirmationThreshold;
|
||||
const requiresConfirmationForFreeEmail = eventType?.requiresConfirmationForFreeEmail;
|
||||
|
||||
if (requiresConfirmationForFreeEmail) {
|
||||
requiresConfirmation = await checkIfFreeEmailDomain(bookerEmail);
|
||||
}
|
||||
|
||||
if (rcThreshold) {
|
||||
const timeDifference = dayjs(dayjs(bookingStartTime).utc().format()).diff(dayjs(), rcThreshold.unit);
|
||||
|
||||
+16
@@ -72,6 +72,7 @@ export default function RequiresConfirmationController({
|
||||
);
|
||||
|
||||
const requiresConfirmationWillBlockSlot = formMethods.getValues("requiresConfirmationWillBlockSlot");
|
||||
const requiresConfirmationForFreeEmail = formMethods.getValues("requiresConfirmationForFreeEmail");
|
||||
|
||||
return (
|
||||
<div className="block items-start sm:flex">
|
||||
@@ -241,6 +242,21 @@ export default function RequiresConfirmationController({
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<CheckboxField
|
||||
checked={requiresConfirmationForFreeEmail}
|
||||
descriptionAsLabel
|
||||
description={t("require_confirmation_for_free_email")}
|
||||
className={customClassNames?.conditionalConfirmationRadio?.checkbox}
|
||||
descriptionClassName={
|
||||
customClassNames?.conditionalConfirmationRadio?.checkboxDescription
|
||||
}
|
||||
onChange={(e) => {
|
||||
// We set should dirty to properly detect when we can submit the form
|
||||
formMethods.setValue("requiresConfirmationForFreeEmail", e.target.checked, {
|
||||
shouldDirty: true,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -81,6 +81,7 @@ export type FormValues = {
|
||||
lockTimeZoneToggleOnBookingPage: boolean;
|
||||
requiresConfirmation: boolean;
|
||||
requiresConfirmationWillBlockSlot: boolean;
|
||||
requiresConfirmationForFreeEmail: boolean;
|
||||
requiresBookerEmailVerification: boolean;
|
||||
recurringEvent: RecurringEvent | null;
|
||||
schedulingType: SchedulingType | null;
|
||||
|
||||
@@ -21,13 +21,13 @@ function presenter(watchlistedEmail: Watchlist | null) {
|
||||
* to the specific use cases. Controllers orchestrate Use Cases. They don't implement any
|
||||
* logic, but define the whole operations using use cases.
|
||||
*/
|
||||
export async function checkIfEmailInWatchlistController(
|
||||
export async function checkIfEmailIsBlockedInWatchlistController(
|
||||
email: string
|
||||
): Promise<ReturnType<typeof presenter>> {
|
||||
return await startSpan({ name: "checkIfEmailInWatchlist Controller" }, async () => {
|
||||
const lowercasedEmail = email.toLowerCase();
|
||||
const watchlistRepository = new WatchlistRepository();
|
||||
const watchlistedEmail = await watchlistRepository.getEmailInWatchlist(lowercasedEmail);
|
||||
const watchlistedEmail = await watchlistRepository.getBlockedEmailInWatchlist(lowercasedEmail);
|
||||
return presenter(watchlistedEmail);
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Watchlist } from "./watchlist.model";
|
||||
|
||||
export interface IWatchlistRepository {
|
||||
getEmailInWatchlist(email: string): Promise<Watchlist | null>;
|
||||
getBlockedEmailInWatchlist(email: string): Promise<Watchlist | null>;
|
||||
}
|
||||
@@ -1,16 +1,17 @@
|
||||
import { captureException } from "@sentry/nextjs";
|
||||
|
||||
import db from "@calcom/prisma";
|
||||
import { WatchlistType } from "@calcom/prisma/enums";
|
||||
import { WatchlistType, WatchlistSeverity } from "@calcom/prisma/enums";
|
||||
|
||||
import type { IWatchlistRepository } from "./watchlist.repository.interface";
|
||||
|
||||
export class WatchlistRepository implements IWatchlistRepository {
|
||||
async getEmailInWatchlist(email: string) {
|
||||
async getBlockedEmailInWatchlist(email: string) {
|
||||
const [, domain] = email.split("@");
|
||||
try {
|
||||
const emailInWatchlist = await db.watchlist.findFirst({
|
||||
where: {
|
||||
severity: WatchlistSeverity.CRITICAL,
|
||||
OR: [
|
||||
{ type: WatchlistType.EMAIL, value: email },
|
||||
{ type: WatchlistType.DOMAIN, value: domain },
|
||||
@@ -23,4 +24,19 @@ export class WatchlistRepository implements IWatchlistRepository {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async getFreeEmailDomainInWatchlist(emailDomain: string) {
|
||||
try {
|
||||
const domainInWatchWatchlist = await db.watchlist.findFirst({
|
||||
where: {
|
||||
type: WatchlistType.DOMAIN,
|
||||
value: emailDomain,
|
||||
},
|
||||
});
|
||||
return domainInWatchWatchlist;
|
||||
} catch (err) {
|
||||
captureException(err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user