Commit 3145b521 authored by Benjamin Bouvier's avatar Benjamin Bouvier

Small fixes to !753;

- Fix server startup because of incorrect import path;
- Fix logic error to decide whether a deprecated access should be polled;
- Take into account the renaming of isDeprecated to deprecated;
- Disallow account balance syncing if the bank vendor is deprecated;
- Use the cache during the migration;
parent 951516f0
......@@ -93,6 +93,7 @@ export default connect(
account: get.accountById(state, props.accountId)
};
},
(dispatch, props) => {
return {
handleDeleteAccount: () => {
......@@ -106,6 +107,7 @@ export default connect(
}
};
},
(stateToProps, dispatchToProps, props) => {
let currentExcludeFromBalance = stateToProps.account.excludeFromBalance;
return {
......
......@@ -104,9 +104,10 @@ export default connect(
}
)(props => {
let { access } = props;
let accounts = access.accountIds.map(id => (
<AccountItem key={id} accountId={id} enabled={access.enabled} />
));
let accounts = access.accountIds.map(id => {
let enabled = access.enabled && !access.isBankVendorDeprecated;
return <AccountItem key={id} accountId={id} enabled={enabled} />;
});
// Display fetch and edit icons only if the access is active.
let maybeFetchIcon = null;
......@@ -114,7 +115,7 @@ export default connect(
let toggleEnableIcon = null;
if (!access.bankIsVendorDeprecated) {
if (!access.isBankVendorDeprecated) {
if (access.enabled) {
maybeFetchIcon = (
<button
......
......@@ -30,7 +30,7 @@ export class Access {
this.customLabel = (maybeHas(arg, 'customLabel') && arg.customLabel) || null;
this.bankIsVendorDeprecated = staticBank.deprecated;
this.isBankVendorDeprecated = staticBank.deprecated;
assert(!maybeHas(arg, 'customFields') || arg.customFields instanceof Array);
let customFields =
......
......@@ -15,7 +15,7 @@ if 'WEBOOB_DIR' in os.environ and os.path.isdir(os.environ['WEBOOB_DIR']):
WEBOOB_DIR = os.environ['WEBOOB_DIR']
sys.path.insert(0, os.environ['WEBOOB_DIR'])
else:
print >>sys.stderr, '"WEBOOB_DIR" env variable shall be set.'
print >>sys.stderr, '"WEBOOB_DIR" env variable must be set.'
sys.exit(1)
from weboob.core import WebNip
......
import Accesses from '../../models/accesses';
import Accounts from '../../models/accounts';
import { bankVendorByUuid } from '../models/static-data';
import { bankVendorByUuid } from '../../models/static-data';
import accountManager from '../../lib/accounts-manager';
import { fullPoll } from '../../lib/poller';
......@@ -125,9 +125,9 @@ export async function fetchOperations(req, res) {
try {
let { id: userId } = req.user;
let access = req.preloaded.access;
let bank = bankVendorByUuid(access.bank);
let bankVendor = bankVendorByUuid(access.bank);
if (!access.enabled || bank.isDeprecated) {
if (!access.enabled || bankVendor.deprecated) {
let errcode = getErrorCode('DISABLED_ACCESS');
throw new KError('disabled access', 403, errcode);
}
......@@ -152,9 +152,9 @@ export async function fetchAccounts(req, res) {
try {
let { id: userId } = req.user;
let access = req.preloaded.access;
let bank = bankVendorByUuid(access.bank);
let bankVendor = bankVendorByUuid(access.bank);
if (!access.enabled || bank.isDeprecated) {
if (!access.enabled || bankVendor.deprecated) {
let errcode = getErrorCode('DISABLED_ACCESS');
throw new KError('disabled access', 403, errcode);
}
......
......@@ -69,6 +69,15 @@ export async function fullPoll(userId) {
let accesses = await Accesses.all(userId);
for (let access of accesses) {
try {
let { bank, login } = access;
// Don't try to fetch accesses for deprecated modules.
let staticBank = bankVendorByUuid(bank);
if (!staticBank || staticBank.deprecated) {
log.info(`Won't poll, module for bank ${bank} with login ${login} is deprecated.`);
continue;
}
// Only import if last poll did not raise a login/parameter error.
if (access.canBePolled()) {
await accountManager.retrieveNewAccountsByAccess(userId, access, false, needUpdate);
......@@ -76,14 +85,7 @@ export async function fullPoll(userId) {
needUpdate = false;
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;
}
let { enabled } = access;
if (!enabled) {
log.info(
`Won't poll, access from bank ${bank} with login ${login} is disabled.`
......
......@@ -646,9 +646,9 @@ let migrations = [
async function m19(cache, userId) {
log.info('Migrating Crédit Mutuel de Bretagne default website.');
try {
let accesses = await Accesses.byBank(userId, { uuid: 'cmb' });
cache.accesses = cache.accesses || (await Accesses.byBank(userId, { uuid: 'cmb' }));
accessLoop: for (let access of accesses) {
accessLoop: for (let access of cache.accesses) {
let customFields = JSON.parse(access.customFields);
for (let customField of customFields) {
if (customField.name === 'website') {
......@@ -657,14 +657,17 @@ let migrations = [
}
}
customFields.push({ name: 'website', value: 'par' });
customFields.push({ name: 'website', value: 'pro' });
let stringified = JSON.stringify(customFields);
await Accesses.update(userId, access.id, {
customFields: JSON.stringify(customFields)
customFields: stringified
});
access.customFields = stringified;
}
} catch (e) {
log.error(
'Error while migrating Crédit Mutuel de Bretagn default website:',
'Error while migrating Crédit Mutuel de Bretagne default website:',
e.toString()
);
return false;
......
......@@ -1075,4 +1075,4 @@
"name": "Fake Bank 2",
"uuid": "fakebank2"
}
]
\ No newline at end of file
]
......@@ -393,10 +393,10 @@ describe('Test migration 19', async function() {
(await Accesses.find(0, cmbAccessToKeepId)).should.containDeep(cmbAccessToKeep);
});
it('the cmb access with no website set should be changed', async function() {
it('the cmb access with no website set should be changed', async function() {
let access = await Accesses.find(0, cmbAccessToChangeId);
access.should.not.containDeep(cmbAccessToChange);
cmbAccessToChange.customFields = JSON.stringify([{ name: 'website', value: 'par' }]);
cmbAccessToChange.customFields = JSON.stringify([{ name: 'website', value: 'pro' }]);
access.should.containDeep(cmbAccessToChange);
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment