feat: add signup watchlist review mode (#27912)
* feat: add signup watchlist review feature flag and handler logic - Add 'signup-watchlist-review' global feature flag - Add SIGNUP to WatchlistSource enum in Prisma schema - When flag enabled, lock new signups and add email to watchlist - Show 'account under review' message on signup page - Add i18n strings for review UI - Create seed migration for the feature flag Co-Authored-By: [email protected] <[email protected]> * test: add isAccountUnderReview tests to fetchSignup test suite Co-Authored-By: [email protected] <[email protected]> * fix: address Cubic AI review feedback (confidence >= 9/10) - Remove 'import process from node:process' in signup-view.tsx (P0 bug in 'use client' component) - Move watchlist review check before checkoutSessionId early return in calcomSignupHandler (P1 premium bypass) - Revert selfHostedHandler to original state (out of scope per user request) - Add test mocks for FeaturesRepository and GlobalWatchlistRepository Co-Authored-By: [email protected] <[email protected]> * fix: remove node:process import from useFlags.ts (client-side file) Co-Authored-By: [email protected] <[email protected]> * fix: remove !token condition from watchlist review check Token is present in normal email-verified signups, so the !token condition was incorrectly skipping watchlist review for verified users. Co-Authored-By: [email protected] <[email protected]> * Apply suggestion from @cubic-dev-ai[bot] Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * refactor: move user lock to UserRepository.lockByEmail Co-Authored-By: [email protected] <[email protected]> * refactor: use cached getFeatureRepository() instead of deprecated FeaturesRepository Co-Authored-By: [email protected] <[email protected]> * refactor: remove user locking, keep only watchlist addition on signup review Co-Authored-By: [email protected] <[email protected]> * feat: lock user on signup review, remove watchlist entry on unlock Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
This commit is contained in:
12 files changed
+569
-415
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
|
||||
|
||||
import { SIGNUP_ERROR_CODES } from "../constants";
|
||||
import { fetchSignup, isUserAlreadyExistsError, hasCheckoutSession } from "./fetchSignup";
|
||||
import { fetchSignup, isUserAlreadyExistsError, hasCheckoutSession, isAccountUnderReview } from "./fetchSignup";
|
||||
|
||||
function createJsonResponse(json: unknown, status = 200) {
|
||||
return new Response(JSON.stringify(json), {
|
||||
@@ -101,3 +101,42 @@ describe("hasCheckoutSession", () => {
|
||||
expect(hasCheckoutSession(result)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isAccountUnderReview", () => {
|
||||
it("returns true when accountUnderReview is true in success response", () => {
|
||||
const result = {
|
||||
ok: true as const,
|
||||
data: { message: "Created user", accountUnderReview: true },
|
||||
};
|
||||
|
||||
expect(isAccountUnderReview(result)).toBe(true);
|
||||
});
|
||||
|
||||
it("returns false when accountUnderReview is not set", () => {
|
||||
const result = {
|
||||
ok: true as const,
|
||||
data: { message: "Created user" },
|
||||
};
|
||||
|
||||
expect(isAccountUnderReview(result)).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false when accountUnderReview is false", () => {
|
||||
const result = {
|
||||
ok: true as const,
|
||||
data: { message: "Created user", accountUnderReview: false },
|
||||
};
|
||||
|
||||
expect(isAccountUnderReview(result)).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false for error responses", () => {
|
||||
const result = {
|
||||
ok: false as const,
|
||||
status: 500,
|
||||
error: { message: "Internal error" },
|
||||
};
|
||||
|
||||
expect(isAccountUnderReview(result)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -11,6 +11,7 @@ type SignupData = {
|
||||
type SignupSuccessResponse = {
|
||||
message: string;
|
||||
stripeCustomerId?: string;
|
||||
accountUnderReview?: boolean;
|
||||
};
|
||||
|
||||
type SignupErrorResponse = {
|
||||
@@ -20,9 +21,9 @@ type SignupErrorResponse = {
|
||||
|
||||
type SignupResponse = SignupSuccessResponse | SignupErrorResponse;
|
||||
|
||||
export type SignupResult =
|
||||
| { ok: true; data: SignupSuccessResponse }
|
||||
| { ok: false; status: number; error: SignupErrorResponse };
|
||||
export type SignupSuccessResult = { ok: true; data: SignupSuccessResponse };
|
||||
|
||||
export type SignupResult = SignupSuccessResult | { ok: false; status: number; error: SignupErrorResponse };
|
||||
|
||||
export async function fetchSignup(data: SignupData, cfToken?: string): Promise<SignupResult> {
|
||||
const allParams = new URLSearchParams(window.location.search);
|
||||
@@ -91,3 +92,7 @@ export function hasCheckoutSession(
|
||||
): result is { ok: false; status: number; error: SignupErrorResponse & { checkoutSessionId: string } } {
|
||||
return !result.ok && !!result.error.checkoutSessionId;
|
||||
}
|
||||
|
||||
export function isAccountUnderReview(result: SignupResult): boolean {
|
||||
return result.ok && result.data.accountUnderReview === true;
|
||||
}
|
||||
@@ -38,6 +38,7 @@ export type AppFlags = {
|
||||
"hwm-seating": boolean;
|
||||
"active-user-billing": boolean;
|
||||
"sidebar-tips": boolean;
|
||||
"signup-watchlist-review": boolean;
|
||||
};
|
||||
|
||||
export type TeamFeatures = Record<keyof AppFlags, boolean>;
|
||||
|
||||
@@ -1429,4 +1429,11 @@ export class UserRepository {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async lockByEmail({ email }: { email: string }) {
|
||||
await this.prismaClient.user.updateMany({
|
||||
where: { email },
|
||||
data: { locked: true },
|
||||
});
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
-- Add SIGNUP to WatchlistSource enum
|
||||
ALTER TYPE "WatchlistSource" ADD VALUE IF NOT EXISTS 'SIGNUP';
|
||||
|
||||
-- Seed the signup-watchlist-review feature flag
|
||||
INSERT INTO "Feature" ("slug", "enabled", "type", "description", "createdAt", "updatedAt")
|
||||
VALUES
|
||||
('signup-watchlist-review', false, 'OPERATIONAL', 'When enabled, new signups are added to the watchlist for review', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
||||
ON CONFLICT ("slug") DO NOTHING;
|
||||
@@ -2464,6 +2464,7 @@ enum WatchlistAction {
|
||||
enum WatchlistSource {
|
||||
MANUAL
|
||||
FREE_DOMAIN_POLICY
|
||||
SIGNUP
|
||||
}
|
||||
|
||||
model Watchlist {
|
||||
@@ -3044,7 +3045,7 @@ model TeamBilling {
|
||||
subscriptionEnd DateTime?
|
||||
|
||||
billingPeriod BillingPeriod?
|
||||
billingMode BillingMode @default(SEATS)
|
||||
billingMode BillingMode @default(SEATS)
|
||||
pricePerSeat Int?
|
||||
paidSeats Int?
|
||||
monthlyProrations MonthlyProration[]
|
||||
@@ -3073,7 +3074,7 @@ model OrganizationBilling {
|
||||
subscriptionEnd DateTime?
|
||||
|
||||
billingPeriod BillingPeriod?
|
||||
billingMode BillingMode @default(SEATS)
|
||||
billingMode BillingMode @default(SEATS)
|
||||
pricePerSeat Int?
|
||||
paidSeats Int?
|
||||
monthlyProrations MonthlyProration[]
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { GlobalWatchlistRepository } from "@calcom/features/watchlist/lib/repository/GlobalWatchlistRepository";
|
||||
import { normalizeEmail } from "@calcom/features/watchlist/lib/utils/normalization";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
|
||||
import type { TrpcSessionUser } from "../../../types";
|
||||
@@ -20,12 +22,25 @@ const lockUserAccountHandler = async ({ input }: GetOptions) => {
|
||||
data: {
|
||||
locked,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
email: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new Error("User not found");
|
||||
}
|
||||
|
||||
if (!locked) {
|
||||
const globalWatchlistRepo = new GlobalWatchlistRepository(prisma);
|
||||
const normalizedEmail = normalizeEmail(user.email);
|
||||
const watchlistEntry = await globalWatchlistRepo.findBlockedEmail(normalizedEmail);
|
||||
if (watchlistEntry) {
|
||||
await globalWatchlistRepo.deleteEntry(watchlistEntry.id);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
userId,
|
||||
|
||||
Reference in new issue
Block a user