From 471f7c669d387705cbc9bb3aad3800ac8281bb80 Mon Sep 17 00:00:00 2001 From: azivner Date: Thu, 2 Nov 2017 23:36:58 -0400 Subject: [PATCH] encryption of note history if the note is encrypted --- public/javascripts/encryption.js | 27 +++++++++++++++++++++++++++ public/javascripts/note_history.js | 16 ++++++++++++---- routes/api/note_history.js | 20 +++++++++++++++++++- 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/public/javascripts/encryption.js b/public/javascripts/encryption.js index 6ddbc2278..499d5f0f6 100644 --- a/public/javascripts/encryption.js +++ b/public/javascripts/encryption.js @@ -235,10 +235,37 @@ function encryptNoteAndSendToServer() { saveNoteToServer(note); + encryptNoteHistory(note.detail.note_id); + setNoteBackgroundIfEncrypted(note); }); } +function encryptNoteHistory(noteId) { + $.ajax({ + url: baseApiUrl + 'notes-history/' + noteId + "?encryption=0", + type: 'GET', + success: result => { + for (const row of result) { + row.note_title = encryptString(row.note_title); + row.note_text = encryptString(row.note_text); + + row.encryption = 1; + + $.ajax({ + url: baseApiUrl + 'notes-history', + type: 'PUT', + contentType: 'application/json', + data: JSON.stringify(row), + success: result => console.log('Note history ' + row.note_history_id + ' encrypted'), + error: () => alert("Error encrypting note history.") + }); + } + }, + error: () => alert("Error getting note history.") + }); +} + function decryptNoteAndSendToServer() { handleEncryption(true, true, () => { const note = globalCurrentNote; diff --git a/public/javascripts/note_history.js b/public/javascripts/note_history.js index d0c57213c..b508210ba 100644 --- a/public/javascripts/note_history.js +++ b/public/javascripts/note_history.js @@ -24,7 +24,7 @@ function showNoteHistoryDialog(noteId, noteHistoryId) { const dateModified = getDateFromTS(row.date_modified_to); $("#note-history-list").append($('