mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
🐛 Fixed upgrade notification showing post-upgrade
closes https://github.com/TryGhost/Team/issues/564 refs https://github.com/TryGhost/Ghost/issues/10236 - The notification to upgrade to new 4.0 Ghost version was still visible to users after upgrading the instance to 4.0. This was caused by notification filtering not taking into account 3.x or 4.x versions. - The fix filters out notifications that detect a major version notification using `x.0 is now available` pattern and compares current version to that major. This should future proof the issue from happening in Ghost 5.0 (but a proper holistic fix is preferable!)
This commit is contained in:
parent
72602040d7
commit
4dc413d6a1
2 changed files with 77 additions and 16 deletions
|
@ -47,14 +47,15 @@ class Notifications {
|
|||
// after Ghost update. Logic below should be removed when Ghost upgrade detection
|
||||
// is done (https://github.com/TryGhost/Ghost/issues/10236) and notifications are
|
||||
// be removed permanently on upgrade event.
|
||||
const ghost20RegEx = /Ghost 2.0 is now available/gi;
|
||||
const ghostMajorRegEx = /Ghost (?<major>\d).0 is now available/gi;
|
||||
|
||||
// CASE: do not return old release notification
|
||||
if (notification.message && (!notification.custom || notification.message.match(ghost20RegEx))) {
|
||||
if (notification.message && (!notification.custom || notification.message.match(ghostMajorRegEx))) {
|
||||
let notificationVersion = notification.message.match(/(\d+\.)(\d+\.)(\d+)/);
|
||||
|
||||
if (notification.message.match(ghost20RegEx)) {
|
||||
notificationVersion = '2.0.0';
|
||||
const ghostMajorMatch = ghostMajorRegEx.exec(notification.message);
|
||||
if (ghostMajorMatch.groups.major) {
|
||||
notificationVersion = `${ghostMajorMatch.groups.major}.0.0`;
|
||||
} else if (notificationVersion){
|
||||
notificationVersion = notificationVersion[0];
|
||||
}
|
||||
|
|
|
@ -5,29 +5,28 @@ const Notifications = require('../../../../core/server/services/notifications/no
|
|||
const {owner} = require('../../../utils/fixtures/context');
|
||||
|
||||
describe('Notifications Service', function () {
|
||||
it('can browse version upgrade notifications notifications in Ghost v3', function () {
|
||||
it('can browse major version upgrade notifications notifications', function () {
|
||||
const settingsCache = {
|
||||
get: sinon.fake.returns([{
|
||||
dismissible: true,
|
||||
location: 'bottom',
|
||||
status: 'alert',
|
||||
id: '130f7c24-113a-4768-a698-12a8b34223f5',
|
||||
id: '130f7c24-113a-4768-a698-12a8b34223f6',
|
||||
custom: true,
|
||||
createdAt: '2021-03-16T12:55:20.000Z',
|
||||
type: 'info',
|
||||
top: true,
|
||||
message: `<strong>Ghost 4.0 is now available</strong> - You are using an old version of Ghost, which means you don't have access to the latest features. <a href=\'https://ghost.org/changelog/4/\' target=\'_blank\' rel=\'noopener\'>Read more!</a>`,
|
||||
message: `<strong>Ghost 5.0 is now available</strong> - You are using an old version of Ghost, which means you don't have access to the latest features. <a href=\'https://ghost.org/changelog/4/\' target=\'_blank\' rel=\'noopener\'>Read more!</a>`,
|
||||
seen: true,
|
||||
addedAt: '2021-03-17T01:41:20.906Z',
|
||||
seenBy: ['1']
|
||||
}
|
||||
])
|
||||
}])
|
||||
};
|
||||
|
||||
const notificationSvc = new Notifications({
|
||||
settingsCache,
|
||||
ghostVersion: {
|
||||
full: '3.0.0'
|
||||
full: '4.0.0'
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -37,23 +36,22 @@ describe('Notifications Service', function () {
|
|||
notifications.length.should.equal(1);
|
||||
});
|
||||
|
||||
it('cannot see 2.0 version upgrade notifications notifications in Ghost v3', function () {
|
||||
it('cannot see 2.0 version upgrade notifications notifications in Ghost 3.0', function () {
|
||||
const settingsCache = {
|
||||
get: sinon.fake.returns([{
|
||||
dismissible: true,
|
||||
location: 'bottom',
|
||||
status: 'alert',
|
||||
id: '130f7c24-113a-4768-a698-12a8b34223f5',
|
||||
id: '130f7c24-113a-4768-a698-12a8b34223f7',
|
||||
custom: true,
|
||||
createdAt: '2021-03-16T12:55:20.000Z',
|
||||
createdAt: '2020-03-16T12:55:20.000Z',
|
||||
type: 'info',
|
||||
top: true,
|
||||
message: `<strong>Ghost 2.0 is now available</strong> - You are using an old version of Ghost, which means you don't have access to the latest features.`,
|
||||
seen: true,
|
||||
addedAt: '2021-03-17T01:41:20.906Z',
|
||||
addedAt: '2020-03-17T01:41:20.906Z',
|
||||
seenBy: ['1']
|
||||
}
|
||||
])
|
||||
}])
|
||||
};
|
||||
|
||||
const notificationSvc = new Notifications({
|
||||
|
@ -68,4 +66,66 @@ describe('Notifications Service', function () {
|
|||
should.exist(notifications);
|
||||
notifications.length.should.equal(0);
|
||||
});
|
||||
|
||||
it('cannot see 4.0 version upgrade notifications notifications in Ghost 4.0', function () {
|
||||
const settingsCache = {
|
||||
get: sinon.fake.returns([{
|
||||
dismissible: true,
|
||||
location: 'bottom',
|
||||
status: 'alert',
|
||||
id: '130f7c24-113a-4768-a698-12a8b34223f8',
|
||||
custom: true,
|
||||
createdAt: '2021-03-16T12:55:20.000Z',
|
||||
type: 'info',
|
||||
top: true,
|
||||
message: `<strong>Ghost 4.0 is now available</strong> - You are using an old version of Ghost, which means you don't have access to the latest features.`,
|
||||
seen: true,
|
||||
addedAt: '2021-03-17T01:41:20.906Z',
|
||||
seenBy: ['1']
|
||||
}])
|
||||
};
|
||||
|
||||
const notificationSvc = new Notifications({
|
||||
settingsCache,
|
||||
ghostVersion: {
|
||||
full: '4.0.0'
|
||||
}
|
||||
});
|
||||
|
||||
const notifications = notificationSvc.browse({user: owner});
|
||||
|
||||
should.exist(notifications);
|
||||
notifications.length.should.equal(0);
|
||||
});
|
||||
|
||||
it('cannot see 5.0 version upgrade notifications notifications in Ghost 5.0', function () {
|
||||
const settingsCache = {
|
||||
get: sinon.fake.returns([{
|
||||
dismissible: true,
|
||||
location: 'bottom',
|
||||
status: 'alert',
|
||||
id: '130f7c24-113a-4768-a698-12a8b34223f9',
|
||||
custom: true,
|
||||
createdAt: '2022-03-16T12:55:20.000Z',
|
||||
type: 'info',
|
||||
top: true,
|
||||
message: `<strong>Ghost 5.0 is now available</strong> - You are using an old version of Ghost, which means you don't have access to the latest features.`,
|
||||
seen: true,
|
||||
addedAt: '2022-03-17T01:41:20.906Z',
|
||||
seenBy: ['1']
|
||||
}])
|
||||
};
|
||||
|
||||
const notificationSvc = new Notifications({
|
||||
settingsCache,
|
||||
ghostVersion: {
|
||||
full: '5.0.0'
|
||||
}
|
||||
});
|
||||
|
||||
const notifications = notificationSvc.browse({user: owner});
|
||||
|
||||
should.exist(notifications);
|
||||
notifications.length.should.equal(0);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue