From 66964ad5a1ae2247e5a76ae8eb08fa7906ee11d0 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Fri, 11 Jul 2025 07:47:03 -0400 Subject: [PATCH] fix: Blank page is rendered when link to draft without collection is shared (#9605) * fix: 404 response for public shared collection-less draft * fix: sharedTree undefined in response for public shared draft in no collection * test --- server/commands/documentLoader.ts | 6 ++--- server/routes/api/documents/documents.test.ts | 27 +++++++++++++++++++ server/routes/api/documents/documents.ts | 4 +-- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/server/commands/documentLoader.ts b/server/commands/documentLoader.ts index 1ec343ea9b..a83fc9eb45 100644 --- a/server/commands/documentLoader.ts +++ b/server/commands/documentLoader.ts @@ -142,10 +142,10 @@ export default async function loadDocument({ includeDocumentStructure: true, rejectOnEmpty: true, }); - } - if (!collection?.sharing) { - throw AuthorizationError(); + if (!collection.sharing) { + throw AuthorizationError(); + } } // If we're attempting to load a document that isn't the document originally diff --git a/server/routes/api/documents/documents.test.ts b/server/routes/api/documents/documents.test.ts index 32837b25ab..0aeae23597 100644 --- a/server/routes/api/documents/documents.test.ts +++ b/server/routes/api/documents/documents.test.ts @@ -385,6 +385,33 @@ describe("#documents.info", () => { }); expect(res.status).toEqual(200); }); + + it("should return sharedTree as null for shared draft without collection", async () => { + const user = await buildUser(); + const document = await buildDraftDocument({ + userId: user.id, + teamId: user.teamId, + collectionId: null, + }); + const share = await buildShare({ + documentId: document.id, + teamId: document.teamId, + userId: user.id, + includeChildDocuments: true, + }); + const res = await server.post("/api/documents.info", { + body: { + shareId: share.id, + apiVersion: 2, + }, + }); + const body = await res.json(); + expect(res.status).toEqual(200); + expect(body.data.document.id).toEqual(document.id); + expect(body.data.document.createdBy).toEqual(undefined); + expect(body.data.document.updatedBy).toEqual(undefined); + expect(body.data.sharedTree).toEqual(null); + }); }); it("should not return document from shareId if sharing is disabled for collection", async () => { diff --git a/server/routes/api/documents/documents.ts b/server/routes/api/documents/documents.ts index 60690838f2..d797841632 100644 --- a/server/routes/api/documents/documents.ts +++ b/server/routes/api/documents/documents.ts @@ -597,8 +597,8 @@ router.post( ) : undefined, sharedTree: - share && share.includeChildDocuments - ? collection?.getDocumentTree(share.documentId) + share && share.includeChildDocuments && collection + ? collection.getDocumentTree(share.documentId) : null, } : serializedDocument;