Skip to content

Build your personal knowledge base with Trilium Notes

protection against deleting root note

azivnerce9805c5bcfc
diff --git a/src/public/javascripts/services/branches.js b/src/public/javascripts/services/branches.js
index e654dd1a01..88deca2652 100644
--- a/src/public/javascripts/services/branches.js
+++ b/src/public/javascripts/services/branches.js
@@ -59,6 +59,8 @@ async function moveToNode(nodesToMove, toNode) {
}
async function deleteNodes(nodes) {
+ nodes = nodes.filter(node => node.data.noteId !== 'root');
+
if (nodes.length === 0 || !confirm('Are you sure you want to delete select note(s) and all the sub-notes?')) {
return;
}
diff --git a/src/services/notes.js b/src/services/notes.js
index 488bcb9cf8..7575184df0 100644
--- a/src/services/notes.js
+++ b/src/services/notes.js
@@ -248,6 +248,10 @@ async function deleteNote(branch) {
return;
}
+ if (branch.branchId === 'root' || branch.noteId === 'root') {
+ throw new Error("Can't delete root branch/note");
+ }
+
branch.isDeleted = true;
await branch.save();
diff --git a/src/services/tree.js b/src/services/tree.js
index 348e9bab4c..a8a9e282e8 100644
--- a/src/services/tree.js
+++ b/src/services/tree.js
@@ -19,7 +19,7 @@ async function validateParentChild(parentNoteId, childNoteId, branchId = null) {
if (!await checkTreeCycle(parentNoteId, childNoteId)) {
return {
success: false,
- message: 'Moving note here would create cycle.'
+ message: 'Moving/cloning note here would create cycle.'
};
}