Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
before we clone the note we must make sure it's not deleted
azivner91ca07929d89
diff --git a/src/services/cloning.js b/src/services/cloning.jsindex bb3c51d52f..af987aceb6 100644--- a/src/services/cloning.js+++ b/src/services/cloning.js@@ -8,6 +8,10 @@ const repository = require('./repository');const Branch = require('../entities/branch');async function cloneNoteToParent(noteId, parentNoteId, prefix) {+ if (await isNoteDeleted(noteId) || await isNoteDeleted(parentNoteId)) {+ return { success: false, message: 'Note is deleted.' };+ }+const validationResult = await treeService.validateParentChild(parentNoteId, noteId);if (!validationResult.success) {@@ -27,6 +31,10 @@ async function cloneNoteToParent(noteId, parentNoteId, prefix) {}async function ensureNoteIsPresentInParent(noteId, parentNoteId, prefix) {+ if (await isNoteDeleted(noteId) || await isNoteDeleted(parentNoteId)) {+ return { success: false, message: 'Note is deleted.' };+ }+const validationResult = await treeService.validateParentChild(parentNoteId, noteId);if (!validationResult.success) {@@ -61,6 +69,10 @@ async function toggleNoteInParent(present, noteId, parentNoteId, prefix) {async function cloneNoteAfter(noteId, afterBranchId) {const afterNote = await treeService.getBranch(afterBranchId);+ if (await isNoteDeleted(noteId) || await isNoteDeleted(afterNote.parentNoteId)) {+ return { success: false, message: 'Note is deleted.' };+ }+const validationResult = await treeService.validateParentChild(afterNote.parentNoteId, noteId);if (!validationResult.result) {@@ -84,6 +96,12 @@ async function cloneNoteAfter(noteId, afterBranchId) {return { success: true };}+async function isNoteDeleted(noteId) {+ const note = await repository.getNote(noteId);++ return note.isDeleted;+}+module.exports = {cloneNoteToParent,ensureNoteIsPresentInParent,diff --git a/src/services/tree.js b/src/services/tree.jsindex f51089d8b1..6e97ed065a 100644--- a/src/services/tree.js+++ b/src/services/tree.js@@ -111,6 +111,12 @@ async function sortNotesAlphabetically(parentNoteId) {}async function setNoteToParent(noteId, prefix, parentNoteId) {+ const parentNote = await repository.getNote(parentNoteId);++ if (parentNote.isDeleted) {+ throw new Error("Cannot move note to deleted parent note");+ }+// case where there might be more such branches is ignored. It's expected there should be just oneconst branch = await repository.getEntity("SELECT * FROM branches WHERE isDeleted = 0 AND noteId = ? AND prefix = ?", [noteId, prefix]);