diff --git a/src/notes_api.py b/src/notes_api.py index 73c81cb79..191d4c5fc 100644 --- a/src/notes_api.py +++ b/src/notes_api.py @@ -125,7 +125,8 @@ def createChild(parent_note_id): 'date_created': now, 'date_modified': now, 'icon_info': 'pencil', - 'is_finished': 0 + 'is_finished': 0, + 'encryption': note['encryption'] }) insert("notes_tree", { diff --git a/static/js/encryption.js b/static/js/encryption.js index ceef6f821..2e8ab5211 100644 --- a/static/js/encryption.js +++ b/static/js/encryption.js @@ -141,6 +141,10 @@ setInterval(function() { } }, 5000); +function isEncryptionAvailable() { + return globalEncryptionKey !== null; +} + function getAes() { globalLastEncryptionOperationDate = new Date(); diff --git a/static/js/note.js b/static/js/note.js index 5f691e5b8..72ed0f312 100644 --- a/static/js/note.js +++ b/static/js/note.js @@ -101,23 +101,32 @@ function createNewTopLevelNote() { let newNoteCreated = false; -function createNote(node, parentKey, target) { - let newNoteName = "new note"; +function createNote(node, parentKey, target, encryption) { + // if encryption isn't available (user didn't enter password yet), then note is created as unencrypted + // but this is quite weird since user doesn't see where the note is being created so it shouldn't occur often + if (!encryption || !isEncryptionAvailable()) { + encryption = 0; + } + + const newNoteName = "new note"; + const newNoteNameEncryptedIfNecessary = encryption > 0 ? encryptString(newNoteName) : newNoteName; $.ajax({ url: baseUrl + 'notes/' + parentKey + '/children' , type: 'POST', data: JSON.stringify({ - note_title: newNoteName, + note_title: newNoteNameEncryptedIfNecessary, target: target, - target_note_id: node.key + target_note_id: node.key, + encryption: encryption }), contentType: "application/json", success: function(result) { let newNode = { - "title": newNoteName, - "key": result.note_id, - "note_id": result.note_id + title: newNoteName, + key: result.note_id, + note_id: result.note_id, + encryption: encryption }; globalAllNoteIds.push(result.note_id); diff --git a/static/js/tree.js b/static/js/tree.js index 9051e6cdb..3be05eada 100644 --- a/static/js/tree.js +++ b/static/js/tree.js @@ -70,14 +70,19 @@ function getParentKey(node) { return (node.getParent() === null || node.getParent().key === "root_1") ? "root" : node.getParent().key; } +function getParentEncryption(node) { + return node.getParent() === null ? 0 : node.getParent().data.encryption; +} + const keybindings = { "insert": function(node) { const parentKey = getParentKey(node); + const encryption = getParentEncryption(node); - createNote(node, parentKey, 'after'); + createNote(node, parentKey, 'after', encryption); }, "ctrl+insert": function(node) { - createNote(node, node.key, 'into'); + createNote(node, node.key, 'into', node.data.encryption); }, "del": function(node) { deleteNode(node); @@ -329,9 +334,10 @@ $(function(){ const node = $.ui.fancytree.getNode(ui.target); if (ui.cmd === "insertNoteHere") { - const parentKey = getParentKey(node); + const parentKey = getParentKey(node); + const encryption = getParentEncryption(node); - createNote(node, parentKey, 'after'); + createNote(node, parentKey, 'after', encryption); } else if (ui.cmd === "insertChildNote") { createNote(node, node.key, 'into');