From 6070c499cc51392ecd031d89ac45dbdce430315a Mon Sep 17 00:00:00 2001 From: ThaumRystra <9525416+ThaumRystra@users.noreply.github.com> Date: Fri, 31 May 2024 20:36:09 +0200 Subject: [PATCH] Fixed broken library node insert button --- app/imports/api/library/LibraryNodes.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/imports/api/library/LibraryNodes.js b/app/imports/api/library/LibraryNodes.js index b31333ca..574ea464 100644 --- a/app/imports/api/library/LibraryNodes.js +++ b/app/imports/api/library/LibraryNodes.js @@ -158,16 +158,19 @@ const insertNode = new ValidatedMethod({ const parentDoc = fetchDocByRef(parentRef); // Check permission to edit - let root; + let rootLibrary; if (parentRef.collection === 'libraries') { - root = parentDoc; + rootLibrary = parentDoc; } else if (parentRef.collection === 'libraryNodes') { - root = Libraries.findOne(parentDoc.root.id); + rootLibrary = Libraries.findOne(parentDoc.root.id); libraryNode.parentId = parentRef.id; } else { throw `${parentRef.collection} is not a valid parent collection` } - assertEditPermission(root, this.userId); + assertEditPermission(rootLibrary, this.userId); + + // Set the root of the node we are inserting + libraryNode.root = { collection: 'libraries', id: rootLibrary._id }; // Remove its ID if it came with one to force a random one to be generated // server-side @@ -183,7 +186,7 @@ const insertNode = new ValidatedMethod({ } // Tree structure changed by insert, reorder the tree - rebuildNestedSets(LibraryNodes, root._id); + rebuildNestedSets(LibraryNodes, rootLibrary._id); // Return the id of the inserted node return nodeId;