From 70b03971f6170ffc7707f53caeaf8af8f6799e48 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Fri, 22 Dec 2017 18:50:27 +0000 Subject: [PATCH] All: Fixed handling of unloaded master key --- ElectronClient/app/gui/MainScreen.jsx | 6 +++--- ReactNativeClient/lib/BaseApplication.js | 2 +- ReactNativeClient/lib/reducer.js | 18 +++++++++--------- .../lib/services/DecryptionWorker.js | 4 ++-- .../lib/services/EncryptionService.js | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ElectronClient/app/gui/MainScreen.jsx b/ElectronClient/app/gui/MainScreen.jsx index a29f01b0e7..742d7f0b8b 100644 --- a/ElectronClient/app/gui/MainScreen.jsx +++ b/ElectronClient/app/gui/MainScreen.jsx @@ -289,7 +289,7 @@ class MainScreenComponent extends React.Component { const promptOptions = this.state.promptOptions; const folders = this.props.folders; const notes = this.props.notes; - const messageBoxVisible = this.props.hasDisabledSyncItems || this.props.missingMasterKeys.length; + const messageBoxVisible = this.props.hasDisabledSyncItems || this.props.showMissingMasterKeyMessage; const styles = this.styles(this.props.theme, style.width, style.height, messageBoxVisible); const theme = themeStyle(this.props.theme); @@ -356,7 +356,7 @@ class MainScreenComponent extends React.Component { let msg = null; if (this.props.hasDisabledSyncItems) { msg = {_('Some items cannot be synchronised.')} { onViewDisabledItemsClick() }}>{_('View them now')} - } else if (this.props.missingMasterKeys.length) { + } else if (this.props.showMissingMasterKeyMessage) { msg = {_('Some items cannot be decrypted.')} { onViewMasterKeysClick() }}>{_('Set the password')} } @@ -401,7 +401,7 @@ const mapStateToProps = (state) => { folders: state.folders, notes: state.notes, hasDisabledSyncItems: state.hasDisabledSyncItems, - missingMasterKeys: state.missingMasterKeys, + showMissingMasterKeyMessage: state.notLoadedMasterKeys.length && state.masterKeys.length, }; }; diff --git a/ReactNativeClient/lib/BaseApplication.js b/ReactNativeClient/lib/BaseApplication.js index 33553be4a5..bf44287951 100644 --- a/ReactNativeClient/lib/BaseApplication.js +++ b/ReactNativeClient/lib/BaseApplication.js @@ -274,7 +274,7 @@ class BaseApplication { const loadedMasterKeyIds = EncryptionService.instance().loadedMasterKeyIds(); this.dispatch({ - type: 'MASTERKEY_REMOVE_MISSING', + type: 'MASTERKEY_REMOVE_NOT_LOADED', ids: loadedMasterKeyIds, }); } diff --git a/ReactNativeClient/lib/reducer.js b/ReactNativeClient/lib/reducer.js index c292c4e618..90c95fbb97 100644 --- a/ReactNativeClient/lib/reducer.js +++ b/ReactNativeClient/lib/reducer.js @@ -9,7 +9,7 @@ const defaultState = { folders: [], tags: [], masterKeys: [], - missingMasterKeys: [], + notLoadedMasterKeys: [], searches: [], selectedNoteIds: [], selectedFolderId: null, @@ -370,27 +370,27 @@ const reducer = (state = defaultState, action) => { newState.masterKeys = action.items; break; - case 'MASTERKEY_ADD_MISSING': + case 'MASTERKEY_ADD_NOT_LOADED': - if (state.missingMasterKeys.indexOf(action.id) < 0) { + if (state.notLoadedMasterKeys.indexOf(action.id) < 0) { newState = Object.assign({}, state); - const keys = newState.missingMasterKeys.slice(); + const keys = newState.notLoadedMasterKeys.slice(); keys.push(action.id); - newState.missingMasterKeys = keys; + newState.notLoadedMasterKeys = keys; } break; - case 'MASTERKEY_REMOVE_MISSING': + case 'MASTERKEY_REMOVE_NOT_LOADED': const ids = action.id ? [action.id] : action.ids; for (let i = 0; i < ids.length; i++) { const id = ids[i]; - const index = state.missingMasterKeys.indexOf(id); + const index = state.notLoadedMasterKeys.indexOf(id); if (index >= 0) { newState = Object.assign({}, state); - const keys = newState.missingMasterKeys.slice(); + const keys = newState.notLoadedMasterKeys.slice(); keys.splice(index, 1); - newState.missingMasterKeys = keys; + newState.notLoadedMasterKeys = keys; } } break; diff --git a/ReactNativeClient/lib/services/DecryptionWorker.js b/ReactNativeClient/lib/services/DecryptionWorker.js index a751fa84d0..95b0ab013e 100644 --- a/ReactNativeClient/lib/services/DecryptionWorker.js +++ b/ReactNativeClient/lib/services/DecryptionWorker.js @@ -62,10 +62,10 @@ class DecryptionWorker { try { await ItemClass.decrypt(item); } catch (error) { - if (error.code === 'missingMasterKey') { + if (error.code === 'masterKeyNotLoaded') { excludedIds.push(item.id); this.dispatch({ - type: 'MASTERKEY_ADD_MISSING', + type: 'MASTERKEY_ADD_NOT_LOADED', id: error.masterKeyId, }); continue; diff --git a/ReactNativeClient/lib/services/EncryptionService.js b/ReactNativeClient/lib/services/EncryptionService.js index 34ec8c76c7..815c487b36 100644 --- a/ReactNativeClient/lib/services/EncryptionService.js +++ b/ReactNativeClient/lib/services/EncryptionService.js @@ -136,7 +136,7 @@ class EncryptionService { loadedMasterKey(id) { if (!this.loadedMasterKeys_[id]) { const error = new Error('Master key is not loaded: ' + id); - error.code = 'missingMasterKey'; + error.code = 'masterKeyNotLoaded'; error.masterKeyId = id; throw error; }