The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Fix move links to folders bug
Steven Teyf4576cd37a41
diff --git a/apps/web/app/api/links/[linkId]/route.ts b/apps/web/app/api/links/[linkId]/route.tsindex c53ca3b32e..f76ab18d7c 100644--- a/apps/web/app/api/links/[linkId]/route.ts+++ b/apps/web/app/api/links/[linkId]/route.ts@@ -153,6 +153,7 @@ export const PATCH = withWorkspace(workspace,skipKeyChecks,skipExternalIdChecks,+ skipFolderChecks: true,});if (error) {diff --git a/apps/web/app/api/links/upsert/route.ts b/apps/web/app/api/links/upsert/route.tsindex 4a1cdfdf7b..569f302c8e 100644--- a/apps/web/app/api/links/upsert/route.ts+++ b/apps/web/app/api/links/upsert/route.ts@@ -30,14 +30,29 @@ export const PUT = withWorkspace(});if (link) {- if (link.folderId) {- await verifyFolderAccess({- workspaceId: workspace.id,- userId: session.user.id,- folderId: link.folderId,- requiredPermission: "folders.links.write",- });- }+ await Promise.all([+ ...(link.folderId+ ? [+ verifyFolderAccess({+ workspaceId: workspace.id,+ userId: session.user.id,+ folderId: link.folderId,+ requiredPermission: "folders.links.write",+ }),+ ]+ : []),++ ...(body.folderId+ ? [+ verifyFolderAccess({+ workspaceId: workspace.id,+ userId: session.user.id,+ folderId: body.folderId,+ requiredPermission: "folders.links.write",+ }),+ ]+ : []),+ ]);// proceed with /api/links/[linkId] PATCH logicconst updatedLink = {@@ -106,6 +121,7 @@ export const PUT = withWorkspace(workspace,skipKeyChecks,skipExternalIdChecks,+ skipFolderChecks: true,});if (error) {diff --git a/apps/web/lib/api/links/process-link.ts b/apps/web/lib/api/links/process-link.tsindex 030f4a4f9d..d49a9ff51a 100644--- a/apps/web/lib/api/links/process-link.ts+++ b/apps/web/lib/api/links/process-link.ts@@ -29,7 +29,8 @@ export async function processLink<T extends Record<string, any>>({bulk = false,skipKeyChecks = false, // only skip when key doesn't change (e.g. when editing a link)skipExternalIdChecks = false, // only skip when externalId doesn't change (e.g. when editing a link)- skipProgramChecks = false,+ skipFolderChecks = false, // only skip for update / upsert links+ skipProgramChecks = false, // only skip for when program is already validated}: {payload: NewLinkProps & T;workspace?: Pick<WorkspaceProps, "id" | "plan" | "flags">;@@ -37,6 +38,7 @@ export async function processLink<T extends Record<string, any>>({bulk?: boolean;skipKeyChecks?: boolean;skipExternalIdChecks?: boolean;+ skipFolderChecks?: boolean;skipProgramChecks?: boolean;}): Promise<| {@@ -390,8 +392,8 @@ export async function processLink<T extends Record<string, any>>({// only perform folder validity checks if:// - not bulk creation (we do that check separately in the route itself)- // - folderId is present- if (folderId) {+ // - folderId is present and we're not skipping folder checks+ if (folderId && !skipFolderChecks) {if (!workspace || !userId) {return {link: payload,