feat: Add spam blocker DI structure (#24040)

* --init

* --

* replace old structure with new DI

* fix type

* --

* moving stuff around

* moving stuff around again

* minor clean up

* --

* resolve conflict

* clea up

* old schema clean up

* further clean up

* removing unwanted merged responsibilities

* --

* improve DI and SOLID

* some type fixes

* --1

* clean up --cont

* fix DI in facade for test

* more fix

* fix

* checking

* o.o

* fix import

* fix failing test --2

* fix failing test --3

* fix failing test --4

* normalization use

* introduce facade container injection

* uniform async telemetry spans

* further improvements

* replace prismock with repo mocks

* ensure we don't pass prisma outside of repo

* fix import

* remove try catch from repo calls

* async await fixes

* using deps pattern

* more clean up and fixes

* more clean up

* address feedback --1

* separation of concern

* clean up

* test clean up

* feedback --2

* remove extra fetch

* remove await

* migrate _post test from prismock

* fix type

* --

* fix tokens path

* rename AuditRepo

* test --1

* update _post to integration test

* fix test

* fix test

* test fix maybe?

* --

* feedback

* feedback

* fixes

* more feedback

* NIT

* use sentry and logger imports as planned

* assertion in test

* add missing test case

* add tests for controllers and services

* NITs

* fix domain normalisation
This commit is contained in:
Syed Ali Shahbaz authored and GitHub committed 2025-10-14 10:16:18 +03:00
1 parent 52ecea964d
commit a2bee76da6
60 files changed
+3599 -461

No files matched your search

+11 -4
View File
@@ -7,13 +7,14 @@ import {
sendChangeOfEmailVerificationLink,
} from "@calcom/emails/email-manager";
import { FeaturesRepository } from "@calcom/features/flags/features.repository";
import { sentrySpan } from "@calcom/features/watchlist/lib/telemetry";
import { checkIfEmailIsBlockedInWatchlistController } from "@calcom/features/watchlist/operations/check-if-email-in-watchlist.controller";
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
import { WEBAPP_URL } from "@calcom/lib/constants";
import logger from "@calcom/lib/logger";
import { hashEmail } from "@calcom/lib/server/PiiHasher";
import { getTranslation } from "@calcom/lib/server/i18n";
import { prisma } from "@calcom/prisma";
import { hashEmail } from "@calcom/lib/server/PiiHasher";
const log = logger.getSubLogger({ prefix: [`[[Auth] `] });
@@ -43,7 +44,7 @@ export const sendEmailVerification = async ({
return { ok: true, skipped: true };
}
if (await checkIfEmailIsBlockedInWatchlistController(email)) {
if (await checkIfEmailIsBlockedInWatchlistController({ email, organizationId: null, span: sentrySpan })) {
log.warn("Email is blocked - not sending verification email", email);
return { ok: false, skipped: false };
}
@@ -90,7 +91,7 @@ export const sendEmailVerificationByCode = async ({
username,
isVerifyingEmail,
}: VerifyEmailType) => {
if (await checkIfEmailIsBlockedInWatchlistController(email)) {
if (await checkIfEmailIsBlockedInWatchlistController({ email, organizationId: null, span: sentrySpan })) {
log.warn("Email is blocked - not sending verification email", email);
return { ok: false, skipped: false };
}
@@ -136,7 +137,13 @@ export const sendChangeOfEmailVerification = async ({ user, language }: ChangeOf
return { ok: true, skipped: true };
}
if (await checkIfEmailIsBlockedInWatchlistController(user.emailFrom)) {
if (
await checkIfEmailIsBlockedInWatchlistController({
email: user.emailFrom,
organizationId: null,
span: sentrySpan,
})
) {
log.warn("Email is blocked - not sending verification email", user.emailFrom);
return { ok: false, skipped: false };
}
@@ -7,6 +7,7 @@ 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 { StripeBillingService } from "@calcom/features/ee/billing/stripe-billling-service";
import { sentrySpan } from "@calcom/features/watchlist/lib/telemetry";
import { checkIfEmailIsBlockedInWatchlistController } from "@calcom/features/watchlist/operations/check-if-email-in-watchlist.controller";
import { hashPassword } from "@calcom/lib/auth/hashPassword";
import { WEBAPP_URL } from "@calcom/lib/constants";
@@ -45,7 +46,11 @@ const handler: CustomNextApiHandler = async (body, usernameStatus) => {
const billingService = new StripeBillingService();
const shouldLockByDefault = await checkIfEmailIsBlockedInWatchlistController(_email);
const shouldLockByDefault = await checkIfEmailIsBlockedInWatchlistController({
email: _email,
organizationId: null,
span: sentrySpan,
});
log.debug("handler", { email: _email });