mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +02:00
prevent pasting notes into search parent note
This commit is contained in:
parent
ec087ed328
commit
b45df29937
@ -3,10 +3,7 @@
|
|||||||
const sql = require('./sql');
|
const sql = require('./sql');
|
||||||
const eventChangesService = require('./entity_changes');
|
const eventChangesService = require('./entity_changes');
|
||||||
const treeService = require('./tree');
|
const treeService = require('./tree');
|
||||||
const noteService = require('./notes');
|
|
||||||
const Branch = require('../becca/entities/branch');
|
const Branch = require('../becca/entities/branch');
|
||||||
const TaskContext = require("./task_context");
|
|
||||||
const utils = require('./utils');
|
|
||||||
const becca = require("../becca/becca");
|
const becca = require("../becca/becca");
|
||||||
const beccaService = require("../becca/becca_service");
|
const beccaService = require("../becca/becca_service");
|
||||||
const log = require("./log");
|
const log = require("./log");
|
||||||
@ -18,6 +15,15 @@ function cloneNoteToNote(noteId, parentNoteId, prefix) {
|
|||||||
specialNotesService.getShareRoot();
|
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)) {
|
if (isNoteDeleted(noteId) || isNoteDeleted(parentNoteId)) {
|
||||||
return { success: false, message: 'Note is deleted.' };
|
return { success: false, message: 'Note is deleted.' };
|
||||||
}
|
}
|
||||||
@ -53,7 +59,7 @@ function cloneNoteToBranch(noteId, parentBranchId, prefix) {
|
|||||||
|
|
||||||
const ret = cloneNoteToNote(noteId, parentBranch.noteId, 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();
|
parentBranch.save();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -64,6 +70,15 @@ function ensureNoteIsPresentInParent(noteId, parentNoteId, prefix) {
|
|||||||
return { success: false, message: 'Note is deleted.' };
|
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);
|
const validationResult = treeService.validateParentChild(parentNoteId, noteId);
|
||||||
|
|
||||||
if (!validationResult.success) {
|
if (!validationResult.success) {
|
||||||
@ -78,6 +93,8 @@ function ensureNoteIsPresentInParent(noteId, parentNoteId, prefix) {
|
|||||||
}).save();
|
}).save();
|
||||||
|
|
||||||
log.info(`Ensured note ${noteId} is in parent note ${parentNoteId} with prefix ${prefix}`);
|
log.info(`Ensured note ${noteId} is in parent note ${parentNoteId} with prefix ${prefix}`);
|
||||||
|
|
||||||
|
return { success: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureNoteIsAbsentFromParent(noteId, parentNoteId) {
|
function ensureNoteIsAbsentFromParent(noteId, parentNoteId) {
|
||||||
@ -111,6 +128,15 @@ function cloneNoteAfter(noteId, afterBranchId) {
|
|||||||
return { success: false, message: 'Note is deleted.' };
|
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);
|
const validationResult = treeService.validateParentChild(afterNote.parentNoteId, noteId);
|
||||||
|
|
||||||
if (!validationResult.success) {
|
if (!validationResult.success) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user