1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-24 08:12:24 +02:00

All: Fixed handling of unloaded master key

This commit is contained in:
Laurent Cozic 2017-12-22 18:50:27 +00:00
parent 6683da804b
commit 70b03971f6
5 changed files with 16 additions and 16 deletions

View File

@ -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 = <span>{_('Some items cannot be synchronised.')} <a href="#" onClick={() => { onViewDisabledItemsClick() }}>{_('View them now')}</a></span>
} else if (this.props.missingMasterKeys.length) {
} else if (this.props.showMissingMasterKeyMessage) {
msg = <span>{_('Some items cannot be decrypted.')} <a href="#" onClick={() => { onViewMasterKeysClick() }}>{_('Set the password')}</a></span>
}
@ -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,
};
};

View File

@ -274,7 +274,7 @@ class BaseApplication {
const loadedMasterKeyIds = EncryptionService.instance().loadedMasterKeyIds();
this.dispatch({
type: 'MASTERKEY_REMOVE_MISSING',
type: 'MASTERKEY_REMOVE_NOT_LOADED',
ids: loadedMasterKeyIds,
});
}

View File

@ -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;

View File

@ -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;

View File

@ -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;
}