Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
fix: child folder is allowed but parent not
Marc Seitzb128c2486544
diff --git a/lib/api/links/link-data.ts b/lib/api/links/link-data.tsindex cb7161a7..4f261985 100644--- a/lib/api/links/link-data.ts+++ b/lib/api/links/link-data.ts@@ -7,13 +7,49 @@ import {import prisma from "@/lib/prisma";import { sortItemsByIndexAndName } from "@/lib/utils/sort-items-by-index-name";+// Helper function to get all parent folder IDs for given folder IDs+async function getAllParentFolderIds(+ folderIds: string[],+ dataroomId: string,+): Promise<string[]> {+ if (folderIds.length === 0) return [];++ const allRequiredFolderIds = new Set(folderIds);++ // Get all folders in the dataroom to build the hierarchy+ const allFolders = await prisma.dataroomFolder.findMany({+ where: { dataroomId },+ select: { id: true, parentId: true },+ });++ // Use Map for O(1) parent lookup: folderId -> parentId+ // This is more efficient than Set because we need key-value relationship for traversal+ const folderMap = new Map(+ allFolders.map((folder) => [folder.id, folder.parentId]),+ );++ // For each accessible folder, traverse up to find all parent folders+ for (const folderId of folderIds) {+ let currentId: string | null = folderId;++ while (currentId) {+ allRequiredFolderIds.add(currentId);+ currentId = folderMap.get(currentId) || null;+ }+ }++ return Array.from(allRequiredFolderIds);+}+export async function fetchDataroomLinkData({linkId,+ dataroomId,teamId,groupId,permissionGroupId,}: {linkId: string;+ dataroomId: string | null;teamId: string;groupId?: string;permissionGroupId?: string;@@ -23,6 +59,7 @@ export async function fetchDataroomLinkData({| PermissionGroupAccessControls[] = [];let documentIds: string[] = [];let folderIds: string[] = [];+ let allRequiredFolderIds: string[] = [];const effectiveGroupId = groupId || permissionGroupId;@@ -55,6 +92,14 @@ export async function fetchDataroomLinkData({folderIds = groupPermissions.filter((permission) => permission.itemType === ItemType.DATAROOM_FOLDER).map((permission) => permission.itemId);++ // Include parent folders if we have group permissions and they're actually being applied+ // This ensures that if a group has access to a subfolder, all parent folders+ // are also included to maintain proper hierarchy (even without explicit permissions)+ allRequiredFolderIds = folderIds;+ if (dataroomId && folderIds.length > 0) {+ allRequiredFolderIds = await getAllParentFolderIds(folderIds, dataroomId);+ }}const linkData = await prisma.link.findUnique({@@ -107,7 +152,7 @@ export async function fetchDataroomLinkData({folders: {where:groupPermissions.length > 0 || effectiveGroupId- ? { id: { in: folderIds } }+ ? { id: { in: allRequiredFolderIds } }: undefined,orderBy: [{ orderIndex: "asc" }, { name: "asc" }],},diff --git a/pages/api/links/[id]/index.ts b/pages/api/links/[id]/index.tsindex c6399f3e..9ed40501 100644--- a/pages/api/links/[id]/index.ts+++ b/pages/api/links/[id]/index.ts@@ -63,6 +63,7 @@ export default async function handle(groupId: true,permissionGroupId: true,audienceType: true,+ dataroomId: true,teamId: true,team: {select: {@@ -115,6 +116,7 @@ export default async function handle(console.time("get-dataroom-link-data");const data = await fetchDataroomLinkData({linkId: id,+ dataroomId: link.dataroomId,teamId: link.teamId!,permissionGroupId: link.permissionGroupId || undefined,...(link.audienceType === LinkAudienceType.GROUP &&@@ -134,6 +136,7 @@ export default async function handle(const returnLink = {...link,...linkData,+ dataroomId: undefined,...(teamPlan === "free" && {customFields: [], // reset custom fields for free planenableAgreement: false,