Skip to content

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

feat: add block list

Marc Seitz7c0b3a2e9bb6
diff --git a/pages/api/links/[id]/documents/[documentId].ts b/pages/api/links/[id]/documents/[documentId].ts
index 3ce3daa9..31c9f8d8 100644
--- a/pages/api/links/[id]/documents/[documentId].ts
+++ b/pages/api/links/[id]/documents/[documentId].ts
@@ -5,7 +5,6 @@ import { DataroomBrand, LinkAudienceType } from "@prisma/client";
import { fetchDataroomDocumentLinkData } from "@/lib/api/links/link-data";
import { errorhandler } from "@/lib/errorHandler";
import prisma from "@/lib/prisma";
-import { validateEmail } from "@/lib/utils/validate-email";
import { checkGlobalBlockList } from "@/lib/utils/global-block-list";
export default async function handle(
@@ -92,16 +91,15 @@ export default async function handle(
}
const { email } = req.query as { email?: string };
- const globalBlockCheck = checkGlobalBlockList(email, link.team?.globalBlockList);
+ const globalBlockCheck = checkGlobalBlockList(
+ email,
+ link.team?.globalBlockList,
+ );
if (globalBlockCheck.error) {
- return res.status(400).json(
- { message: globalBlockCheck.error },
- );
+ return res.status(400).json({ message: globalBlockCheck.error });
}
if (globalBlockCheck.isBlocked) {
- return res.status(403).json(
- { message: "Access denied" },
- );
+ return res.status(403).json({ message: "Access denied" });
}
let brand: Partial<DataroomBrand> | null = null;
diff --git a/pages/api/links/[id]/index.ts b/pages/api/links/[id]/index.ts
index ba2aa132..4eb7425b 100644
--- a/pages/api/links/[id]/index.ts
+++ b/pages/api/links/[id]/index.ts
@@ -13,6 +13,7 @@ import {
decryptEncrpytedPassword,
generateEncrpytedPassword,
} from "@/lib/utils";
+import { checkGlobalBlockList } from "@/lib/utils/global-block-list";
import { DomainObject } from "..";
import { authOptions } from "../../auth/[...nextauth]";
@@ -68,6 +69,7 @@ export default async function handle(
team: {
select: {
plan: true,
+ globalBlockList: true,
},
},
customFields: {
@@ -98,6 +100,18 @@ export default async function handle(
return res.status(404).json({ error: "Link is archived" });
}
+ const { email } = req.query as { email?: string };
+ const globalBlockCheck = checkGlobalBlockList(
+ email,
+ link.team?.globalBlockList,
+ );
+ if (globalBlockCheck.error) {
+ return res.status(400).json({ message: globalBlockCheck.error });
+ }
+ if (globalBlockCheck.isBlocked) {
+ return res.status(403).json({ message: "Access denied" });
+ }
+
const linkType = link.linkType;
let brand: Partial<Brand> | Partial<DataroomBrand> | null = null;
diff --git a/pages/api/links/domains/[...domainSlug].ts b/pages/api/links/domains/[...domainSlug].ts
index 8fd86760..37a5310f 100644
--- a/pages/api/links/domains/[...domainSlug].ts
+++ b/pages/api/links/domains/[...domainSlug].ts
@@ -121,16 +121,15 @@ export default async function handle(
}
const { email } = req.query as { email?: string };
- const globalBlockCheck = checkGlobalBlockList(email, link.team?.globalBlockList);
+ const globalBlockCheck = checkGlobalBlockList(
+ email,
+ link.team?.globalBlockList,
+ );
if (globalBlockCheck.error) {
- return res.status(400).json(
- { message: globalBlockCheck.error },
- );
+ return res.status(400).json({ message: globalBlockCheck.error });
}
if (globalBlockCheck.isBlocked) {
- return res.status(403).json(
- { message: "Access denied" },
- );
+ return res.status(403).json({ message: "Access denied" });
}
const teamPlan = link.team?.plan || "free";
diff --git a/pages/api/teams/[teamId]/global-block-list.ts b/pages/api/teams/[teamId]/global-block-list.ts
index d5b8adef..32b38e55 100644
--- a/pages/api/teams/[teamId]/global-block-list.ts
+++ b/pages/api/teams/[teamId]/global-block-list.ts
@@ -9,76 +9,76 @@ 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.globalBlockList || []);
+ }
- const isUserAdmin = team.users.some(
- (user) =>
- user.role === "ADMIN" && user.userId === (session.user as CustomUser).id,
- );
+ if (req.method === "PUT") {
+ try {
+ const { blockList } = req.body;
- if (!isUserAdmin) {
- return res.status(403).json({ error: "Forbidden" });
- }
+ if (!Array.isArray(blockList)) {
+ return res.status(400).json({ error: "Invalid block list" });
+ }
- if (req.method === "GET") {
- return res.status(200).json(team.globalBlockList || []);
- }
+ const uniqueBlockList = sanitizeList(blockList.join("\n"), "both");
+
+ await prisma.team.update({
+ where: {
+ id: teamId,
+ },
+ data: {
+ globalBlockList: uniqueBlockList,
+ },
+ });
- if (req.method === "PUT") {
- try {
- const { blockList } = req.body;
-
- if (!Array.isArray(blockList)) {
- return res.status(400).json({ error: "Invalid block list" });
- }
-
- const uniqueBlockList = sanitizeList(blockList.join("\n"), "both");
-
- await prisma.team.update({
- where: {
- id: teamId,
- },
- data: {
- globalBlockList: uniqueBlockList,
- },
- });
-
- return res.status(200).json({ message: "Global block list updated" });
- } catch (error) {
- console.error(error);
- return res.status(500).json({ error: "Internal server error" });
- }
+ return res.status(200).json({ message: "Global block list 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 not allowed" });
+ res.setHeader("Allow", ["GET", "PUT"]);
+ return res.status(405).json({ error: "Method not allowed" });
}
-export default handler;
\ No newline at end of file
+export default handler;