Skip to content
48 changes: 35 additions & 13 deletions app/api/views-dataroom/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export async function POST(request: NextRequest) {
enableWatermark: true,
watermarkConfig: true,
groupId: true,
permissionGroupId: true,
audienceType: true,
allowDownload: true,
enableConversation: true,
Expand Down Expand Up @@ -854,10 +855,13 @@ export async function POST(request: NextRequest) {

// check if viewer can download the document based on group permissions
let canDownload: boolean = link.allowDownload ?? false;
const effectiveGroupId = link.groupId || link.permissionGroupId;

if (
link.allowDownload &&
link.audienceType === LinkAudienceType.GROUP &&
link.groupId &&
(link.audienceType === LinkAudienceType.GROUP ||
link.permissionGroupId) &&
effectiveGroupId &&
documentId &&
dataroomId
) {
Expand All @@ -873,18 +877,36 @@ export async function POST(request: NextRequest) {
if (!dataroomDocument) {
canDownload = false;
} else {
const groupDocumentPermission =
await prisma.viewerGroupAccessControls.findUnique({
where: {
groupId_itemId: {
groupId: link.groupId,
itemId: dataroomDocument.id,
if (link.groupId) {
// This is a ViewerGroup (legacy behavior)
const groupDocumentPermission =
await prisma.viewerGroupAccessControls.findUnique({
where: {
groupId_itemId: {
groupId: link.groupId,
itemId: dataroomDocument.id,
},
itemType: ItemType.DATAROOM_DOCUMENT,
},
itemType: ItemType.DATAROOM_DOCUMENT,
},
select: { canDownload: true },
});
canDownload = groupDocumentPermission?.canDownload ?? false;
select: { canDownload: true },
});
canDownload = groupDocumentPermission?.canDownload ?? false;
} else if (link.permissionGroupId) {
// This is a PermissionGroup (new behavior)
const permissionGroupDocumentPermission =
await prisma.permissionGroupAccessControls.findUnique({
where: {
groupId_itemId: {
groupId: link.permissionGroupId,
itemId: dataroomDocument.id,
},
itemType: ItemType.DATAROOM_DOCUMENT,
},
select: { canDownload: true },
});
canDownload =
permissionGroupDocumentPermission?.canDownload ?? false;
}
}
}

Expand Down
7 changes: 3 additions & 4 deletions components/datarooms/dataroom-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import { BellRingIcon } from "lucide-react";

import { useDataroom, useDataroomLinks } from "@/lib/swr/use-dataroom";

import LinkSheet from "@/components/links/link-sheet";
import { DataroomLinkSheet } from "@/components/links/link-sheet/dataroom-link-sheet";
import { Button } from "@/components/ui/button";

import {
Tooltip,
TooltipContent,
TooltipPortal,
TooltipTrigger,
} from "../ui/tooltip";
} from "@/components/ui/tooltip";

export const DataroomHeader = ({
title,
Expand Down Expand Up @@ -70,7 +69,7 @@ export const DataroomHeader = ({
Share
</Button>
</div>
<LinkSheet
<DataroomLinkSheet
linkType={"DATAROOM_LINK"}
isOpen={isLinkSheetOpen}
setIsOpen={setIsLinkSheetOpen}
Expand Down
12 changes: 12 additions & 0 deletions components/links/link-sheet/dataroom-link-sheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use client";

import {
DataroomLinkSheet as DataroomLinkSheetEE,
type ItemPermission as ItemPermissionEE,
} from "@/ee/features/permissions/components/dataroom-link-sheet";

export type ItemPermission = ItemPermissionEE;

export function DataroomLinkSheet(props: any) {
return <DataroomLinkSheetEE {...props} />;
}
40 changes: 20 additions & 20 deletions components/links/link-sheet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { ButtonTooltip } from "@/components/ui/tooltip";

import { CustomFieldData } from "./custom-fields-panel";
import { type ItemPermission } from "./dataroom-link-sheet";
import DomainSection from "./domain-section";
import { LinkOptions } from "./link-options";
import TagSection from "./tags/tag-section";
Expand Down Expand Up @@ -89,6 +90,8 @@ export const DEFAULT_LINK_PROPS = (
uploadFolderId: null,
uploadFolderName: "Home",
enableIndexFile: false,
permissions: {},
permissionGroupId: null,
});

export type DEFAULT_LINK_TYPE = {
Expand Down Expand Up @@ -129,6 +132,8 @@ export type DEFAULT_LINK_TYPE = {
uploadFolderId: string | null;
uploadFolderName: string;
enableIndexFile: boolean;
permissions?: ItemPermission | null; // For dataroom links file permissions
permissionGroupId?: string | null;
};

export default function LinkSheet({
Expand Down Expand Up @@ -250,10 +255,8 @@ export default function LinkSheet({
enableAgreement: preset.enableAgreement || prev.enableAgreement,
agreementId: preset.agreementId || prev.agreementId,
enableScreenshotProtection:
preset.enableScreenshotProtection ||
prev.enableScreenshotProtection,
enableNotification:
!!preset.enableNotification,
preset.enableScreenshotProtection || prev.enableScreenshotProtection,
enableNotification: !!preset.enableNotification,
};
});

Expand Down Expand Up @@ -443,7 +446,7 @@ export default function LinkSheet({

return (
<Sheet open={isOpen} onOpenChange={(open: boolean) => setIsOpen(open)}>
<SheetContent className="flex w-[90%] flex-col justify-between border-l border-gray-200 bg-background px-4 text-foreground dark:border-gray-800 dark:bg-gray-900 sm:w-[600px] sm:max-w-2xl md:px-5">
<SheetContent className="flex w-[90%] flex-col justify-between border-l border-gray-200 bg-background px-4 text-foreground dark:border-gray-800 dark:bg-gray-900 sm:w-[800px] sm:max-w-4xl md:px-5">
<SheetHeader className="text-start">
<SheetTitle>
{currentLink
Expand All @@ -458,7 +461,7 @@ export default function LinkSheet({
>
<ScrollArea className="flex-grow">
<div className="h-0 flex-1">
<div className="flex flex-1 flex-col justify-between">
<div className="flex flex-1 flex-col justify-between pb-6">
<div className="divide-y divide-gray-200">
<Tabs
value={data.audienceType}
Expand Down Expand Up @@ -493,7 +496,7 @@ export default function LinkSheet({

<TabsContent value={LinkAudienceType.GENERAL}>
{/* GENERAL LINK */}
<div className="space-y-6 pb-10 pt-2">
<div className="space-y-6 pt-2">
<div className="space-y-2">
<Label htmlFor="link-name">Link Name</Label>
<Input
Expand All @@ -516,12 +519,6 @@ export default function LinkSheet({
editLink={!!currentLink}
/>
</div>
<div className="space-y-2">
<TagSection
{...{ data, setData }}
teamId={teamInfo?.currentTeam?.id as string}
/>
</div>

{/* Preset Selector - only show when creating a new link */}
{!currentLink &&
Expand Down Expand Up @@ -582,7 +579,7 @@ export default function LinkSheet({

<TabsContent value={LinkAudienceType.GROUP}>
{/* GROUP LINK */}
<div className="space-y-6 pb-10 pt-2">
<div className="space-y-6 pt-2">
<div className="space-y-2">
<div className="flex w-full items-center justify-between">
<Label htmlFor="group-id">Group </Label>
Expand Down Expand Up @@ -672,12 +669,6 @@ export default function LinkSheet({
editLink={!!currentLink}
/>
</div>
<div className="space-y-2">
<TagSection
{...{ data, setData }}
teamId={teamInfo?.currentTeam?.id as string}
/>
</div>

{/* Preset Selector for Group links - only show when creating a new link */}
{!currentLink &&
Expand Down Expand Up @@ -737,6 +728,15 @@ export default function LinkSheet({
</TabsContent>
</Tabs>
</div>

<Separator className="mb-6 mt-2" />

<div className="space-y-2">
<TagSection
{...{ data, setData }}
teamId={teamInfo?.currentTeam?.id as string}
/>
</div>
</div>
</div>
</ScrollArea>
Expand Down
Loading