Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

fix: mutate permissions after create

Marc Seitz64397f7a57dd
diff --git a/components/links/links-table.tsx b/components/links/links-table.tsx
index 962bdf7d..c8e256cd 100644
--- a/components/links/links-table.tsx
+++ b/components/links/links-table.tsx
@@ -326,6 +326,9 @@ export default function LinksTable({
throw new Error(error.error || "Failed to create permission group");
}
+ const { permissionGroup: newPermissionGroup, _ } =
+ await response.json();
+
// Refresh the links cache
const endpointTargetType = `${targetType.toLowerCase()}s`;
mutate(
@@ -334,6 +337,15 @@ export default function LinksTable({
)}/links`,
);
+ // Cache the new permission group data
+ if (newPermissionGroup?.id) {
+ mutate(
+ `/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${targetId}/permission-groups/${newPermissionGroup.id}`,
+ newPermissionGroup,
+ false,
+ );
+ }
+
setShowPermissionsSheet(false);
setEditPermissionLink(null);
toast.success("File permissions updated successfully");
@@ -373,6 +385,13 @@ export default function LinksTable({
)}/links`,
);
+ // Invalidate the permission group cache
+ if (editPermissionLink.permissionGroupId) {
+ mutate(
+ `/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${targetId}/permission-groups/${editPermissionLink.permissionGroupId}`,
+ );
+ }
+
setShowPermissionsSheet(false);
setEditPermissionLink(null);
toast.success("File permissions updated successfully");
diff --git a/ee/features/permissions/components/dataroom-link-sheet.tsx b/ee/features/permissions/components/dataroom-link-sheet.tsx
index c1e5e67d..9eb1c6b6 100644
--- a/ee/features/permissions/components/dataroom-link-sheet.tsx
+++ b/ee/features/permissions/components/dataroom-link-sheet.tsx
@@ -333,7 +333,7 @@ export function DataroomLinkSheet({
if (permissions && typeof permissions === "object") {
if (isUpdating && currentLink?.permissionGroupId) {
// Update existing permission group
- await fetch(
+ const response = await fetch(
`/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${targetId}/permission-groups/${currentLink.permissionGroupId}`,
{
method: "PUT",
@@ -345,9 +345,16 @@ export function DataroomLinkSheet({
}),
},
);
+
+ if (response.ok) {
+ // Invalidate the permission group cache
+ mutate(
+ `/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${targetId}/permission-groups/${currentLink.permissionGroupId}`,
+ );
+ }
} else {
// Create new permission group
- await fetch(
+ const response = await fetch(
`/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${targetId}/permission-groups`,
{
method: "POST",
@@ -360,6 +367,22 @@ export function DataroomLinkSheet({
}),
},
);
+
+ if (response.ok) {
+ const { permissionGroup: newPermissionGroup, _ } =
+ await response.json();
+ // Cache the new permission group data
+ mutate(
+ `/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${targetId}/permission-groups/${newPermissionGroup.id}`,
+ newPermissionGroup,
+ false,
+ );
+
+ // Update the link with the new permission group ID
+ if (newPermissionGroup.id) {
+ link.permissionGroupId = newPermissionGroup.id;
+ }
+ }
}
}
};
diff --git a/ee/features/permissions/components/permissions-sheet.tsx b/ee/features/permissions/components/permissions-sheet.tsx
index af9cfa30..e69fe366 100644
--- a/ee/features/permissions/components/permissions-sheet.tsx
+++ b/ee/features/permissions/components/permissions-sheet.tsx
@@ -773,8 +773,11 @@ export function PermissionsSheet({
setShareEntireDataroom(effectivePermissions.length === 0);
setPendingChanges({});
- // Reset the UI to show full access for new links (when no effective permissions)
+ // For new links (no existing permissions), default to "share entire dataroom" on
+ // But if they turn it off, they'll start with no permissions selected (opt-in approach)
+ // For existing links, show the current permissions state
if (effectivePermissions.length === 0) {
+ // New link - start with full access shown but toggle is on
setData((prevData) => {
const resetToFullAccess = (items: FileOrFolder[]): FileOrFolder[] => {
return items.map((item) => ({
@@ -825,10 +828,28 @@ export function PermissionsSheet({
return updateAllItems(prevData);
});
} else {
- // When turning off, don't automatically set all items to viewable
- // Let the user manually select what they want
- // Just ensure we have some changes to track
+ // When turning off, reset all permissions to false so user must opt-in
setPendingChanges({});
+ setData((prevData) => {
+ const resetToNoAccess = (items: FileOrFolder[]): FileOrFolder[] => {
+ return items.map((item) => {
+ return {
+ ...item,
+ permissions: {
+ view: false,
+ download: false,
+ partialView: false,
+ partialDownload: false,
+ },
+ subItems: item.subItems
+ ? resetToNoAccess(item.subItems)
+ : undefined,
+ };
+ });
+ };
+
+ return resetToNoAccess(prevData);
+ });
}
};
@@ -902,9 +923,8 @@ export function PermissionsSheet({
<SheetHeader className="text-start">
<SheetTitle>Manage File Permissions</SheetTitle>
<p className="text-sm text-muted-foreground">
- Configure which files can be viewed and downloaded through this
- link. Use the toggle below to share all dataroom contents or set
- specific permissions.
+ Use the toggle below to share all dataroom contents or set specific
+ permissions.
</p>
</SheetHeader>
@@ -930,9 +950,9 @@ export function PermissionsSheet({
)}
</div>
<p className="text-sm text-muted-foreground">
- When enabled, all files and folders will be visible and
- accessible. <br />
Turn off to set specific permissions for individual items.
+ When turned off, no items are selected by default - you must
+ choose what to share.
</p>
</div>
{!canSetCustomPermissions ? (