From b277a250e5d9dcec5c6515499e3d941c3ec52148 Mon Sep 17 00:00:00 2001 From: azivner Date: Sun, 8 Apr 2018 12:27:10 -0400 Subject: [PATCH] protected notes are not in autocomplete when not in protected session, fixes #46 --- src/entities/note.js | 3 ++- src/public/javascripts/services/autocomplete.js | 14 +++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/entities/note.js b/src/entities/note.js index 2b5e9e7b7..9f599c5f1 100644 --- a/src/entities/note.js +++ b/src/entities/note.js @@ -12,7 +12,8 @@ class Note extends Entity { constructor(row) { super(row); - if (this.isProtected) { + // check if there's noteId, otherwise this is a new entity which wasn't encrypted yet + if (this.isProtected && this.noteId) { protected_session.decryptNote(this); } diff --git a/src/public/javascripts/services/autocomplete.js b/src/public/javascripts/services/autocomplete.js index 7054c14d7..7243a53f9 100644 --- a/src/public/javascripts/services/autocomplete.js +++ b/src/public/javascripts/services/autocomplete.js @@ -1,5 +1,6 @@ import treeCache from "./tree_cache.js"; import treeUtils from "./tree_utils.js"; +import protectedSessionHolder from './protected_session_holder.js'; async function getAutocompleteItems(parentNoteId, notePath, titlePath) { if (!parentNoteId) { @@ -21,9 +22,6 @@ async function getAutocompleteItems(parentNoteId, notePath, titlePath) { titlePath = ''; } - // https://github.com/zadam/trilium/issues/46 - // unfortunately not easy to implement because we don't have an easy access to note's isProtected property - const autocompleteItems = []; for (const childNote of childNotes) { @@ -34,10 +32,12 @@ async function getAutocompleteItems(parentNoteId, notePath, titlePath) { const childNotePath = (notePath ? (notePath + '/') : '') + childNote.noteId; const childTitlePath = (titlePath ? (titlePath + ' / ') : '') + await treeUtils.getNoteTitle(childNote.noteId, parentNoteId); - autocompleteItems.push({ - value: childTitlePath + ' (' + childNotePath + ')', - label: childTitlePath - }); + if (!childNote.isProtected || protectedSessionHolder.isProtectedSessionAvailable()) { + autocompleteItems.push({ + value: childTitlePath + ' (' + childNotePath + ')', + label: childTitlePath + }); + } const childItems = await getAutocompleteItems(childNote.noteId, childNotePath, childTitlePath);