mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-08 02:52:39 -05:00
Added filtering of outdated custom notifications
refs https://linear.app/tryghost/issue/CORE-64/resolve-undissmissable-update-notification-banners refs https://github.com/TryGhost/Team/issues/754 refs https://github.com/TryGhost/Team/issues/204 refs https://github.com/TryGhost/Ghost/issues/10236 - Custom notifications coming form the update check service should not be shown beyond instance's update. Once the notification is received it's marked with the current version number. With an instance upgrade all notification with older version should be hidden. - This improvement should also resolve the problem of major version notifications with next major update (the code associated with https://github.com/TryGhost/Ghost/issues/10236 can then be removed after 5.0.1)
This commit is contained in:
parent
d948be5bcb
commit
c0d59db5be
2 changed files with 79 additions and 28 deletions
|
@ -75,40 +75,45 @@ class Notifications {
|
|||
browse({user}) {
|
||||
let allNotifications = this.fetchAllNotifications();
|
||||
allNotifications = _.orderBy(allNotifications, 'addedAt', 'desc');
|
||||
const blogVersion = this.ghostVersion.full.match(/^(\d+\.)(\d+\.)(\d+)/);
|
||||
|
||||
allNotifications = allNotifications.filter((notification) => {
|
||||
// NOTE: Filtering by version below is just a patch for bigger problem - notifications are not removed
|
||||
// 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 ghostMajorRegEx = /Ghost (?<major>\d).0 is now available/gi;
|
||||
const ghostSec43 = /GHSA-9fgx-q25h-jxrg/gi;
|
||||
if (notification.createdAtVersion && !this.wasSeen(notification, user)) {
|
||||
return semver.gte(notification.createdAtVersion, blogVersion[0]);
|
||||
} else {
|
||||
// NOTE: Filtering by version below is just a patch for bigger problem - notifications are not removed
|
||||
// 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.
|
||||
// NOTE: this whole else block can be removed with the first version after Ghost v5.0
|
||||
// as the "createdAtVersion" mechanism will be enough to detect major version updates.
|
||||
const ghostMajorRegEx = /Ghost (?<major>\d).0 is now available/gi;
|
||||
const ghostSec43 = /GHSA-9fgx-q25h-jxrg/gi;
|
||||
|
||||
// CASE: do not return old release notification
|
||||
if (notification.message
|
||||
&& (!notification.custom || notification.message.match(ghostMajorRegEx) || notification.message.match(ghostSec43))) {
|
||||
let notificationVersion = notification.message.match(/(\d+\.)(\d+\.)(\d+)/);
|
||||
// CASE: do not return old release notification
|
||||
if (notification.message
|
||||
&& (!notification.custom || notification.message.match(ghostMajorRegEx) || notification.message.match(ghostSec43))) {
|
||||
let notificationVersion = notification.message.match(/(\d+\.)(\d+\.)(\d+)/);
|
||||
|
||||
if (!notificationVersion && notification.message.match(ghostSec43)) {
|
||||
// Treating "GHSA-9fgx-q25h-jxrg" notification as 4.3.3 because there's no way to detect version
|
||||
// from it's message. In the future we should consider having a separate field with version
|
||||
// coming with each notification
|
||||
notificationVersion = ['4.3.3'];
|
||||
}
|
||||
if (!notificationVersion && notification.message.match(ghostSec43)) {
|
||||
// Treating "GHSA-9fgx-q25h-jxrg" notification as 4.3.3 because there's no way to detect version
|
||||
// from it's message. In the future we should consider having a separate field with version
|
||||
// coming with each notification
|
||||
notificationVersion = ['4.3.3'];
|
||||
}
|
||||
|
||||
const ghostMajorMatch = ghostMajorRegEx.exec(notification.message);
|
||||
if (ghostMajorMatch && ghostMajorMatch.groups && ghostMajorMatch.groups.major) {
|
||||
notificationVersion = `${ghostMajorMatch.groups.major}.0.0`;
|
||||
} else if (notificationVersion){
|
||||
notificationVersion = notificationVersion[0];
|
||||
}
|
||||
const ghostMajorMatch = ghostMajorRegEx.exec(notification.message);
|
||||
if (ghostMajorMatch && ghostMajorMatch.groups && ghostMajorMatch.groups.major) {
|
||||
notificationVersion = `${ghostMajorMatch.groups.major}.0.0`;
|
||||
} else if (notificationVersion){
|
||||
notificationVersion = notificationVersion[0];
|
||||
}
|
||||
|
||||
const blogVersion = this.ghostVersion.full.match(/^(\d+\.)(\d+\.)(\d+)/);
|
||||
|
||||
if (notificationVersion && blogVersion && semver.gt(notificationVersion, blogVersion[0])) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
if (notificationVersion && blogVersion && semver.gt(notificationVersion, blogVersion[0])) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -198,6 +198,52 @@ describe('Notifications Service', function () {
|
|||
should.exist(notifications);
|
||||
notifications.length.should.equal(0);
|
||||
});
|
||||
|
||||
it('filters out outdated notifications', function () {
|
||||
const settingsCache = {
|
||||
get: sinon.fake.returns([{
|
||||
dismissible: true,
|
||||
custom: true,
|
||||
id: '130f7c24-113a-4768-a698-12a8b34223f1',
|
||||
type: 'info',
|
||||
message: 'too old to show',
|
||||
createdAt: '2021-03-16T12:55:20.000Z',
|
||||
addedAt: '2021-03-17T01:41:20.906Z',
|
||||
createdAtVersion: '4.0.1'
|
||||
}, {
|
||||
dismissible: true,
|
||||
custom: true,
|
||||
id: '130f7c24-113a-4768-a698-12a8b34223f2',
|
||||
type: 'info',
|
||||
message: 'should be visible',
|
||||
createdAt: '2021-03-16T12:55:20.000Z',
|
||||
addedAt: '2021-03-17T01:41:20.906Z',
|
||||
createdAtVersion: '4.1.0'
|
||||
}, {
|
||||
dismissible: true,
|
||||
custom: true,
|
||||
id: '130f7c24-113a-4768-a698-12a8b34223f2',
|
||||
type: 'info',
|
||||
message: 'visible even though without a created at property',
|
||||
createdAt: '2021-03-16T12:55:20.000Z',
|
||||
addedAt: '2021-03-17T01:41:20.906Z'
|
||||
}])
|
||||
};
|
||||
|
||||
const notificationSvc = new Notifications({
|
||||
settingsCache,
|
||||
ghostVersion: {
|
||||
full: '4.1.0'
|
||||
}
|
||||
});
|
||||
|
||||
const notifications = notificationSvc.browse({user: owner});
|
||||
|
||||
should.exist(notifications);
|
||||
notifications.length.should.equal(2);
|
||||
notifications[0].message.should.equal('should be visible');
|
||||
notifications[1].message.should.equal('visible even though without a created at property');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Stored notifications data corruption recovery', function () {
|
||||
|
|
Loading…
Add table
Reference in a new issue