Commit e983a386 authored by Antoine's avatar Antoine Committed by ZeHiro
Browse files

Upgrade minimal version of weboob to 1.2

Fixes #536.
parent 13efd6d2
import React from 'react';
import { translate as $t } from '../../helpers';
import { translate as $t, MIN_WEBOOB_VERSION as version } from '../../helpers';
export default () => (
<div>
<h1>
{ $t('client.weboobinstallreadme.title') }
{ $t('client.weboobinstallreadme.title', { version }) }
</h1>
<div className="well">
{ $t('client.weboobinstallreadme.content') }
{ $t('client.weboobinstallreadme.content', { version }) }
<a href="https://framagit.org/bnjbvr/kresus/blob/master/README.md">README</a>.
</div>
</div>
......
......@@ -4,6 +4,8 @@
/* eslint no-console: 0 */
import semver from 'semver';
import { assert as assert_,
assertHas as assertHas_,
maybeHas as maybeHas_,
......@@ -74,3 +76,36 @@ export const wellsColors = {
SPENT: '#F26C4F',
SAVED: '#0072BC'
};
export function normalizeVersion(version) {
if (typeof version === 'undefined' || version === null) {
return null;
}
let stringifiedVersion = version.toString();
let cleanedVersion = semver.clean(stringifiedVersion);
if (cleanedVersion !== null) {
return cleanedVersion;
}
if (!/\d/.test(stringifiedVersion)) {
throw new Error(`version should contain numbers: ${version}`);
}
let digits = stringifiedVersion.split('.');
// Eliminate extra digits
digits = digits.slice(0, 3);
// Fill missing digits
while (digits.length < 3) {
digits.push('0');
}
// Replace fully string version with '0'
digits = digits.map(digit => {
if (typeof digit === 'string' && /^\D*$/.test(digit)) {
return '0';
}
return digit;
});
return digits.join('.');
}
export const MIN_WEBOOB_VERSION = '1.2';
......@@ -6,6 +6,7 @@ import {
import reduxThunk from 'redux-thunk';
import { createSelector } from 'reselect';
import semver from 'semver';
import * as Bank from './banks';
import * as Category from './categories';
......@@ -19,7 +20,9 @@ import {
assert,
assertHas,
assertDefined,
debug
debug,
MIN_WEBOOB_VERSION,
normalizeVersion
} from '../helpers';
import * as backend from './backend';
......@@ -220,8 +223,9 @@ export const get = {
if (!this.boolSetting(state, 'weboob-installed'))
return false;
let version = this.setting(state, 'weboob-version');
return version !== '?' && version !== '1.0';
let version = normalizeVersion(this.setting(state, 'weboob-version'));
return semver(version) && semver.gt(version, normalizeVersion(MIN_WEBOOB_VERSION));
},
// Bool
......
......@@ -19,8 +19,8 @@
"cozydb": "0.1.13",
"currency-formatter": "1.1.1",
"moment": "2.17.1",
"nodemailer": "2.7.2",
"node-polyglot": "2.2.2",
"nodemailer": "2.7.2",
"ospath": "1.2.2",
"pouchdb": "6.1.2",
"printit": "0.1.20"
......@@ -43,8 +43,8 @@
"eslint-plugin-react": "6.10.0",
"font-awesome": "4.7.0",
"jquery": "3.1.1",
"jquery.cookie": "1.4.1",
"jquery-minicolors": "2.1.10",
"jquery.cookie": "1.4.1",
"lodash.throttle": "4.1.1",
"minify": "2.0.13",
"mocha": "3.2.0",
......@@ -57,6 +57,7 @@
"redux": "3.6.0",
"redux-thunk": "2.2.0",
"reselect": "2.5.4",
"semver": "5.3.0",
"should": "11.2.0",
"updeep": "1.0.0",
"watchify": "3.9.0"
......
......@@ -356,8 +356,8 @@ module.exports = {
},
weboobinstallreadme: {
title: 'Please install Weboob 1.1 or later',
content: `In order to work as expected, Kresus has a single dependency called Weboob. To offer you the best experience, the latest stable version of Weboob has to be installed (1.1 or later, at this point). If you are hosted by CozyCloud, this should be already installed for you and this is an error; please let the CozyCloud administrators know about this by sending an email to contact@cozycloud.cc. If you are self-hosted, you'll need to install Weboob as described in the README file: `
title: 'Please install Weboob %{version} or later',
content: `In order to work as expected, Kresus has a single dependency called Weboob. To offer you the best experience, the latest stable version of Weboob has to be installed (%{version} or later, at this point). If you are hosted by CozyCloud, this should be already installed for you and this is an error; please let the CozyCloud administrators know about this by sending an email to contact@cozycloud.cc. If you are self-hosted, you'll need to install Weboob as described in the README file: `
},
datepicker: {
......
......@@ -356,8 +356,8 @@ module.exports = {
},
weboobinstallreadme: {
title: 'Il vous manque Weboob en version 1.1 ou supérieure',
content: `Afin de fonctionner, Kresus a besoin d'une dépendance unique, Weboob. Pour vous offrir la meilleure expérience possible, il est nécessaire que Weboob soit installé en version stable ou expérimentale (1.1 à ce jour). Si vous êtes hébergé⋅e par CozyCloud, cela devrait déjà avoir été installé pour vous et c'est une erreur ; merci de contacter un administrateur de CozyCloud pour leur en faire part sur contact@cozycloud.cc. Si vous êtes auto-hébergé⋅e, vous devriez installer Weboob manuellement, comme indiqué dans le fichier lisezmoi : `
title: 'Veuillez installer Weboob en version %{version} ou supérieure',
content: `Afin de fonctionner, Kresus a besoin d'une dépendance unique, Weboob. Pour vous offrir la meilleure expérience possible, il est nécessaire que Weboob soit installé en version stable ou expérimentale (%{version} à ce jour). Si vous êtes hébergé⋅e par CozyCloud, cela devrait déjà avoir été installé pour vous et c'est une erreur ; merci de contacter un administrateur de CozyCloud pour leur en faire part sur contact@cozycloud.cc. Si vous êtes auto-hébergé⋅e, vous devriez installer Weboob manuellement, comme indiqué dans le fichier lisezmoi : `
},
datepicker: {
......
import should from 'should';
import { normalizeVersion } from '../client/helpers';
describe('normalizeVersion', () => {
it ('0 should become 0.0.0', () => {
normalizeVersion(0).should.equal('0.0.0');
});
it ('0.1 should become 0.1.0', () => {
normalizeVersion(0.1).should.equal('0.1.0');
});
it ('1 should become 1.0.0', () => {
normalizeVersion('1').should.equal('1.0.0');
});
it ('1.1.1.1 should become 1.1.1', () => {
normalizeVersion('1.1.1.1').should.equal('1.1.1');
});
it ('1.1.1 should be unchanged', () => {
normalizeVersion('1.1.1').should.equal('1.1.1');
});
it ('0.h should become 0.0.0', () => {
normalizeVersion('0.h').should.equal('0.0.0');
});
it ('1.2.4-beta.0 should be unchanged', () => {
normalizeVersion('1.2.4-beta.0').should.equal('1.2.4-beta.0');
});
it ('1.2.4-beta should be unchanged', () => {
normalizeVersion('1.2.4-beta').should.equal('1.2.4-beta');
});
});
Supports Markdown
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