Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

handle isBlacklistedCancellation

Steven Tey3d435f3b8f21
diff --git a/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-deleted.ts b/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-deleted.ts
index cf9c0ae71c..12899ea1d0 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-deleted.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-deleted.ts
@@ -1,5 +1,6 @@
import { deleteWorkspaceFolders } from "@/lib/api/folders/delete-workspace-folders";
import { tokenCache } from "@/lib/auth/token-cache";
+import { isBlacklistedEmail } from "@/lib/edge-config/is-blacklisted-email";
import { recordLink } from "@/lib/tinybird";
import { redis } from "@/lib/upstash";
import { webhookCache } from "@/lib/webhook/cache";
@@ -73,6 +74,10 @@ export async function customerSubscriptionDeleted(event: Stripe.Event) {
const workspaceLinks = workspace.links;
const workspaceUsers = workspace.users.map(({ user }) => user);
+ const isBlacklistedCancellation = await isBlacklistedEmail(
+ workspaceUsers.filter(({ email }) => email).map(({ email }) => email!),
+ );
+
const pipeline = redis.pipeline();
// remove root domain redirect for all domains from Redis
workspaceLinks.forEach(({ id, domain }) => {
@@ -155,15 +160,22 @@ export async function customerSubscriptionDeleted(event: Stripe.Event) {
url: "",
})),
),
+ // Log the deletion
log({
message:
- ":cry: Workspace *`" + workspace.slug + "`* deleted their subscription",
+ ":cry: Workspace *`" +
+ workspace.slug +
+ "`* deleted their subscription" +
+ (isBlacklistedCancellation ? " (blacklisted / banned)" : ""),
type: "cron",
mention: true,
}),
- sendCancellationFeedback({
- owners: workspaceUsers,
- }),
+
+ // Don't send feedback if the user was blacklisted / banned
+ !isBlacklistedCancellation &&
+ sendCancellationFeedback({
+ owners: workspaceUsers,
+ }),
// Disable the webhooks
prisma.webhook.updateMany({
diff --git a/apps/web/lib/edge-config/is-blacklisted-email.ts b/apps/web/lib/edge-config/is-blacklisted-email.ts
index c0f775151c..52aa985331 100644
--- a/apps/web/lib/edge-config/is-blacklisted-email.ts
+++ b/apps/web/lib/edge-config/is-blacklisted-email.ts
@@ -1,6 +1,6 @@
import { get } from "@vercel/edge-config";
-export const isBlacklistedEmail = async (email: string) => {
+export const isBlacklistedEmail = async (email: string | string[]) => {
if (!process.env.NEXT_PUBLIC_IS_DUB || !process.env.EDGE_CONFIG) {
return false;
}
@@ -12,5 +12,12 @@ export const isBlacklistedEmail = async (email: string) => {
blacklistedEmails = [];
}
if (blacklistedEmails.length === 0) return false;
+
+ if (Array.isArray(email)) {
+ return email.some((e) =>
+ new RegExp(blacklistedEmails.join("|"), "i").test(e),
+ );
+ }
+
return new RegExp(blacklistedEmails.join("|"), "i").test(email);
};