mirror of
https://github.com/zadam/trilium.git
synced 2025-01-18 04:59:56 +08:00
before we clone the note we must make sure it's not deleted
This commit is contained in:
parent
afabaa5fdb
commit
91ca07929d
2 changed files with 24 additions and 0 deletions
|
@ -8,6 +8,10 @@ const repository = require('./repository');
|
||||||
const Branch = require('../entities/branch');
|
const Branch = require('../entities/branch');
|
||||||
|
|
||||||
async function cloneNoteToParent(noteId, parentNoteId, prefix) {
|
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);
|
const validationResult = await treeService.validateParentChild(parentNoteId, noteId);
|
||||||
|
|
||||||
if (!validationResult.success) {
|
if (!validationResult.success) {
|
||||||
|
@ -27,6 +31,10 @@ async function cloneNoteToParent(noteId, parentNoteId, prefix) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function ensureNoteIsPresentInParent(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);
|
const validationResult = await treeService.validateParentChild(parentNoteId, noteId);
|
||||||
|
|
||||||
if (!validationResult.success) {
|
if (!validationResult.success) {
|
||||||
|
@ -61,6 +69,10 @@ async function toggleNoteInParent(present, noteId, parentNoteId, prefix) {
|
||||||
async function cloneNoteAfter(noteId, afterBranchId) {
|
async function cloneNoteAfter(noteId, afterBranchId) {
|
||||||
const afterNote = await treeService.getBranch(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);
|
const validationResult = await treeService.validateParentChild(afterNote.parentNoteId, noteId);
|
||||||
|
|
||||||
if (!validationResult.result) {
|
if (!validationResult.result) {
|
||||||
|
@ -84,6 +96,12 @@ async function cloneNoteAfter(noteId, afterBranchId) {
|
||||||
return { success: true };
|
return { success: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function isNoteDeleted(noteId) {
|
||||||
|
const note = await repository.getNote(noteId);
|
||||||
|
|
||||||
|
return note.isDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
cloneNoteToParent,
|
cloneNoteToParent,
|
||||||
ensureNoteIsPresentInParent,
|
ensureNoteIsPresentInParent,
|
||||||
|
|
|
@ -111,6 +111,12 @@ async function sortNotesAlphabetically(parentNoteId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setNoteToParent(noteId, prefix, 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 one
|
// case where there might be more such branches is ignored. It's expected there should be just one
|
||||||
const branch = await repository.getEntity("SELECT * FROM branches WHERE isDeleted = 0 AND noteId = ? AND prefix = ?", [noteId, prefix]);
|
const branch = await repository.getEntity("SELECT * FROM branches WHERE isDeleted = 0 AND noteId = ? AND prefix = ?", [noteId, prefix]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue