diff --git a/core/server/data/default-settings.json b/core/server/data/default-settings.json
index 2365f796da..e7ca32564b 100644
--- a/core/server/data/default-settings.json
+++ b/core/server/data/default-settings.json
@@ -10,7 +10,7 @@
"defaultValue": null
},
"displayUpdateNotification": {
- "defaultValue": false
+ "defaultValue": null
}
},
"blog": {
diff --git a/core/server/helpers/index.js b/core/server/helpers/index.js
index 4d52d8dc0b..0e897c0a82 100644
--- a/core/server/helpers/index.js
+++ b/core/server/helpers/index.js
@@ -12,6 +12,7 @@ var downsize = require('downsize'),
filters = require('../filters'),
template = require('./template'),
schema = require('../data/schema').checks,
+ updateCheck = require('../update-check'),
assetTemplate = _.template('<%= source %>?v=<%= version %>'),
scriptTemplate = _.template(''),
@@ -569,8 +570,8 @@ coreHelpers.updateNotification = function () {
return when(output);
}
- return api.settings.read('displayUpdateNotification').then(function (display) {
- if (display && display.value && display.value === 'true') {
+ return updateCheck.showUpdateNotification().then(function (result) {
+ if (result) {
output = '
' +
'A new version of Ghost is available! Hot damn. ' +
'
Upgrade now ';
diff --git a/core/server/update-check.js b/core/server/update-check.js
index 3c8099f91c..94268f591a 100644
--- a/core/server/update-check.js
+++ b/core/server/update-check.js
@@ -31,10 +31,11 @@ var crypto = require('crypto'),
api = require('./api'),
config = require('./config'),
errors = require('./errorHandling'),
+ packageInfo = require('../../package.json'),
allowedCheckEnvironments = ['development', 'production'],
checkEndpoint = 'updates.ghost.org',
- currentVersion;
+ currentVersion = packageInfo.version;
function updateCheckError(error) {
errors.logError(
@@ -140,13 +141,12 @@ function updateCheckRequest() {
// 1. Updates the time we can next make a check
// 2. Checks if the version in the response is new, and updates the notification setting
function updateCheckResponse(response) {
- var ops = [],
- displayUpdateNotification = currentVersion && semver.gt(response.version, currentVersion);
+ var ops = [];
ops.push(api.settings.edit('nextUpdateCheck', response.next_check)
.otherwise(errors.rejectError));
- ops.push(api.settings.edit('displayUpdateNotification', displayUpdateNotification)
+ ops.push(api.settings.edit('displayUpdateNotification', response.version)
.otherwise(errors.rejectError));
return when.settle(ops).then(function (descriptors) {
@@ -159,7 +159,7 @@ function updateCheckResponse(response) {
});
}
-function updateCheck(res) {
+function updateCheck() {
var deferred = when.defer();
// The check will not happen if:
@@ -175,8 +175,7 @@ function updateCheck(res) {
// It's not time to check yet
deferred.resolve();
} else {
- // We need to do a check, store the current version
- currentVersion = res.locals.version;
+ // We need to do a check
return updateCheckRequest()
.then(updateCheckResponse)
.otherwise(updateCheckError);
@@ -188,4 +187,21 @@ function updateCheck(res) {
return deferred.promise;
}
+function showUpdateNotification() {
+ return api.settings.read('displayUpdateNotification').then(function (display) {
+ // Version 0.4 used boolean to indicate the need for an update. This special case is
+ // translated to the version string.
+ // TODO: remove in future version.
+ if (display.value === 'false' || display.value === 'true') {
+ display.value = '0.4.0';
+ }
+
+ if (display && display.value && currentVersion && semver.gt(display.value, currentVersion)) {
+ return when(true);
+ }
+ return when(false);
+ });
+}
+
module.exports = updateCheck;
+module.exports.showUpdateNotification = showUpdateNotification;
diff --git a/core/test/unit/server_helpers_index_spec.js b/core/test/unit/server_helpers_index_spec.js
index c04e956b6d..4c0fe070d0 100644
--- a/core/test/unit/server_helpers_index_spec.js
+++ b/core/test/unit/server_helpers_index_spec.js
@@ -1,19 +1,19 @@
/*globals describe, beforeEach, afterEach, it*/
-var testUtils = require('../utils'),
- should = require('should'),
- sinon = require('sinon'),
- when = require('when'),
- _ = require('underscore'),
- path = require('path'),
- rewire = require('rewire'),
- api = require('../../server/api'),
- hbs = require('express-hbs'),
-
+var testUtils = require('../utils'),
+ should = require('should'),
+ sinon = require('sinon'),
+ when = require('when'),
+ _ = require('underscore'),
+ path = require('path'),
+ rewire = require('rewire'),
+ api = require('../../server/api'),
+ hbs = require('express-hbs'),
+ packageInfo = require('../../../package'),
// Stuff we are testing
- handlebars = hbs.handlebars,
- helpers = rewire('../../server/helpers'),
- config = require('../../server/config');
+ handlebars = hbs.handlebars,
+ helpers = rewire('../../server/helpers'),
+ config = require('../../server/config');
describe('Core Helpers', function () {
@@ -939,14 +939,16 @@ describe('Core Helpers', function () {
});
});
describe('updateNotification', function () {
- it('outputs a correctly formatted notification when display is set to true', function (done) {
+ it('outputs a correctly formatted notification when db version is higher than package version', function (done) {
var output = '' +
'A new version of Ghost is available! Hot damn. ' +
'
Upgrade now ';
apiStub.restore();
apiStub = sandbox.stub(api.settings, 'read', function () {
- return when({value: 'true'});
+ var futureversion = packageInfo.version.split('.');
+ futureversion[futureversion.length-1] = parseInt(futureversion[futureversion.length-1], 10) + 1;
+ return when({value: futureversion.join('.')});
});
helpers.updateNotification.call({currentUser: {name: 'bob'}}).then(function (rendered) {
@@ -957,7 +959,12 @@ describe('Core Helpers', function () {
}).then(null, done);
});
- it('does NOT output a correctly formatted notification when display is not set to true', function (done) {
+ it('does NOT output a correctly formatted notification when db version equals package version', function (done) {
+ apiStub.restore();
+ apiStub = sandbox.stub(api.settings, 'read', function () {
+ return when({value: packageInfo.version});
+ });
+
helpers.updateNotification.call({currentUser: {name: 'bob'}}).then(function (rendered) {
should.exist(rendered);
rendered.should.equal('');
@@ -983,7 +990,9 @@ describe('Core Helpers', function () {
it('does NOT output a notification if the user is not logged in', function (done) {
apiStub.restore();
apiStub = sandbox.stub(api.settings, 'read', function () {
- return when({value: 'true'});
+ var futureversion = packageInfo.version.split('.');
+ futureversion[futureversion.length-1] = parseInt(futureversion[futureversion.length-1], 10) + 1;
+ return when({value: futureversion.join('.')});
});
helpers.updateNotification.call().then(function (rendered) {