Skip to content
Snippets Groups Projects
Commit e12da924 authored by Tom Robinson's avatar Tom Robinson
Browse files

Check that version is equal to or newer than latest published version. Resolves #3658

parent 9b9309ce
Branches
Tags
No related merge requests found
import React, { Component, PropTypes } from "react";
import MetabaseSettings from "metabase/lib/settings";
import MetabaseUtils from "metabase/lib/utils";
import SettingsSetting from "./SettingsSetting.jsx";
import _ from "underscore";
......@@ -68,7 +69,7 @@ export default class SettingsUpdatesForm extends Component {
*/
if (!versionInfo || currentVersion === versionInfo.latest.version) {
if (!versionInfo || MetabaseUtils.compareVersions(currentVersion, versionInfo.latest.version) >= 0) {
return (
<div className="p2 bg-brand bordered rounded border-brand text-white text-bold">
You're running Metabase {this.removeVersionPrefixIfNeeded(currentVersion)} which is the latest and greatest!
......
......@@ -66,6 +66,42 @@ var MetabaseUtils = {
copy: function(a) {
return JSON.parse(JSON.stringify(a));
},
// this should correctly compare all version formats Metabase uses, e.x.
// 0.0.9, 0.0.10-snapshot, 0.0.10-alpha1, 0.0.10-rc1, 0.0.10-rc2, 0.0.10-rc10
// 0.0.10, 0.1.0, 0.2.0, 0.10.0, 1.1.0
compareVersions: function(aVersion, bVersion) {
const SPECIAL_COMPONENTS = {
"snapshot": -4,
"alpha": -3,
"beta": -2,
"rc": -1,
};
const getComponents = (x) =>
// v1.2.3-BETA1
x.toLowerCase()
// v1.2.3-beta1
.replace(/^v/, "")
// 1.2.3-beta1
.split(/[.-]*([0-9]+)[.-]*/).filter(c => c)
// ["1", "2", "3", "beta", "1"]
.map(c => SPECIAL_COMPONENTS[c] || parseInt(c, 10));
// [1, 2, 3, -2, 1]
let aComponents = getComponents(aVersion);
let bComponents = getComponents(bVersion);
for (let i = 0; i < Math.max(aComponents.length, bComponents.length); i++) {
let a = aComponents[i];
let b = bComponents[i];
if (b == undefined || a < b) {
return -1;
} else if (a == undefined || b < a) {
return 1;
}
}
return 0;
}
}
......
......@@ -51,4 +51,33 @@ describe('utils', () => {
);
});
});
describe("compareVersions", () => {
fit ("should compare versions correctly", () => {
let expected = [
"0.0.9",
"0.0.10-snapshot",
"0.0.10-alpha1",
"0.0.10-rc1",
"0.0.10-rc2",
"0.0.10-rc10",
"0.0.10",
"0.1.0",
"0.2.0",
"0.10.0",
"1.1.0"
];
let shuffled = expected.slice();
shuffle(shuffled);
shuffled.sort(MetabaseUtils.compareVersions);
expect(shuffled).toEqual(expected);
})
})
});
function shuffle(a) {
for (let i = a.length; i; i--) {
let j = Math.floor(Math.random() * i);
[a[i - 1], a[j]] = [a[j], a[i - 1]];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment