if parent note is encrypted, then child note will be created as encrypted as well

This commit is contained in:
azivner 2017-09-08 22:43:02 -04:00
parent 9ba958205d
commit adf18132fb
4 changed files with 32 additions and 12 deletions

View file

@ -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", {

View file

@ -141,6 +141,10 @@ setInterval(function() {
}
}, 5000);
function isEncryptionAvailable() {
return globalEncryptionKey !== null;
}
function getAes() {
globalLastEncryptionOperationDate = new Date();

View file

@ -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);

View file

@ -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');