Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/view/dataroom/dataroom-document-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ export default function DataroomDocumentView({
userEmail ??
undefined
}
canDownload={viewData.canDownload}
/>
) : (
<div className="flex h-screen items-center justify-center">
Expand Down
14 changes: 13 additions & 1 deletion components/view/view-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ export type TViewDocumentData = Document & {
versions: DocumentVersion[];
};

const isDownloadAllowed = (
canDownload: boolean | undefined,
linkAllowDownload: boolean | undefined,
): boolean => {
if (canDownload === false) return false;
return !!linkAllowDownload;
};

export default function ViewData({
viewData,
link,
Expand All @@ -49,6 +57,7 @@ export default function ViewData({
useAdvancedExcelViewer,
viewerEmail,
dataroomId,
canDownload,
}: {
viewData: DEFAULT_DOCUMENT_VIEW_TYPE | DEFAULT_DATAROOM_DOCUMENT_VIEW_TYPE;
link: LinkWithDocument | LinkWithDataroomDocument;
Expand All @@ -64,6 +73,7 @@ export default function ViewData({
useAdvancedExcelViewer?: boolean;
viewerEmail?: string;
dataroomId?: string;
canDownload?: boolean;
}) {
const { isMobile } = useMediaQuery();

Expand All @@ -83,9 +93,11 @@ export default function ViewData({
? viewData.conversationsEnabled
: false),
assistantEnabled: document.assistantEnabled,
allowDownload: link.allowDownload ?? false,
allowDownload: isDownloadAllowed(canDownload, link.allowDownload ?? false),
};

// Calculate allowDownload once for all components

return notionData?.recordMap ? (
<NotionPage
recordMap={notionData.recordMap}
Expand Down
17 changes: 15 additions & 2 deletions components/view/viewer/dataroom-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ export default function DataroomViewer({
[folderId, folders],
);

const allDocumentsCanDownload = useMemo(() => {
if (!allowDownload) return false;
if (!documents || documents.length === 0) return false;

return documents.some((doc) => {
if (doc.versions[0].type === "notion") return false;
const accessControl = accessControls.find(
(access) => access.itemId === doc.dataroomDocumentId,
);
return accessControl?.canDownload ?? true;
});
}, [documents, accessControls, allowDownload]);

// create a mixedItems array with folders and documents of the current folder and memoize it
const mixedItems = useMemo(() => {
const mixedItems: FolderOrDocument[] = [
Expand Down Expand Up @@ -142,7 +155,7 @@ export default function DataroomViewer({
linkId={linkId}
viewId={viewId}
isPreview={!!isPreview}
allowDownload={allowDownload}
allowDownload={allowDownload && item.canDownload}
/>
);
}
Expand All @@ -164,7 +177,7 @@ export default function DataroomViewer({
linkId={linkId}
viewId={viewId}
dataroom={dataroom}
allowDownload={allowDownload}
allowDownload={allDocumentsCanDownload}
isPreview={isPreview}
dataroomId={dataroom?.id}
viewerId={viewerId}
Expand Down
3 changes: 0 additions & 3 deletions ee/features/conversations/api/team-conversations-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,6 @@ const routeHandlers = {
return res.status(400).json({ message: "Missing required parameters" });
}

console.log("teamId", teamId);
console.log("dataroomId", dataroomId);

try {
// Check if user has access to the dataroom
const dataroom = await prisma.dataroom.findUnique({
Expand Down
2 changes: 0 additions & 2 deletions pages/api/links/[id]/documents/[documentId].ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ export default async function handle(
}),
});

console.log("data documents", data.linkData.dataroom?.documents[0]);

linkData = data.linkData;
brand = data.brand;

Expand Down