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.

update sidebar usage

Steven Tey4dc7b19ea46f
diff --git a/apps/web/lib/email/email-templates-map.ts b/apps/web/lib/email/email-templates-map.ts
index 674b007fb9..91b8f892de 100644
--- a/apps/web/lib/email/email-templates-map.ts
+++ b/apps/web/lib/email/email-templates-map.ts
@@ -11,6 +11,7 @@ import PartnerPayoutProcessed from "@dub/email/templates/partner-payout-processe
import PartnerRewardUpdated from "@dub/email/templates/partner-reward-updated";
import ProgramPayoutThankYou from "@dub/email/templates/program-payout-thank-you";
import UnresolvedRiskEventsSummary from "@dub/email/templates/unresolved-risk-events-summary";
+import WorkspaceDisabled from "@dub/email/templates/workspace-disabled";
export const EMAIL_TEMPLATES_MAP = {
BountyApproved,
@@ -24,7 +25,7 @@ export const EMAIL_TEMPLATES_MAP = {
UnresolvedRiskEventsSummary,
PartnerGroupChanged,
PartnerRewardUpdated,
-
+ WorkspaceDisabled,
// special broadcast emails
// DubPartnerRewind,
// DubProductUpdateMar26,
diff --git a/apps/web/scripts/misc/disable-workspace-links.ts b/apps/web/scripts/misc/disable-workspace-links.ts
index 96c01fa8df..9101fadbc4 100644
--- a/apps/web/scripts/misc/disable-workspace-links.ts
+++ b/apps/web/scripts/misc/disable-workspace-links.ts
@@ -1,8 +1,7 @@
import { prisma } from "@/lib/prisma";
-import { LEGAL_USER_ID } from "@dub/utils";
import "dotenv-flow/config";
import { linkCache } from "../../lib/api/links/cache";
-import { updateConfig } from "../../lib/edge-config";
+import { queueBatchEmail } from "../../lib/email/queue-batch-email";
// script to disable all links for a workspace
async function main() {
@@ -12,10 +11,17 @@ async function main() {
},
include: {
users: {
+ where: {
+ role: "owner",
+ user: {
+ email: {
+ not: null,
+ },
+ },
+ },
select: {
user: {
select: {
- id: true,
email: true,
},
},
@@ -24,11 +30,6 @@ async function main() {
},
});
- if (project.users.length === 0) {
- console.log("No users found");
- return;
- }
-
while (true) {
const linksToDisable = await prisma.link.findMany({
where: {
@@ -61,37 +62,52 @@ async function main() {
}
}
- const userToBan = project.users[0].user;
+ const owners = project.users.map(({ user }) => user.email);
+
+ if (owners.length > 0) {
+ await queueBatchEmail(
+ owners.map((email) => ({
+ to: email!,
+ variant: "notifications",
+ subject: "Your Dub workspace has been disabled",
+ templateName: "WorkspaceDisabled",
+ templateProps: {
+ email: email!,
+ workspace: {
+ name: project.name,
+ slug: project.slug,
+ usage: project.usage,
+ usageLimit: project.usageLimit,
+ plan: project.plan,
+ },
+ },
+ })),
+ );
+ }
- await prisma.projectUsers.update({
+ const updatedOwners = await prisma.projectUsers.updateMany({
where: {
- userId_projectId: {
- userId: userToBan.id,
- projectId: project.id,
- },
+ projectId: project.id,
+ role: "owner",
},
data: {
- userId: LEGAL_USER_ID,
+ role: "billing",
},
});
- await prisma.project.update({
+ console.log(`Updated ${updatedOwners.count} owners to billing role`);
+
+ const updatedMembers = await prisma.projectUsers.updateMany({
where: {
- id: project.id,
+ projectId: project.id,
+ role: "member",
},
data: {
- name: userToBan.email!,
+ role: "viewer",
},
});
- await updateConfig({
- key: "emails",
- value: userToBan.email!,
- });
-
- console.log(
- `Banned ${userToBan.email}, transfered project ${project.slug} to legal user`,
- );
+ console.log(`Updated ${updatedMembers.count} members to viewer role`);
}
main();
diff --git a/apps/web/scripts/misc/restore-workspace-access.ts b/apps/web/scripts/misc/restore-workspace-access.ts
index 9fc615dced..bd078c0dc9 100644
--- a/apps/web/scripts/misc/restore-workspace-access.ts
+++ b/apps/web/scripts/misc/restore-workspace-access.ts
@@ -1,5 +1,4 @@
import { prisma } from "@/lib/prisma";
-import { LEGAL_USER_ID } from "@dub/utils";
import "dotenv-flow/config";
import { linkCache } from "../../lib/api/links/cache";
@@ -11,12 +10,6 @@ async function main() {
},
});
- const user = await prisma.user.findUniqueOrThrow({
- where: {
- email: project.name,
- },
- });
-
while (true) {
const linksToRestore = await prisma.link.findMany({
where: {
@@ -51,30 +44,29 @@ async function main() {
}
}
- await prisma.projectUsers.update({
+ const updatedOwners = await prisma.projectUsers.updateMany({
where: {
- userId_projectId: {
- userId: LEGAL_USER_ID,
- projectId: project.id,
- },
+ projectId: project.id,
+ role: "billing",
},
data: {
- userId: user.id,
+ role: "owner",
},
});
- await prisma.project.update({
+ console.log(`Reverted ${updatedOwners.count} billing to owner role`);
+
+ const updatedMembers = await prisma.projectUsers.updateMany({
where: {
- id: project.id,
+ projectId: project.id,
+ role: "viewer",
},
data: {
- name: project.slug,
+ role: "member",
},
});
- console.log(
- `Restored access to project ${project.slug} for user ${user.email}`,
- );
+ console.log(`Reverted ${updatedMembers.count} viewers to member role`);
}
main();
diff --git a/apps/web/ui/layout/sidebar/sidebar-usage.tsx b/apps/web/ui/layout/sidebar/sidebar-usage.tsx
index 09c5ed2332..5c3cfb7559 100644
--- a/apps/web/ui/layout/sidebar/sidebar-usage.tsx
+++ b/apps/web/ui/layout/sidebar/sidebar-usage.tsx
@@ -144,7 +144,7 @@ function UsageInner() {
href={`/${slug}/settings/billing`}
>
Usage
- <ChevronRight className="size-2 text-neutral-400 transition-[color,transform] group-hover:translate-x-0.5 group-hover:text-neutral-500" />
+ <ChevronRight className="size-3 text-neutral-400 transition-[color,transform] group-hover:translate-x-0.5 group-hover:text-neutral-500" />
</Link>
)}
diff --git a/packages/email/src/templates/workspace-disabled.tsx b/packages/email/src/templates/workspace-disabled.tsx
new file mode 100644
index 0000000000..349cfbb682
--- /dev/null
+++ b/packages/email/src/templates/workspace-disabled.tsx
@@ -0,0 +1,114 @@
+import { DUB_WORDMARK, capitalize, nFormatter } from "@dub/utils";
+import {
+ Body,
+ Container,
+ Head,
+ Heading,
+ Html,
+ Img,
+ Link,
+ Preview,
+ Section,
+ Tailwind,
+ Text,
+} from "@react-email/components";
+import { Footer } from "../components/footer";
+
+export default function WorkspaceDisabled({
+ email = "[email protected]",
+ workspace = {
+ name: "Acme",
+ slug: "acme",
+ usage: 2_232_432,
+ usageLimit: 1_000,
+ plan: "free",
+ },
+}: {
+ email: string;
+ workspace: {
+ name: string;
+ slug: string;
+ usage: number;
+ usageLimit: number;
+ plan: string;
+ };
+}) {
+ const { slug, name, usage, usageLimit, plan } = workspace as {
+ slug: string;
+ name: string;
+ usage: number;
+ usageLimit: number;
+ plan: string;
+ };
+ const percentage = nFormatter(Math.round((usage / usageLimit) * 100), {
+ full: true,
+ });
+
+ const upgradeUrl = `https://app.dub.co/${slug}/settings/billing/upgrade?plan=advanced&planPeriod=yearly`;
+
+ return (
+ <Html>
+ <Head />
+ <Preview>
+ Your Dub workspace, {name} has used {percentage}% of its events limit
+ and has been disabled.
+ </Preview>
+ <Tailwind>
+ <Body className="mx-auto my-auto bg-white font-sans">
+ <Container className="mx-auto my-10 max-w-[600px] rounded border border-solid border-neutral-200 px-10 py-5">
+ <Section className="mt-8">
+ <Img src={DUB_WORDMARK} height="32" alt="Dub" />
+ </Section>
+ <Heading className="mx-0 my-7 p-0 text-lg font-medium text-black">
+ Your Dub workspace has been disabled
+ </Heading>
+ <Text className="text-sm leading-6 text-black">
+ Your Dub workspace,{" "}
+ <Link
+ href={`https://app.dub.co/${slug}`}
+ className="text-black underline"
+ >
+ <strong>{name}</strong>
+ </Link>{" "}
+ has used <strong>{percentage}%</strong> of the monthly events
+ limit included in the {capitalize(plan)} plan, which is in
+ violation of our{" "}
+ <Link
+ href="https://dub.co/legal/terms"
+ className="font-semibold text-black underline"
+ >
+ fair use policy
+ </Link>
+ . You have used a total of{" "}
+ <strong>{nFormatter(usage, { full: true })} events</strong> (out
+ of a maximum of {nFormatter(usageLimit, { full: true })} events)
+ in your current billing cycle.
+ </Text>
+
+ <Text className="text-sm leading-6 text-black">
+ As a result, all links in your workspace have been disabled. You
+ will need to{" "}
+ <Link
+ href={upgradeUrl}
+ className="font-semibold text-black underline"
+ >
+ upgrade to a yearly Advanced plan
+ </Link>{" "}
+ to re-enable your links.
+ </Text>
+
+ <Section className="mb-8 mt-6">
+ <Link
+ className="w-full rounded-lg bg-black px-6 py-3 text-center text-[12px] font-semibold text-white no-underline"
+ href={upgradeUrl}
+ >
+ Upgrade now
+ </Link>
+ </Section>
+ <Footer email={email} />
+ </Container>
+ </Body>
+ </Tailwind>
+ </Html>
+ );
+}