mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
added "update pojo" stage in entity saving to avoid encrypting data on protected note directly on the entity
This commit is contained in:
parent
e37dd69827
commit
ee1e4fc710
@ -105,6 +105,11 @@ class Attribute extends Entity {
|
|||||||
this.dateModified = dateUtils.nowDate();
|
this.dateModified = dateUtils.nowDate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cannot be static!
|
||||||
|
updatePojo(pojo) {
|
||||||
|
delete pojo.isOwned;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Attribute;
|
module.exports = Attribute;
|
@ -59,6 +59,11 @@ class Branch extends Entity {
|
|||||||
this.dateModified = dateUtils.nowDate();
|
this.dateModified = dateUtils.nowDate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cannot be static!
|
||||||
|
updatePojo(pojo) {
|
||||||
|
delete pojo.origParentNoteId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Branch;
|
module.exports = Branch;
|
@ -606,10 +606,6 @@ class Note extends Entity {
|
|||||||
// we do this here because encryption needs the note ID for the IV
|
// we do this here because encryption needs the note ID for the IV
|
||||||
this.generateIdIfNecessary();
|
this.generateIdIfNecessary();
|
||||||
|
|
||||||
if (this.isProtected) {
|
|
||||||
protectedSessionService.encryptNote(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.isDeleted) {
|
if (!this.isDeleted) {
|
||||||
this.isDeleted = false;
|
this.isDeleted = false;
|
||||||
}
|
}
|
||||||
@ -624,6 +620,17 @@ class Note extends Entity {
|
|||||||
this.dateModified = dateUtils.nowDate();
|
this.dateModified = dateUtils.nowDate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cannot be static!
|
||||||
|
updatePojo(pojo) {
|
||||||
|
if (pojo.isProtected) {
|
||||||
|
protectedSessionService.encryptNote(pojo);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete pojo.jsonContent;
|
||||||
|
delete pojo.isContentAvailable;
|
||||||
|
delete pojo.__attributeCache;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Note;
|
module.exports = Note;
|
@ -74,13 +74,13 @@ async function updateEntity(entity) {
|
|||||||
|
|
||||||
const clone = Object.assign({}, entity);
|
const clone = Object.assign({}, entity);
|
||||||
|
|
||||||
// transient properties not supposed to be persisted
|
// this check requires that updatePojo is not static
|
||||||
delete clone.jsonContent;
|
if (entity.updatePojo) {
|
||||||
delete clone.isOwned;
|
await entity.updatePojo(clone);
|
||||||
|
}
|
||||||
|
|
||||||
|
// indicates whether entity actually changed
|
||||||
delete clone.isChanged;
|
delete clone.isChanged;
|
||||||
delete clone.origParentNoteId;
|
|
||||||
delete clone.isContentAvailable;
|
|
||||||
delete clone.__attributeCache;
|
|
||||||
|
|
||||||
for (const key in clone) {
|
for (const key in clone) {
|
||||||
// !isBuffer is for images and attachments
|
// !isBuffer is for images and attachments
|
||||||
|
Loading…
x
Reference in New Issue
Block a user