fix encrypting new notes

This commit is contained in:
azivner
2018-08-27 23:04:52 +02:00
parent 4721ddc6b3
commit 174d4e67af
4 changed files with 19 additions and 4 deletions

View File

@@ -17,9 +17,7 @@ class Entity {
}
beforeSaving() {
if (!this[this.constructor.primaryKeyName]) {
this[this.constructor.primaryKeyName] = utils.newEntityId();
}
this.generateIdIfNecessary();
const origHash = this.hash;
@@ -28,6 +26,12 @@ class Entity {
this.isChanged = origHash !== this.hash;
}
generateIdIfNecessary() {
if (!this[this.constructor.primaryKeyName]) {
this[this.constructor.primaryKeyName] = utils.newEntityId();
}
}
generateHash() {
let contentToHash = "";

View File

@@ -513,6 +513,9 @@ class Note extends Entity {
this.content = JSON.stringify(this.jsonContent, null, '\t');
}
// we do this here because encryption needs the note ID for the IV
this.generateIdIfNecessary();
if (this.isProtected) {
protectedSessionService.encryptNote(this);
}