Skip to content

Commit 06ba286

Browse files
authored
Merge pull request #1404 from mfts/fix/dataroom-group-custom-link
fix: update group permissions for deeply nested files
2 parents b1ce6fd + 7117435 commit 06ba286

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

components/datarooms/groups/group-permissions.tsx

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -453,37 +453,34 @@ export default function ExpandableTable({
453453

454454
// Ensure all parent folders are viewable if the item is being set to viewable
455455
// and downloadable if the item is being set to downloadable
456-
// if (updatedPermissions.view || updatedPermissions.download) {
457-
// parents.forEach((parent) => {
458-
// changes[parent.id] = {
459-
// view: updatedPermissions.view || parent.permissions.view,
460-
// download:
461-
// updatedPermissions.download || parent.permissions.download,
462-
// itemType: parent.itemType,
463-
// };
464-
// });
465-
466-
// } else {
467-
// If turning off view, recalculate parent permissions
468-
[...parents].reverse().forEach((parent) => {
469-
const someSubItemViewable = parent.subItems?.some((subItem) =>
470-
subItem.id === item.id
471-
? updatedPermissions.view
472-
: subItem.permissions.view,
473-
);
474-
const someSubItemDownloadable = parent.subItems?.some((subItem) =>
475-
subItem.id === item.id
476-
? updatedPermissions.download
477-
: subItem.permissions.download,
478-
);
479-
480-
changes[parent.id] = {
481-
view: someSubItemViewable || false,
482-
download: someSubItemDownloadable || false,
483-
itemType: parent.itemType,
484-
};
485-
});
486-
// }
456+
if (updatedPermissions.view) {
457+
parents.forEach((parent) => {
458+
changes[parent.id] = {
459+
view: true, // Always enable view for parent folders
460+
download: parent.permissions.download, // Maintain existing download permission
461+
itemType: parent.itemType,
462+
};
463+
});
464+
} else {
465+
// If turning off view, recalculate parent permissions
466+
[...parents].reverse().forEach((parent) => {
467+
const otherChildren =
468+
parent.subItems?.filter((subItem) => subItem.id !== item.id) ||
469+
[];
470+
const someSubItemViewable = otherChildren.some(
471+
(subItem) => subItem.permissions.view,
472+
);
473+
const someSubItemDownloadable = otherChildren.some(
474+
(subItem) => subItem.permissions.download,
475+
);
476+
477+
changes[parent.id] = {
478+
view: someSubItemViewable,
479+
download: someSubItemDownloadable,
480+
itemType: parent.itemType,
481+
};
482+
});
483+
}
487484

488485
return changes;
489486
};

0 commit comments

Comments
 (0)