diff --git a/core/server/api/notifications.js b/core/server/api/notifications.js index c50d8944c8..6ee15c13f8 100644 --- a/core/server/api/notifications.js +++ b/core/server/api/notifications.js @@ -5,8 +5,10 @@ const Promise = require('bluebird'), _ = require('lodash'), + semver = require('semver'), moment = require('moment'), ObjectId = require('bson-objectid'), + ghostVersion = require('../lib/ghost-version'), pipeline = require('../lib/promise/pipeline'), permissions = require('../services/permissions'), localUtils = require('./utils'), @@ -63,6 +65,18 @@ notifications = { allNotifications = _.orderBy(allNotifications, 'addedAt', 'desc'); allNotifications = allNotifications.filter(function (notification) { + // CASE: do not return old release notification + if (!notification.custom && notification.message) { + let notificationVersion = notification.message.match(/(\d+\.)(\d+\.)(\d+)/); + let blogVersion = ghostVersion.full.match(/^(\d+\.)(\d+\.)(\d+)/); + + if (notificationVersion && blogVersion && semver.gt(notificationVersion[0], blogVersion[0])) { + return true; + } else { + return false; + } + } + return notification.seen !== true; }); diff --git a/core/test/functional/routes/api/notifications_spec.js b/core/test/functional/routes/api/notifications_spec.js index a3c821f537..ee1dd9f766 100644 --- a/core/test/functional/routes/api/notifications_spec.js +++ b/core/test/functional/routes/api/notifications_spec.js @@ -25,7 +25,8 @@ describe('Notifications API', function () { describe('Add', function () { var newNotification = { type: 'info', - message: 'test notification' + message: 'test notification', + custom: true }; it('creates a new notification', function (done) { @@ -59,7 +60,8 @@ describe('Notifications API', function () { var newNotification = { type: 'info', message: 'test notification', - status: 'alert' + status: 'alert', + custom: true }; it('deletes a notification', function (done) { diff --git a/core/test/integration/api/api_notifications_spec.js b/core/test/integration/api/api_notifications_spec.js index 38bcf506a2..75ec99dc41 100644 --- a/core/test/integration/api/api_notifications_spec.js +++ b/core/test/integration/api/api_notifications_spec.js @@ -108,7 +108,8 @@ describe('Notifications API', function () { it('can browse (internal)', function (done) { var msg = { type: 'error', // this can be 'error', 'success', 'warn' and 'info' - message: 'This is an error' // A string. Should fit in one line. + message: 'This is an error', // A string. Should fit in one line. + custom: true }; NotificationsAPI.add({notifications: [msg]}, testUtils.context.internal).then(function () { NotificationsAPI.browse(testUtils.context.internal).then(function (results) { @@ -124,7 +125,8 @@ describe('Notifications API', function () { it('can browse (owner)', function (done) { var msg = { type: 'error', // this can be 'error', 'success', 'warn' and 'info' - message: 'This is an error' // A string. Should fit in one line. + message: 'This is an error', // A string. Should fit in one line. + custom: true }; NotificationsAPI.add({notifications: [msg]}, testUtils.context.owner).then(function () { NotificationsAPI.browse(testUtils.context.owner).then(function (results) { diff --git a/core/test/integration/update_check_spec.js b/core/test/integration/update_check_spec.js index 889d08c815..a3994c7cf6 100644 --- a/core/test/integration/update_check_spec.js +++ b/core/test/integration/update_check_spec.js @@ -9,13 +9,15 @@ var _ = require('lodash'), configUtils = require('../utils/configUtils'), packageInfo = require('../../../package'), updateCheck = rewire('../../server/update-check'), + ghostVersion = rewire('../../server/lib/ghost-version'), SettingsAPI = require('../../server/api/settings'), - NotificationsAPI = require('../../server/api/notifications'), + NotificationsAPI = rewire('../../server/api/notifications'), sandbox = sinon.sandbox.create(); describe('Update Check', function () { beforeEach(function () { updateCheck = rewire('../../server/update-check'); + NotificationsAPI = rewire('../../server/api/notifications'); }); afterEach(function () { @@ -168,6 +170,8 @@ describe('Update Check', function () { }] }; + NotificationsAPI.__set__('ghostVersion.full', '0.8.1'); + createCustomNotification(notification).then(function () { return NotificationsAPI.browse(testUtils.context.internal); }).then(function (results) { @@ -187,6 +191,58 @@ describe('Update Check', function () { }).catch(done); }); + it('release notification version format is wrong', function (done) { + var createCustomNotification = updateCheck.__get__('createCustomNotification'), + notification = { + id: 1, + custom: 0, + messages: [{ + id: uuid.v4(), + version: '0.9.x', + content: '
Hey there! This is for 0.9 version
', + dismissible: true, + top: true + }] + }; + + NotificationsAPI.__set__('ghostVersion.full', '0.8.1'); + + createCustomNotification(notification).then(function () { + return NotificationsAPI.browse(testUtils.context.internal); + }).then(function (results) { + should.exist(results); + should.exist(results.notifications); + results.notifications.length.should.eql(0); + done(); + }).catch(done); + }); + + it('blog version format is wrong', function (done) { + var createCustomNotification = updateCheck.__get__('createCustomNotification'), + notification = { + id: 1, + custom: 0, + messages: [{ + id: uuid.v4(), + version: '0.9.x', + content: 'Hey there! This is for 0.9.0 version
', + dismissible: true, + top: true + }] + }; + + NotificationsAPI.__set__('ghostVersion.full', '0.8'); + + createCustomNotification(notification).then(function () { + return NotificationsAPI.browse(testUtils.context.internal); + }).then(function (results) { + should.exist(results); + should.exist(results.notifications); + results.notifications.length.should.eql(0); + done(); + }).catch(done); + }); + it('should create a custom notification', function (done) { var createCustomNotification = updateCheck.__get__('createCustomNotification'), notification = { diff --git a/core/test/utils/api.js b/core/test/utils/api.js index 00c90dd60f..7297082095 100644 --- a/core/test/utils/api.js +++ b/core/test/utils/api.js @@ -50,7 +50,7 @@ var _ = require('lodash'), accesstoken: _.keys(schema.accesstokens), role: _.keys(schema.roles), permission: _.keys(schema.permissions), - notification: ['type', 'message', 'status', 'id', 'dismissible', 'location'], + notification: ['type', 'message', 'status', 'id', 'dismissible', 'location', 'custom'], theme: ['name', 'package', 'active'], themes: ['themes'], invites: _(schema.invites).keys().without('token').value(),