diff --git a/app/components/Sidebar/components/DocumentLink.tsx b/app/components/Sidebar/components/DocumentLink.tsx index bc7ce632a..8b3eec687 100644 --- a/app/components/Sidebar/components/DocumentLink.tsx +++ b/app/components/Sidebar/components/DocumentLink.tsx @@ -180,7 +180,9 @@ function InnerDocumentLink( setExpanded(true); }, canDrop: (_item, monitor) => - !!pathToNode && !pathToNode.includes(monitor.getItem().id), + !isDraft && + !!pathToNode && + !pathToNode.includes(monitor.getItem().id), hover: (_item, monitor) => { // Enables expansion of document children when hovering over the document // for more than half a second. diff --git a/server/routes/api/documents/documents.test.ts b/server/routes/api/documents/documents.test.ts index 2a35bf62e..568aac9c2 100644 --- a/server/routes/api/documents/documents.test.ts +++ b/server/routes/api/documents/documents.test.ts @@ -1826,6 +1826,26 @@ describe("#documents.move", () => { ); }); + it("should fail if attempting to nest doc within a draft", async () => { + const { user, document, collection } = await seed(); + const draft = await buildDraftDocument({ + userId: user.id, + teamId: document.teamId, + collectionId: collection.id, + }); + const res = await server.post("/api/documents.move", { + body: { + id: document.id, + collectionId: collection.id, + parentDocumentId: draft.id, + token: user.getJwtToken(), + }, + }); + const body = await res.json(); + expect(res.status).toEqual(400); + expect(body.message).toEqual("Cannot move document inside a draft"); + }); + it("should require id", async () => { const { user } = await seed(); const res = await server.post("/api/documents.move", { diff --git a/server/routes/api/documents/documents.ts b/server/routes/api/documents/documents.ts index f73b19b86..b5a0f3acd 100644 --- a/server/routes/api/documents/documents.ts +++ b/server/routes/api/documents/documents.ts @@ -904,6 +904,10 @@ router.post( userId: user.id, }); authorize(user, "update", parent); + + if (!parent.publishedAt) { + throw InvalidRequestError("Cannot move document inside a draft"); + } } const {