prevent pasting notes into search parent note

This commit is contained in:
zadam 2022-06-16 20:02:40 +02:00
parent ec087ed328
commit b45df29937

View file

@ -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) {