0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Simplified Notification's service constructor

refs https://linear.app/tryghost/issue/CORE-64/resolve-undissmissable-update-notification-banners

- There's no need to pass a whole "version object" when all we need it a string in a full version format inside the module
This commit is contained in:
Naz 2021-10-11 15:55:02 +02:00
parent c0d59db5be
commit 1530cb28a5
3 changed files with 13 additions and 32 deletions

View file

@ -5,6 +5,6 @@ const models = require('../../models');
module.exports.notifications = new Notifications({
settingsCache,
ghostVersion,
ghostVersion: ghostVersion.full,
SettingsModel: models.Settings
});

View file

@ -16,8 +16,7 @@ class Notifications {
*
* @param {Object} options
* @param {Object} options.settingsCache - settings cache instance
* @param {Object} options.ghostVersion
* @param {String} options.ghostVersion.full - Ghost instance version in "full" format - major.minor.patch
* @param {String} options.ghostVersion - Ghost instance version in "full" format - major.minor.patch
* @param {Object} options.SettingsModel - Ghost's Setting model instance
*/
constructor({settingsCache, ghostVersion, SettingsModel}) {
@ -75,7 +74,7 @@ class Notifications {
browse({user}) {
let allNotifications = this.fetchAllNotifications();
allNotifications = _.orderBy(allNotifications, 'addedAt', 'desc');
const blogVersion = this.ghostVersion.full.match(/^(\d+\.)(\d+\.)(\d+)/);
const blogVersion = this.ghostVersion.match(/^(\d+\.)(\d+\.)(\d+)/);
allNotifications = allNotifications.filter((notification) => {
if (notification.createdAtVersion && !this.wasSeen(notification, user)) {
@ -129,7 +128,7 @@ class Notifications {
location: 'bottom',
status: 'alert',
id: ObjectId().toHexString(),
createdAtVersion: this.ghostVersion.full
createdAtVersion: this.ghostVersion
};
const overrides = {

View file

@ -15,9 +15,7 @@ describe('Notifications Service', function () {
const notificationsSvc = new Notifications({
settingsCache,
ghostVersion: {
full: '4.1.0'
}
ghostVersion: '4.1.0'
});
const {allNotifications, notificationsToAdd} = notificationsSvc.add({
@ -64,9 +62,7 @@ describe('Notifications Service', function () {
const notificationSvc = new Notifications({
settingsCache,
ghostVersion: {
full: '4.1.0'
}
ghostVersion: '4.1.0'
});
const notifications = notificationSvc.browse({user: owner});
@ -95,9 +91,7 @@ describe('Notifications Service', function () {
const notificationSvc = new Notifications({
settingsCache,
ghostVersion: {
full: '4.0.0'
}
ghostVersion: '4.0.0'
});
const notifications = notificationSvc.browse({user: owner});
@ -126,9 +120,7 @@ describe('Notifications Service', function () {
const notificationSvc = new Notifications({
settingsCache,
ghostVersion: {
full: '3.0.0'
}
ghostVersion: '3.0.0'
});
const notifications = notificationSvc.browse({user: owner});
@ -157,9 +149,7 @@ describe('Notifications Service', function () {
const notificationSvc = new Notifications({
settingsCache,
ghostVersion: {
full: '4.0.0'
}
ghostVersion: '4.0.0'
});
const notifications = notificationSvc.browse({user: owner});
@ -188,9 +178,7 @@ describe('Notifications Service', function () {
const notificationSvc = new Notifications({
settingsCache,
ghostVersion: {
full: '5.0.0'
}
ghostVersion: '5.0.0'
});
const notifications = notificationSvc.browse({user: owner});
@ -232,9 +220,7 @@ describe('Notifications Service', function () {
const notificationSvc = new Notifications({
settingsCache,
ghostVersion: {
full: '4.1.0'
}
ghostVersion: '4.1.0'
});
const notifications = notificationSvc.browse({user: owner});
@ -257,9 +243,7 @@ describe('Notifications Service', function () {
const notificationSvc = new Notifications({
settingsCache,
ghostVersion: {
full: '5.0.0'
},
ghostVersion: '5.0.0',
SettingsModel: {
edit: settingsModelStub
}
@ -287,9 +271,7 @@ describe('Notifications Service', function () {
const notificationSvc = new Notifications({
settingsCache,
ghostVersion: {
full: '5.0.0'
},
ghostVersion: '5.0.0',
SettingsModel: {
edit: settingsModelStub
}