Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
fix: individual group download
Marc Seitzacbf74a819d1
diff --git a/components/view/dataroom/dataroom-view.tsx b/components/view/dataroom/dataroom-view.tsxindex a4574ff7..ee2b967c 100644--- a/components/view/dataroom/dataroom-view.tsx+++ b/components/view/dataroom/dataroom-view.tsx@@ -69,6 +69,7 @@ export type DEFAULT_DOCUMENT_VIEW_TYPE = {fileType?: string;ipAddress?: string;useAdvancedExcelViewer?: boolean;+ canDownload?: boolean;};export default function DataroomView({@@ -171,6 +172,7 @@ export default function DataroomView({isPreview,ipAddress,useAdvancedExcelViewer,+ canDownload,} = fetchData as DEFAULT_DOCUMENT_VIEW_TYPE;plausible("dataroomViewed"); // track the eventanalytics.identify(@@ -196,6 +198,7 @@ export default function DataroomView({isPreview,ipAddress,useAdvancedExcelViewer,+ canDownload,}));setSubmitted(true);setVerificationRequested(false);@@ -329,7 +332,7 @@ export default function DataroomView({brand={brand}dataroomId={dataroom.id}setDocumentData={setDocumentData}- allowDownload={link.allowDownload!}+ allowDownload={viewData.canDownload ?? link.allowDownload!}/></div>) : viewData.fileType === "sheet" && viewData.useAdvancedExcelViewer ? (@@ -342,7 +345,7 @@ export default function DataroomView({documentName={documentData.name}versionNumber={documentData.documentVersionNumber}file={viewData.file!}- allowDownload={link.allowDownload!}+ allowDownload={viewData.canDownload ?? link.allowDownload!}brand={brand}dataroomId={dataroom.id}setDocumentData={setDocumentData}@@ -357,7 +360,7 @@ export default function DataroomView({isPreview={viewData.isPreview}documentId={documentData.id}documentName={documentData.name}- allowDownload={link.allowDownload!}+ allowDownload={viewData.canDownload ?? link.allowDownload!}feedbackEnabled={link.enableFeedback!}screenshotProtectionEnabled={link.enableScreenshotProtection!}versionNumber={documentData.documentVersionNumber}@@ -382,7 +385,7 @@ export default function DataroomView({linkId={link.id}documentId={documentData.id}documentName={documentData.name}- allowDownload={link.allowDownload!}+ allowDownload={viewData.canDownload ?? link.allowDownload!}feedbackEnabled={link.enableFeedback!}screenshotProtectionEnabled={link.enableScreenshotProtection!}versionNumber={documentData.documentVersionNumber}diff --git a/pages/api/views-dataroom.ts b/pages/api/views-dataroom.tsindex e8408243..4979ef1f 100644--- a/pages/api/views-dataroom.ts+++ b/pages/api/views-dataroom.ts@@ -1,6 +1,6 @@import { NextApiRequest, NextApiResponse } from "next";-import { LinkAudienceType } from "@prisma/client";+import { ItemType, LinkAudienceType } from "@prisma/client";import { waitUntil } from "@vercel/functions";import { getServerSession } from "next-auth/next";import { parsePageId } from "notion-utils";@@ -106,6 +106,7 @@ export default async function handle(watermarkConfig: true,groupId: true,audienceType: true,+ allowDownload: true,dataroom: {select: {teamId: true,@@ -546,6 +547,42 @@ export default async function handle(console.timeEnd("get-file");}+ // check if viewer can download the document based on group permissions+ let canDownload: boolean = link.allowDownload ?? false;+ if (+ link.allowDownload &&+ link.audienceType === LinkAudienceType.GROUP &&+ link.groupId &&+ documentId &&+ dataroomId+ ) {+ const dataroomDocument = await prisma.dataroomDocument.findUnique({+ where: {+ dataroomId_documentId: {+ dataroomId: dataroomId,+ documentId: documentId,+ },+ },+ select: { id: true },+ });+ if (!dataroomDocument) {+ canDownload = false;+ } else {+ const groupDocumentPermission =+ await prisma.viewerGroupAccessControls.findUnique({+ where: {+ groupId_itemId: {+ groupId: link.groupId,+ itemId: dataroomDocument.id,+ },+ itemType: ItemType.DATAROOM_DOCUMENT,+ },+ select: { canDownload: true },+ });+ canDownload = groupDocumentPermission?.canDownload ?? false;+ }+ }+const returnObject = {message: "View recorded",viewId: !isPreview && newView ? newView.id : undefined,@@ -587,6 +624,7 @@ export default async function handle(useAdvancedExcelViewer? useAdvancedExcelViewer: undefined,+ canDownload: canDownload,};return res.status(200).json(returnObject);