Fixed broken library node insert button

This commit is contained in:
ThaumRystra
2024-05-31 20:36:09 +02:00
parent 6e8c970287
commit 6070c499cc

View File

@@ -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;