Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: exclude deleted links
Marc Seitzbad06cef46b5
diff --git a/pages/api/links/[id]/annotations.ts b/pages/api/links/[id]/annotations.tsindex b2ba99fd..3a049c75 100644--- a/pages/api/links/[id]/annotations.ts+++ b/pages/api/links/[id]/annotations.ts@@ -45,6 +45,10 @@ export default async function handle(return res.status(404).json({ error: "Annotation not found" });}+ if (view.link.deletedAt) {+ return res.status(404).json({ error: "Link deleted" });+ }+if (view.viewedAt < new Date(Date.now() - 1000 * 60 * 60 * 23)) {// if view is older than 23 hours, we should not allow the annotations to be accessedreturn res.status(404).json({ error: "Annotation not found" });diff --git a/pages/api/links/[id]/documents/[documentId]/annotations.ts b/pages/api/links/[id]/documents/[documentId]/annotations.tsindex 549c1848..7c9b8d57 100644--- a/pages/api/links/[id]/documents/[documentId]/annotations.ts+++ b/pages/api/links/[id]/documents/[documentId]/annotations.ts@@ -37,6 +37,7 @@ export default async function handle(teamId: true,documentId: true,dataroomId: true,+ deletedAt: true,},},},@@ -46,6 +47,10 @@ export default async function handle(return res.status(404).json({ error: "View not found" });}+ if (view.link.deletedAt) {+ return res.status(404).json({ error: "Link deleted" });+ }+// Check TTL - deny access for views older than 23 hoursif (view.viewedAt < new Date(Date.now() - 23 * 60 * 60 * 1000)) {return res.status(403).json({ error: "Access denied" });diff --git a/pages/api/links/[id]/visits.ts b/pages/api/links/[id]/visits.tsindex 136f91ae..66fdaab2 100644--- a/pages/api/links/[id]/visits.ts+++ b/pages/api/links/[id]/visits.ts@@ -35,6 +35,7 @@ export default async function handle(id: id,},select: {+ deletedAt: true,document: {select: {id: true,@@ -57,7 +58,7 @@ export default async function handle(});// If link doesn't exist (deleted), return empty array- if (!result || !result.document) {+ if (!result || !result.document || result.deletedAt) {return res.status(200).json([]);}diff --git a/pages/api/links/domains/[...domainSlug].ts b/pages/api/links/domains/[...domainSlug].tsindex 70db5f5a..96594055 100644--- a/pages/api/links/domains/[...domainSlug].ts+++ b/pages/api/links/domains/[...domainSlug].ts@@ -114,17 +114,17 @@ export default async function handle(});}- if (link.deletedAt) {+ if (link.isArchived) {return res.status(404).json({- error: "Link has been deleted",- message: "This link has been deleted",+ error: "Link is archived",+ message: "link is archived",});}- if (link.isArchived) {+ if (link.deletedAt) {return res.status(404).json({- error: "Link is archived",- message: "link is archived",+ error: "Link has been deleted",+ message: "This link has been deleted",});}diff --git a/pages/api/links/download/bulk.ts b/pages/api/links/download/bulk.tsindex 92df59cf..dc3362a4 100644--- a/pages/api/links/download/bulk.ts+++ b/pages/api/links/download/bulk.ts@@ -38,6 +38,7 @@ export default async function handle(allowDownload: true,expiresAt: true,isArchived: true,+ deletedAt: true,enableWatermark: true,watermarkConfig: true,name: true,@@ -100,6 +101,10 @@ export default async function handle(return res.status(403).json({ error: "Error downloading" });}+ if (view.link.deletedAt) {+ return res.status(403).json({ error: "Error downloading" });+ }+// if link is expired, we should not allow the downloadif (view.link.expiresAt && view.link.expiresAt < new Date()) {return res.status(403).json({ error: "Error downloading" });diff --git a/pages/api/links/download/dataroom-document.ts b/pages/api/links/download/dataroom-document.tsindex 7e86e4e9..774d9f89 100644--- a/pages/api/links/download/dataroom-document.ts+++ b/pages/api/links/download/dataroom-document.ts@@ -43,6 +43,7 @@ export default async function handle(allowDownload: true,expiresAt: true,isArchived: true,+ deletedAt: true,enableWatermark: true,watermarkConfig: true,name: true,@@ -99,6 +100,11 @@ export default async function handle(return res.status(403).json({ error: "Error downloading" });}+ // if link is deleted, we should not allow the download+ if (view.link.deletedAt) {+ return res.status(403).json({ error: "Error downloading" });+ }+// if link is expired, we should not allow the downloadif (view.link.expiresAt && view.link.expiresAt < new Date()) {return res.status(403).json({ error: "Error downloading" });diff --git a/pages/api/links/download/dataroom-folder.ts b/pages/api/links/download/dataroom-folder.tsindex 885319a0..abc15c03 100644--- a/pages/api/links/download/dataroom-folder.ts+++ b/pages/api/links/download/dataroom-folder.ts@@ -52,6 +52,7 @@ export default async function handler(allowDownload: true,expiresAt: true,isArchived: true,+ deletedAt: true,enableWatermark: true,watermarkConfig: true,name: true,@@ -77,6 +78,11 @@ export default async function handler(return res.status(403).json({ error: "Error downloading" });}+ // if link is deleted, we should not allow the download+ if (view.link.deletedAt) {+ return res.status(403).json({ error: "Error downloading" });+ }+// if link is expired, we should not allow the downloadif (view.link.expiresAt && view.link.expiresAt < new Date()) {return res.status(403).json({ error: "Error downloading" });diff --git a/pages/api/links/download/index.ts b/pages/api/links/download/index.tsindex 29e470e7..f0e6ab73 100644--- a/pages/api/links/download/index.ts+++ b/pages/api/links/download/index.ts@@ -32,6 +32,7 @@ export default async function handle(allowDownload: true,expiresAt: true,isArchived: true,+ deletedAt: true,enableWatermark: true,watermarkConfig: true,name: true,@@ -75,6 +76,11 @@ export default async function handle(return res.status(403).json({ error: "Error downloading" });}+ // if link is deleted, we should not allow the download+ if (view.link.deletedAt) {+ return res.status(403).json({ error: "Error downloading" });+ }+// if link is expired, we should not allow the downloadif (view.link.expiresAt && view.link.expiresAt < new Date()) {return res.status(403).json({ error: "Error downloading" });diff --git a/pages/api/links/generate-index.ts b/pages/api/links/generate-index.tsindex bb579f62..e107df91 100644--- a/pages/api/links/generate-index.ts+++ b/pages/api/links/generate-index.ts@@ -55,6 +55,7 @@ export default async function handle(updatedAt: true,teamId: true,isArchived: true,+ deletedAt: true,domainId: true,domainSlug: true,groupId: true,@@ -114,6 +115,10 @@ export default async function handle(return res.status(404).json({ error: "Link archived" });}+ if (link.deletedAt) {+ return res.status(404).json({ error: "Link deleted" });+ }+// Check if the link is a group link and remove the folder/documents from the dataroom if not part of the group permissionsif (link.groupId) {const groupAccessControls =diff --git a/pages/api/revalidate.ts b/pages/api/revalidate.tsindex de74cbfb..510cb2da 100644--- a/pages/api/revalidate.ts+++ b/pages/api/revalidate.ts@@ -79,6 +79,7 @@ export default async function handler(links: {where: {isArchived: false,+ deletedAt: null,domainId: null,},select: {diff --git a/pages/api/teams/[teamId]/agreements/index.ts b/pages/api/teams/[teamId]/agreements/index.tsindex f11bd7c3..7fbd1826 100644--- a/pages/api/teams/[teamId]/agreements/index.ts+++ b/pages/api/teams/[teamId]/agreements/index.ts@@ -51,7 +51,11 @@ export default async function handle(include: {_count: {select: {- links: true,+ links: {+ where: {+ deletedAt: null,+ },+ },},},},diff --git a/pages/api/teams/[teamId]/datarooms/[id]/permission-groups/index.ts b/pages/api/teams/[teamId]/datarooms/[id]/permission-groups/index.tsindex c3b0392a..78bc1274 100644--- a/pages/api/teams/[teamId]/datarooms/[id]/permission-groups/index.ts+++ b/pages/api/teams/[teamId]/datarooms/[id]/permission-groups/index.ts@@ -75,6 +75,7 @@ export default async function handle(prisma.link.findMany({where: {permissionGroupId: { in: groupIds },+ deletedAt: null,},select: {id: true,diff --git a/pages/api/teams/[teamId]/datarooms/index.ts b/pages/api/teams/[teamId]/datarooms/index.tsindex 2578670f..ea086171 100644--- a/pages/api/teams/[teamId]/datarooms/index.ts+++ b/pages/api/teams/[teamId]/datarooms/index.ts@@ -52,6 +52,7 @@ export default async function handle(links: {where: {linkType: "DATAROOM_LINK",+ deletedAt: null,},orderBy: {createdAt: "desc",diff --git a/pages/api/teams/[teamId]/documents/index.ts b/pages/api/teams/[teamId]/documents/index.tsindex 4b0b8c71..5f300d3a 100644--- a/pages/api/teams/[teamId]/documents/index.ts+++ b/pages/api/teams/[teamId]/documents/index.ts@@ -136,6 +136,7 @@ export default async function handle(by: ["documentId"],where: {documentId: { in: documentIds },+ deletedAt: null,},_count: { id: true },}),diff --git a/pages/api/teams/[teamId]/documents/search.ts b/pages/api/teams/[teamId]/documents/search.tsindex 69bd0018..cb82e671 100644--- a/pages/api/teams/[teamId]/documents/search.ts+++ b/pages/api/teams/[teamId]/documents/search.ts@@ -56,6 +56,7 @@ export default async function handle(by: ["documentId"],where: {documentId: { in: documentIds },+ deletedAt: null,},_count: { id: true },}),diff --git a/pages/view/[linkId]/chat.tsx b/pages/view/[linkId]/chat.tsxindex 2be915e4..c52cfc42 100644--- a/pages/view/[linkId]/chat.tsx+++ b/pages/view/[linkId]/chat.tsx@@ -7,15 +7,15 @@ import { type Message } from "ai/react";import { getServerSession } from "next-auth";import { usePlausible } from "next-plausible";-import { Chat } from "@/components/chat/chat";-import Sparkle from "@/components/shared/icons/sparkle";-import { Button } from "@/components/ui/button";-import { getFile } from "@/lib/files/get-file";import prisma from "@/lib/prisma";import { usePlan } from "@/lib/swr/use-billing";import { CustomUser } from "@/lib/types";+import { Chat } from "@/components/chat/chat";+import Sparkle from "@/components/shared/icons/sparkle";+import { Button } from "@/components/ui/button";+export const getServerSideProps = async (context: any) => {const { linkId } = context.params;const session = await getServerSession(context.req, context.res, authOptions);@@ -30,7 +30,7 @@ export const getServerSideProps = async (context: any) => {}const link = await prisma.link.findUnique({- where: { id: linkId },+ where: { id: linkId, deletedAt: null },select: {document: {select: {