Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: upgrade ignore domains schema

Marc Seitza904841df7c3
diff --git a/pages/api/jobs/send-notification.ts b/pages/api/jobs/send-notification.ts
index 9cc9ec89..d9df9b26 100644
--- a/pages/api/jobs/send-notification.ts
+++ b/pages/api/jobs/send-notification.ts
@@ -57,6 +57,7 @@ export default async function handle(
} | null;
team: {
plan: string | null;
+ ignoredDomains: string[] | null;
} | null;
} | null;
@@ -93,6 +94,7 @@ export default async function handle(
team: {
select: {
plan: true,
+ ignoredDomains: true,
},
},
},
@@ -118,22 +120,18 @@ export default async function handle(
: view.dataroom!.teamId!;
if (view.viewerEmail) {
- const viewerDomain = view.viewerEmail.split('@').pop();
+ const viewerDomain = view.viewerEmail.split("@").pop();
if (viewerDomain) {
- const ignoredDomainRecord = await prisma.ignoredDomain.findFirst({
- where: {
- teamId,
- },
- select: {
- domains: true,
- },
- });
-
- if (ignoredDomainRecord?.domains) {
- const ignoredDomainList = ignoredDomainRecord.domains.map(d => d.startsWith('@') ? d.substring(1) : d);
+ if (view?.team?.ignoredDomains) {
+ const ignoredDomainList = view.team.ignoredDomains.map((d) =>
+ d.startsWith("@") ? d.substring(1) : d,
+ );
if (ignoredDomainList.includes(viewerDomain)) {
- return res.status(200).json({ message: "Notification skipped for ignored domain.", viewId });
+ return res.status(200).json({
+ message: "Notification skipped for ignored domain.",
+ viewId,
+ });
}
}
}
diff --git a/pages/api/teams/[teamId]/ignored-domains.ts b/pages/api/teams/[teamId]/ignored-domains.ts
index 90e11e8a..937709a6 100644
--- a/pages/api/teams/[teamId]/ignored-domains.ts
+++ b/pages/api/teams/[teamId]/ignored-domains.ts
@@ -1,94 +1,84 @@
import { NextApiRequest, NextApiResponse } from "next";
+
import { getServerSession } from "next-auth";
import prisma from "@/lib/prisma";
import { CustomUser } from "@/lib/types";
import { sanitizeList } from "@/lib/utils";
+
import { authOptions } from "../../auth/[...nextauth]";
async function handler(req: NextApiRequest, res: NextApiResponse) {
- const session = await getServerSession(req, res, authOptions);
- if (!session) {
- return res.status(401).json({ error: "Unauthorized" });
- }
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ return res.status(401).json({ error: "Unauthorized" });
+ }
+
+ const { teamId } = req.query;
+
+ if (typeof teamId !== "string") {
+ return res.status(400).json({ error: "Invalid teamId" });
+ }
+
+ const team = await prisma.team.findFirst({
+ where: {
+ id: teamId,
+ users: {
+ some: {
+ userId: (session.user as CustomUser).id,
+ },
+ },
+ },
+ include: {
+ users: true,
+ },
+ });
- const { teamId } = req.query;
+ if (!team) {
+ return res.status(404).json({ error: "Team not found" });
+ }
- if (typeof teamId !== "string") {
- return res.status(400).json({ error: "Invalid teamId" });
- }
+ const isUserAdmin = team.users.some(
+ (user) =>
+ user.role === "ADMIN" && user.userId === (session.user as CustomUser).id,
+ );
- const team = await prisma.team.findFirst({
- where: {
- id: teamId,
- users: {
- some: {
- userId: (session.user as CustomUser).id,
- },
- },
- },
- include: {
- users: true,
- },
- });
+ if (!isUserAdmin) {
+ return res.status(403).json({ error: "Forbidden" });
+ }
- if (!team) {
- return res.status(404).json({ error: "Team not found" });
- }
+ if (req.method === "GET") {
+ return res.status(200).json(team.ignoredDomains || []);
+ }
- const isUserAdmin = team.users.some(
- (user) =>
- user.role === "ADMIN" &&
- user.userId === (session.user as CustomUser).id,
- );
+ if (req.method === "PUT") {
+ try {
+ const { domains } = req.body;
- if (!isUserAdmin) {
- return res.status(403).json({ error: "Forbidden" });
- }
+ if (!Array.isArray(domains)) {
+ return res.status(400).json({ error: "Invalid domains list" });
+ }
- if (req.method === "GET") {
- try {
- const ignoredDomainRecord = await prisma.ignoredDomain.findFirst({
- where: {
- teamId,
- },
- });
- return res.status(200).json(ignoredDomainRecord?.domains || []);
- } catch (error) {
- console.error(error);
- return res.status(500).json({ error: "Internal server error" });
- }
- }
+ const uniqueDomains = sanitizeList(domains.join("\n"), "domain");
+
+ await prisma.team.update({
+ where: {
+ id: teamId,
+ },
+ data: {
+ ignoredDomains: uniqueDomains,
+ },
+ });
- if (req.method === "PUT") {
- try {
- const { domains } = req.body;
-
- if (!Array.isArray(domains)) {
- return res.status(400).json({ error: "Invalid domains list" });
- }
-
- const uniqueDomains = sanitizeList(domains.join("\n"), "domain");
-
- await prisma.$transaction([
- prisma.ignoredDomain.deleteMany({ where: { teamId } }),
- prisma.ignoredDomain.create({
- data: {
- teamId,
- domains: uniqueDomains,
- },
- }),
- ]);
-
- return res.status(200).json({ message: "Ignored domains updated" });
- } catch (error) {
- console.error(error);
- return res.status(500).json({ error: "Internal server error" });
- }
+ return res.status(200).json({ message: "Ignored domains updated" });
+ } catch (error) {
+ console.error(error);
+ return res.status(500).json({ error: "Internal server error" });
}
+ }
- res.setHeader("Allow", ["GET", "PUT"]);
- return res.status(405).json({ error: `Method ${req.method} not allowed` });
+ res.setHeader("Allow", ["GET", "PUT"]);
+ return res.status(405).json({ error: `Method ${req.method} not allowed` });
}
-export default handler;
\ No newline at end of file
+export default handler;
diff --git a/prisma/migrations/20250709184916_add_ignored_domain_table/migration.sql b/prisma/migrations/20250709184916_add_ignored_domain_table/migration.sql
deleted file mode 100644
index b515870c..00000000
--- a/prisma/migrations/20250709184916_add_ignored_domain_table/migration.sql
+++ /dev/null
@@ -1,19 +0,0 @@
--- DropIndex
-DROP INDEX "Viewer_teamId_createdAt_idx";
-
--- CreateTable
-CREATE TABLE "IgnoredDomain" (
- "id" TEXT NOT NULL,
- "domains" TEXT[] DEFAULT ARRAY[]::TEXT[],
- "teamId" TEXT NOT NULL,
- "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
- "updatedAt" TIMESTAMP(3) NOT NULL,
-
- CONSTRAINT "IgnoredDomain_pkey" PRIMARY KEY ("id")
-);
-
--- CreateIndex
-CREATE INDEX "IgnoredDomain_teamId_idx" ON "IgnoredDomain"("teamId");
-
--- AddForeignKey
-ALTER TABLE "IgnoredDomain" ADD CONSTRAINT "IgnoredDomain_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
diff --git a/prisma/migrations/20250711000000_add_ignored_domains_to_team/migration.sql b/prisma/migrations/20250711000000_add_ignored_domains_to_team/migration.sql
new file mode 100644
index 00000000..b9b1df74
--- /dev/null
+++ b/prisma/migrations/20250711000000_add_ignored_domains_to_team/migration.sql
@@ -0,0 +1,6 @@
+-- DropIndex
+DROP INDEX IF EXISTS "Viewer_teamId_createdAt_idx";
+
+-- AlterTable
+ALTER TABLE "Team" ADD COLUMN "ignoredDomains" TEXT[];
+
diff --git a/prisma/schema/schema.prisma b/prisma/schema/schema.prisma
index dd6ae5ed..a1953c22 100644
--- a/prisma/schema/schema.prisma
+++ b/prisma/schema/schema.prisma
@@ -109,20 +109,9 @@ model Team {
updatedAt DateTime @updatedAt
Tag Tag[]
- ignoredDomains IgnoredDomain[]
+ ignoredDomains String[] // Domains that are ignored for the team
}
-model IgnoredDomain {
- id String @id @default(cuid())
- domains String[] @default([])
- team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
- teamId String
-
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
-
- @@index([teamId])
-}
model Brand {
id String @id @default(cuid())