From b45df29937e3f8b178f0855f03f1ea0e13d7948e Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 16 Jun 2022 20:02:40 +0200 Subject: [PATCH] prevent pasting notes into search parent note --- src/services/cloning.js | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/services/cloning.js b/src/services/cloning.js index d929a1cbf..395cb6772 100644 --- a/src/services/cloning.js +++ b/src/services/cloning.js @@ -3,10 +3,7 @@ const sql = require('./sql'); const eventChangesService = require('./entity_changes'); const treeService = require('./tree'); -const noteService = require('./notes'); const Branch = require('../becca/entities/branch'); -const TaskContext = require("./task_context"); -const utils = require('./utils'); const becca = require("../becca/becca"); const beccaService = require("../becca/becca_service"); const log = require("./log"); @@ -18,6 +15,15 @@ function cloneNoteToNote(noteId, parentNoteId, prefix) { specialNotesService.getShareRoot(); } + const parentNote = becca.getNote(parentNoteId); + + if (parentNote.type === 'search') { + return { + success: false, + message: "Can't clone into a search note" + }; + } + if (isNoteDeleted(noteId) || isNoteDeleted(parentNoteId)) { return { success: false, message: 'Note is deleted.' }; } @@ -53,7 +59,7 @@ function cloneNoteToBranch(noteId, parentBranchId, prefix) { const ret = cloneNoteToNote(noteId, parentBranch.noteId, prefix); - parentBranch.isExpanded = true; // the new target should be expanded so it immediately shows up to the user + parentBranch.isExpanded = true; // the new target should be expanded, so it immediately shows up to the user parentBranch.save(); return ret; @@ -64,6 +70,15 @@ function ensureNoteIsPresentInParent(noteId, parentNoteId, prefix) { return { success: false, message: 'Note is deleted.' }; } + const parentNote = becca.getNote(parentNoteId); + + if (parentNote.type === 'search') { + return { + success: false, + message: "Can't clone into a search note" + }; + } + const validationResult = treeService.validateParentChild(parentNoteId, noteId); if (!validationResult.success) { @@ -78,6 +93,8 @@ function ensureNoteIsPresentInParent(noteId, parentNoteId, prefix) { }).save(); log.info(`Ensured note ${noteId} is in parent note ${parentNoteId} with prefix ${prefix}`); + + return { success: true }; } function ensureNoteIsAbsentFromParent(noteId, parentNoteId) { @@ -111,6 +128,15 @@ function cloneNoteAfter(noteId, afterBranchId) { return { success: false, message: 'Note is deleted.' }; } + const parentNote = becca.getNote(afterNote.parentNoteId); + + if (parentNote.type === 'search') { + return { + success: false, + message: "Can't clone into a search note" + }; + } + const validationResult = treeService.validateParentChild(afterNote.parentNoteId, noteId); if (!validationResult.success) {