mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-11 18:24:43 +02:00
All: Fix: Fix issue with revisions being needlessly created when decrypting notes
This commit is contained in:
parent
6d7511efbb
commit
04c6579f2c
@ -1385,4 +1385,40 @@ describe('Synchronizer', function() {
|
||||
expect(!!resource.encryption_blob_encrypted).toBe(false);
|
||||
}));
|
||||
|
||||
it('should not create revisions when item is modified as a result of decryption', asyncTest(async () => {
|
||||
// Handle this scenario:
|
||||
// - C1 creates note
|
||||
// - C1 never changes it
|
||||
// - E2EE is enabled
|
||||
// - C1 sync
|
||||
// - More than one week later (as defined by oldNoteCutOffDate_), C2 sync
|
||||
// - C2 enters master password and note gets decrypted
|
||||
//
|
||||
// Technically at this point the note is modified (from encrypted to non-encrypted) and thus a ItemChange
|
||||
// object is created. The note is also older than oldNoteCutOffDate. However, this should not lead to the
|
||||
// creation of a revision because that change was not the result of a user action.
|
||||
// I guess that's the general rule - changes that come from user actions should result in revisions,
|
||||
// while automated changes (sync, decryption) should not.
|
||||
|
||||
const dateInPast = revisionService().oldNoteCutOffDate_() - 1000;
|
||||
|
||||
const note1 = await Note.save({ title: 'ma note', updated_time: dateInPast, created_time: dateInPast }, { autoTimestamp: false });
|
||||
const masterKey = await loadEncryptionMasterKey();
|
||||
await encryptionService().enableEncryption(masterKey, '123456');
|
||||
await encryptionService().loadMasterKeysFromSettings();
|
||||
await synchronizer().start();
|
||||
|
||||
await switchClient(2);
|
||||
|
||||
await synchronizer().start();
|
||||
|
||||
Setting.setObjectKey('encryption.passwordCache', masterKey.id, '123456');
|
||||
await encryptionService().loadMasterKeysFromSettings();
|
||||
await decryptionWorker().start();
|
||||
|
||||
await revisionService().collectRevisions();
|
||||
|
||||
expect((await Revision.all()).length).toBe(0);
|
||||
}));
|
||||
|
||||
});
|
||||
|
@ -90,8 +90,8 @@ android {
|
||||
applicationId "net.cozic.joplin"
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode 2097491
|
||||
versionName "1.0.255"
|
||||
versionCode 2097494
|
||||
versionName "1.0.258"
|
||||
ndk {
|
||||
abiFilters "armeabi-v7a", "x86"
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
const BaseModel = require('lib/BaseModel.js');
|
||||
const { Database } = require('lib/database.js');
|
||||
const Setting = require('lib/models/Setting.js');
|
||||
const ItemChange = require('lib/models/ItemChange.js');
|
||||
const JoplinError = require('lib/JoplinError.js');
|
||||
const { time } = require('lib/time-utils.js');
|
||||
const { sprintf } = require('sprintf-js');
|
||||
@ -355,7 +356,7 @@ class BaseItem extends BaseModel {
|
||||
plainItem.updated_time = item.updated_time;
|
||||
plainItem.encryption_cipher_text = '';
|
||||
plainItem.encryption_applied = 0;
|
||||
return ItemClass.save(plainItem, { autoTimestamp: false });
|
||||
return ItemClass.save(plainItem, { autoTimestamp: false, changeSource: ItemChange.SOURCE_DECRYPTION });
|
||||
}
|
||||
|
||||
static async unserialize(content) {
|
||||
|
@ -66,5 +66,6 @@ ItemChange.TYPE_DELETE = 3;
|
||||
|
||||
ItemChange.SOURCE_UNSPECIFIED = 1;
|
||||
ItemChange.SOURCE_SYNC = 2;
|
||||
ItemChange.SOURCE_DECRYPTION = 2;
|
||||
|
||||
module.exports = ItemChange;
|
@ -118,10 +118,11 @@ class RevisionService extends BaseService {
|
||||
FROM item_changes
|
||||
WHERE item_type = ?
|
||||
AND source != ?
|
||||
AND source != ?
|
||||
AND id > ?
|
||||
ORDER BY id ASC
|
||||
LIMIT 10
|
||||
`, [BaseModel.TYPE_NOTE, ItemChange.SOURCE_SYNC, Setting.value('revisionService.lastProcessedChangeId')]);
|
||||
`, [BaseModel.TYPE_NOTE, ItemChange.SOURCE_SYNC, ItemChange.SOURCE_DECRYPTION, Setting.value('revisionService.lastProcessedChangeId')]);
|
||||
|
||||
if (!changes.length) break;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user