fix: Prevent moving documents into drafts
This commit is contained in:
@@ -180,7 +180,9 @@ function InnerDocumentLink(
|
|||||||
setExpanded(true);
|
setExpanded(true);
|
||||||
},
|
},
|
||||||
canDrop: (_item, monitor) =>
|
canDrop: (_item, monitor) =>
|
||||||
!!pathToNode && !pathToNode.includes(monitor.getItem<DragObject>().id),
|
!isDraft &&
|
||||||
|
!!pathToNode &&
|
||||||
|
!pathToNode.includes(monitor.getItem<DragObject>().id),
|
||||||
hover: (_item, monitor) => {
|
hover: (_item, monitor) => {
|
||||||
// Enables expansion of document children when hovering over the document
|
// Enables expansion of document children when hovering over the document
|
||||||
// for more than half a second.
|
// 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 () => {
|
it("should require id", async () => {
|
||||||
const { user } = await seed();
|
const { user } = await seed();
|
||||||
const res = await server.post("/api/documents.move", {
|
const res = await server.post("/api/documents.move", {
|
||||||
|
|||||||
@@ -904,6 +904,10 @@ router.post(
|
|||||||
userId: user.id,
|
userId: user.id,
|
||||||
});
|
});
|
||||||
authorize(user, "update", parent);
|
authorize(user, "update", parent);
|
||||||
|
|
||||||
|
if (!parent.publishedAt) {
|
||||||
|
throw InvalidRequestError("Cannot move document inside a draft");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
|||||||
Reference in New Issue
Block a user