From a432ad74834f3ee614c9c4f29822280f84a7e7b7 Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 8 Mar 2019 22:25:12 +0100 Subject: [PATCH] fix isProtected consistency for images and files + related consistency check --- package-lock.json | 2 +- src/public/javascripts/services/note_detail.js | 5 ++++- src/services/consistency_checks.js | 7 +++++++ src/services/notes.js | 14 ++++++++------ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index ed2f68159..2c7112a53 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "trilium", - "version": "0.30.3-beta", + "version": "0.30.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js index c2f7c3393..1cd8b55ba 100644 --- a/src/public/javascripts/services/note_detail.js +++ b/src/public/javascripts/services/note_detail.js @@ -117,7 +117,10 @@ async function saveNote() { } note.title = $noteTitle.val(); - note.noteContent.content = getCurrentNoteContent(note); + + if (note.noteContent != null) { // might be null for file/image + note.noteContent.content = getCurrentNoteContent(note); + } // it's important to set the flag back to false immediatelly after retrieving title and content // otherwise we might overwrite another change (especially async code) diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js index 208fbc8a5..8a351873d 100644 --- a/src/services/consistency_checks.js +++ b/src/services/consistency_checks.js @@ -357,6 +357,13 @@ async function findLogicIssues() { logFix(`Removed link ${linkId} because target note ${targetNoteId} is also deleted.`); }); + + await findIssues(` + SELECT noteId + FROM notes + JOIN note_contents USING(noteId) + WHERE notes.isDeleted = 0 AND notes.isProtected != note_contents.isProtected`, + ({noteId}) => `Note ${noteId} has inconsistent isProtected in notes and note_contents tables`); } async function runSyncRowChecks(entityName, key) { diff --git a/src/services/notes.js b/src/services/notes.js index 623fbc1c5..7509956bf 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -332,19 +332,21 @@ async function updateNote(noteId, noteUpdates) { const noteTitleChanged = note.title !== noteUpdates.title; - noteUpdates.noteContent.content = await saveLinks(note, noteUpdates.noteContent.content); - note.title = noteUpdates.title; note.isProtected = noteUpdates.isProtected; await note.save(); - if (note.type !== 'file' && note.type !== 'image') { - const noteContent = await note.getNoteContent(); + const noteContent = await note.getNoteContent(); + + if (!['file', 'image'].includes(note.type)) { + noteUpdates.noteContent.content = await saveLinks(note, noteUpdates.noteContent.content); + noteContent.content = noteUpdates.noteContent.content; - noteContent.isProtected = noteUpdates.isProtected; - await noteContent.save(); } + noteContent.isProtected = noteUpdates.isProtected; + await noteContent.save(); + if (noteTitleChanged) { await triggerNoteTitleChanged(note); }