fix: Prevent moving documents into drafts
This commit is contained in:
@@ -180,7 +180,9 @@ function InnerDocumentLink(
|
||||
setExpanded(true);
|
||||
},
|
||||
canDrop: (_item, monitor) =>
|
||||
!!pathToNode && !pathToNode.includes(monitor.getItem<DragObject>().id),
|
||||
!isDraft &&
|
||||
!!pathToNode &&
|
||||
!pathToNode.includes(monitor.getItem<DragObject>().id),
|
||||
hover: (_item, monitor) => {
|
||||
// Enables expansion of document children when hovering over the document
|
||||
// for more than half a second.
|
||||
|
||||
@@ -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", {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user