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
This commit is contained in:
Tom Moor authored and GitHub committed 2025-07-11 07:47:03 -04:00
1 parent 9193e606b9
commit 66964ad5a1
3 files changed
+32 -5

No files matched your search

+3 -3
View File
@@ -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
@@ -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 () => {
+2 -2
View File
@@ -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;