Skip to content

Commit

Permalink
Implement deprecation of a static bank in the client and server
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeHiro committed Feb 7, 2019
1 parent 417ecac commit fdf33d9
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 35 deletions.
4 changes: 3 additions & 1 deletion client/components/operations/sync-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { actions, get } from '../../store';

const Export = connect(
(state, props) => {
let access = get.accessById(state, props.account.bankAccess);
let canBeSynced = !get.bankByUuid(state, access.bank).deprecated && access.enabled;
return {
canBeSynced: get.accessByAccountId(state, props.account.id).enabled
canBeSynced
};
},
(dispatch, ownProps) => {
Expand Down
2 changes: 1 addition & 1 deletion client/components/settings/bank-accesses/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ InitForm.defaultProps = {
const Export = connect(
state => {
return {
banks: get.banks(state),
banks: get.activeBanks(state),
emailEnabled: get.boolSetting(state, 'emails-enabled'),
emailRecipient: get.setting(state, 'email-recipient'),
categories: get.categories(state)
Expand Down
58 changes: 30 additions & 28 deletions client/components/settings/bank-accesses/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,34 +114,36 @@ export default connect(

let toggleEnableIcon = null;

if (access.enabled) {
maybeFetchIcon = (
<button
type="button"
className="fa fa-refresh"
aria-label="Reload accounts"
onClick={props.handleSyncAccounts}
title={$t('client.settings.reload_accounts_button')}
/>
);
maybeEditIcon = (
<ShowEditAccessModalButton
faIcon="fa-cog"
title={$t('client.settings.change_password_button')}
ariaLabel="Edit bank access"
accessId={access.id}
/>
);
toggleEnableIcon = <DisableAccessButton accessId={access.id} />;
} else {
toggleEnableIcon = (
<ShowEditAccessModalButton
faIcon="fa-power-off"
title={$t('client.settings.enable_access')}
ariaLabel="Enable bank access"
accessId={access.id}
/>
);
if (!access.bankIsVendorDeprecated) {
if (access.enabled) {
maybeFetchIcon = (
<button
type="button"
className="fa fa-refresh"
aria-label="Reload accounts"
onClick={props.handleSyncAccounts}
title={$t('client.settings.reload_accounts_button')}
/>
);
maybeEditIcon = (
<ShowEditAccessModalButton
faIcon="fa-cog"
title={$t('client.settings.change_password_button')}
ariaLabel="Edit bank access"
accessId={access.id}
/>
);
toggleEnableIcon = <DisableAccessButton accessId={access.id} />;
} else {
toggleEnableIcon = (
<ShowEditAccessModalButton
faIcon="fa-power-off"
title={$t('client.settings.enable_access')}
ariaLabel="Enable bank access"
accessId={access.id}
/>
);
}
}

return (
Expand Down
3 changes: 3 additions & 0 deletions client/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export class Access {

this.customLabel = (maybeHas(arg, 'customLabel') && arg.customLabel) || null;

this.bankIsVendorDeprecated = staticBank.deprecated;

assert(!maybeHas(arg, 'customFields') || arg.customFields instanceof Array);
let customFields =
maybeHas(arg, 'customFields') && arg.customFields.length ? arg.customFields : [];
Expand All @@ -52,6 +54,7 @@ export class Bank {
this.name = assertHas(arg, 'name') && arg.name;
this.uuid = assertHas(arg, 'uuid') && arg.uuid;
this.id = this.uuid;
this.deprecated = assertHas(arg, 'deprecated') && arg.deprecated;

// Force a deep copy of the custom fields (see also issue #569).
this.customFields = JSON.parse(JSON.stringify(arg.customFields || []));
Expand Down
6 changes: 5 additions & 1 deletion client/store/banks.js
Original file line number Diff line number Diff line change
Expand Up @@ -1284,10 +1284,14 @@ export function getCurrentAccountId(state) {
return state.currentAccountId;
}

export function all(state) {
function all(state) {
return state.banks;
}

export function allActiveStaticBanks(state) {
return all(state).filter(b => !b.deprecated);
}

export function bankByUuid(state, uuid) {
let candidate = state.banks.find(bank => bank.uuid === uuid);
return typeof candidate !== 'undefined' ? candidate : null;
Expand Down
4 changes: 2 additions & 2 deletions client/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ const memoizedUnusedCategories = createSelector(
export const get = {
// *** Banks **************************************************************
// [Bank]
banks(state) {
activeBanks(state) {
assertDefined(state);
return Bank.all(state.banks);
return Bank.allActiveStaticBanks(state.banks);
},

// Bank
Expand Down
7 changes: 5 additions & 2 deletions server/controllers/v1/accesses.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Accesses from '../../models/accesses';
import Accounts from '../../models/accounts';
import { bankVendorByUuid } from '../models/static-data';

import accountManager from '../../lib/accounts-manager';
import { fullPoll } from '../../lib/poller';
Expand Down Expand Up @@ -124,8 +125,9 @@ export async function fetchOperations(req, res) {
try {
let { id: userId } = req.user;
let access = req.preloaded.access;
let bank = bankVendorByUuid(access.bank);

if (!access.enabled) {
if (!access.enabled || bank.isDeprecated) {
let errcode = getErrorCode('DISABLED_ACCESS');
throw new KError('disabled access', 403, errcode);
}
Expand All @@ -150,8 +152,9 @@ export async function fetchAccounts(req, res) {
try {
let { id: userId } = req.user;
let access = req.preloaded.access;
let bank = bankVendorByUuid(access.bank);

if (!access.enabled) {
if (!access.enabled || bank.isDeprecated) {
let errcode = getErrorCode('DISABLED_ACCESS');
throw new KError('disabled access', 403, errcode);
}
Expand Down
7 changes: 7 additions & 0 deletions server/lib/poller.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ export async function fullPoll(userId) {
await accountManager.retrieveOperationsByAccess(userId, access);
} else {
let { bank, enabled, login } = access;
let staticBank = bankVendorByUuid(bank);
if (staticBank && staticBank.isDeprecated) {
log.info(
`Won't poll, module for bank ${bank} with login ${login} is deprecated.`
);
continue;
}
if (!enabled) {
log.info(
`Won't poll, access from bank ${bank} with login ${login} is disabled.`
Expand Down

0 comments on commit fdf33d9

Please sign in to comment.