Skip to content

Commit

Permalink
Merge pull request #1404 from mfts/fix/dataroom-group-custom-link
Browse files Browse the repository at this point in the history
fix: update group permissions for deeply nested files
  • Loading branch information
mfts authored Nov 28, 2024
2 parents b1ce6fd + 7117435 commit 06ba286
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions components/datarooms/groups/group-permissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -453,37 +453,34 @@ export default function ExpandableTable({

// Ensure all parent folders are viewable if the item is being set to viewable
// and downloadable if the item is being set to downloadable
// if (updatedPermissions.view || updatedPermissions.download) {
// parents.forEach((parent) => {
// changes[parent.id] = {
// view: updatedPermissions.view || parent.permissions.view,
// download:
// updatedPermissions.download || parent.permissions.download,
// itemType: parent.itemType,
// };
// });

// } else {
// If turning off view, recalculate parent permissions
[...parents].reverse().forEach((parent) => {
const someSubItemViewable = parent.subItems?.some((subItem) =>
subItem.id === item.id
? updatedPermissions.view
: subItem.permissions.view,
);
const someSubItemDownloadable = parent.subItems?.some((subItem) =>
subItem.id === item.id
? updatedPermissions.download
: subItem.permissions.download,
);

changes[parent.id] = {
view: someSubItemViewable || false,
download: someSubItemDownloadable || false,
itemType: parent.itemType,
};
});
// }
if (updatedPermissions.view) {
parents.forEach((parent) => {
changes[parent.id] = {
view: true, // Always enable view for parent folders
download: parent.permissions.download, // Maintain existing download permission
itemType: parent.itemType,
};
});
} else {
// If turning off view, recalculate parent permissions
[...parents].reverse().forEach((parent) => {
const otherChildren =
parent.subItems?.filter((subItem) => subItem.id !== item.id) ||
[];
const someSubItemViewable = otherChildren.some(
(subItem) => subItem.permissions.view,
);
const someSubItemDownloadable = otherChildren.some(
(subItem) => subItem.permissions.download,
);

changes[parent.id] = {
view: someSubItemViewable,
download: someSubItemDownloadable,
itemType: parent.itemType,
};
});
}

return changes;
};
Expand Down

0 comments on commit 06ba286

Please sign in to comment.