Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Add folder permissions check for bulk link update

Kiran K451131572556
diff --git a/apps/web/app/api/links/bulk/route.ts b/apps/web/app/api/links/bulk/route.ts
index 6be89e5709..d1a171ea98 100644
--- a/apps/web/app/api/links/bulk/route.ts
+++ b/apps/web/app/api/links/bulk/route.ts
@@ -260,7 +260,7 @@ export const PATCH = withWorkspace(
return NextResponse.json("No links to update", { headers });
}
- const links = await prisma.link.findMany({
+ let links = await prisma.link.findMany({
where: {
projectId: workspace.id,
...(linkIds.length > 0
@@ -334,6 +334,43 @@ export const PATCH = withWorkspace(
});
}
+ if (checkIfLinksHaveFolders(links)) {
+ const folderIds = [
+ ...new Set(
+ links.map((link) => link.folderId).filter(Boolean) as string[],
+ ),
+ ];
+
+ const folderPermissions = await checkFolderPermissions({
+ workspaceId: workspace.id,
+ userId: session.user.id,
+ folderIds,
+ requiredPermission: "folders.links.write",
+ });
+
+ links = links.filter((link) => {
+ if (!link.folderId) {
+ return true;
+ }
+
+ const validFolder = folderPermissions.find(
+ (folder) => folder.folderId === link.folderId,
+ );
+
+ if (!validFolder?.hasPermission) {
+ errorLinks.push({
+ error: `You don't have permission to move this link to the folder: ${link.folderId}`,
+ code: "forbidden",
+ link,
+ });
+
+ return false;
+ }
+
+ return true;
+ });
+ }
+
const processedLinks = await Promise.all(
links.map(async (link) =>
processLink({