2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Complete moveover to new Notification API format

fixes #2775
- Fix all occurences of notifications.add to use proper API format
This commit is contained in:
Fabian Becker 2014-06-16 05:24:19 +00:00
parent 4227508c20
commit 2bff35bcc2
7 changed files with 48 additions and 39 deletions

View file

@ -3,6 +3,7 @@
var when = require('when'),
_ = require('lodash'),
errors = require('../errors'),
utils = require('./utils'),
// Holds the persistent notifications
notificationsStore = [],
@ -73,31 +74,39 @@ notifications = {
*
* **takes:** a notification object of the form
* ```
* msg = {
* msg = { notifications: [{
* type: 'error', // this can be 'error', 'success', 'warn' and 'info'
* message: 'This is an error', // A string. Should fit in one line.
* location: 'bottom', // A string where this notification should appear. can be 'bottom' or 'top'
* dismissable: true // A Boolean. Whether the notification is dismissable or not.
* };
* }] };
* ```
*/
add: function add(notification) {
add: function add(object) {
var defaults = {
dismissable: true,
location: 'bottom',
status: 'persistent'
};
dismissable: true,
location: 'bottom',
status: 'persistent'
},
addedNotifications = [];
notificationCounter = notificationCounter + 1;
notification = _.assign(defaults, notification, {
id: notificationCounter
//status: 'persistent'
return utils.checkObject(object, 'notifications').then(function (checkedNotificationData) {
_.each(checkedNotificationData.notifications, function (notification) {
notificationCounter = notificationCounter + 1;
notification = _.assign(defaults, notification, {
id: notificationCounter
//status: 'persistent'
});
notificationsStore.push(notification);
addedNotifications.push(notification);
});
return when({ notifications: addedNotifications});
});
notificationsStore.push(notification);
return when({ notifications: [notification]});
}
};

View file

@ -149,7 +149,7 @@ adminControllers = {
errors.logError(err, 'admin.js', "Your export file could not be generated.");
return api.notifications.add(notification).then(function () {
return api.notifications.add({ notifications: [notification]}).then(function () {
res.redirect(config().paths.subdir + '/ghost/debug');
});
});
@ -190,7 +190,7 @@ adminControllers = {
status: 'passive'
};
return api.notifications.add(notification).then(function () {
return api.notifications.add({ notifications: [notification] }).then(function () {
res.redirect(config().paths.subdir + '/ghost/signin/');
});
},
@ -220,7 +220,7 @@ adminControllers = {
errorMessage = 'There was a problem logging out. Please try again.';
}
return api.notifications.add(notification).then(function () {
return api.notifications.add({ notifications: [notification] }).then(function () {
res.json(statusCode, {error: errorMessage, redirect: redirectUrl});
});
@ -408,7 +408,7 @@ adminControllers = {
status: 'passive'
};
return api.notifications.add(notification).then(function () {
return api.notifications.add({ notifications: [notification] }).then(function () {
res.json(200, {redirect: config().paths.subdir + '/ghost/signin/'});
});
@ -444,7 +444,7 @@ adminControllers = {
errors.logError(err, 'admin.js', "Please check the provided token for validity and expiration.");
return api.notifications.add(notification).then(function () {
return api.notifications.add({ notifications: [notification] }).then(function () {
res.redirect(config().paths.subdir + '/ghost/forgotten');
});
});
@ -464,7 +464,7 @@ adminControllers = {
status: 'passive'
};
return api.notifications.add(notification).then(function () {
return api.notifications.add({ notifications: [notification] }).then(function () {
res.json(200, {redirect: config().paths.subdir + '/ghost/signin/'});
});
}).otherwise(function (err) {

View file

@ -44,10 +44,10 @@ function doFirstRun() {
'See <a href="http://docs.ghost.org/">http://docs.ghost.org</a> for instructions.'
];
return api.notifications.add({
return api.notifications.add({ notifications: [{
type: 'info',
message: firstRunMessage.join(' ')
});
}] });
}
function initDbHashAndFirstRun() {
@ -169,23 +169,23 @@ function ghostStartMessages() {
// in the future apps will want to hook into here
function initNotifications() {
if (mailer.state && mailer.state.usingSendmail) {
api.notifications.add({
api.notifications.add({ notifications: [{
type: 'info',
message: [
"Ghost is attempting to use your server's <b>sendmail</b> to send e-mail.",
"It is recommended that you explicitly configure an e-mail service,",
"See <a href=\"http://docs.ghost.org/mail\">http://docs.ghost.org/mail</a> for instructions"
].join(' ')
});
}] });
}
if (mailer.state && mailer.state.emailDisabled) {
api.notifications.add({
api.notifications.add({ notifications: [{
type: 'warn',
message: [
"Ghost is currently unable to send e-mail.",
"See <a href=\"http://docs.ghost.org/mail\">http://docs.ghost.org/mail</a> for instructions"
].join(' ')
});
}] });
}
}

View file

@ -77,7 +77,7 @@ var middleware = {
};
// let's only add the notification once
if (!_.contains(_.pluck(notifications, 'id'), 'failedauth')) {
api.notifications.add(msg);
api.notifications.add({ notifications: [msg] });
}
redirect = '?r=' + encodeURIComponent(reqPath);
}

View file

@ -85,7 +85,7 @@ describe('Notifications API', function () {
it('creates a new notification', function (done) {
request.post(testUtils.API.getApiQuery('notifications/'))
.set('X-CSRF-Token', csrfToken)
.send(newNotification)
.send({ notifications: [newNotification] })
.expect(201)
.end(function (err, res) {
if (err) {
@ -118,7 +118,7 @@ describe('Notifications API', function () {
// create the notification that is to be deleted
request.post(testUtils.API.getApiQuery('notifications/'))
.set('X-CSRF-Token', csrfToken)
.send(newNotification)
.send({ notifications: [newNotification] })
.expect(201)
.end(function (err, res) {
if (err) {

View file

@ -35,7 +35,7 @@ describe('Notifications API', function () {
type: 'error', // this can be 'error', 'success', 'warn' and 'info'
message: 'This is an error', // A string. Should fit in one line.
};
NotificationsAPI.add(msg).then(function (notification) {
NotificationsAPI.add({ notifications: [msg] }).then(function (notification) {
NotificationsAPI.browse().then(function (results) {
should.exist(results);
should.exist(results.notifications);
@ -52,7 +52,7 @@ describe('Notifications API', function () {
message: 'Hello, this is dog'
};
NotificationsAPI.add(msg).then(function (result) {
NotificationsAPI.add({ notifications: [msg] }).then(function (result) {
var notification;
should.exist(result);
@ -74,7 +74,7 @@ describe('Notifications API', function () {
id: 99
};
NotificationsAPI.add(msg).then(function (result) {
NotificationsAPI.add({ notifications: [msg] }).then(function (result) {
var notification;
should.exist(result);
@ -96,7 +96,7 @@ describe('Notifications API', function () {
message: 'Goodbye, cruel world!'
};
NotificationsAPI.add(msg).then(function (result) {
NotificationsAPI.add({ notifications: [msg] }).then(function (result) {
var notification = result.notifications[0];
NotificationsAPI.destroy({ id: notification.id }).then(function (result) {

View file

@ -121,22 +121,22 @@ describe('Middleware', function () {
describe('cleanNotifications', function () {
beforeEach(function (done) {
api.notifications.add({
api.notifications.add({ notifications: [{
id: 0,
status: 'passive',
message: 'passive-one'
}).then(function () {
return api.notifications.add({
}] }).then(function () {
return api.notifications.add({ notifications: [{
id: 1,
status: 'passive',
message: 'passive-two'
});
}] });
}).then(function () {
return api.notifications.add({
return api.notifications.add({ notifications: [{
id: 2,
status: 'aggressive',
message: 'aggressive'
});
}] });
}).then(function () {
done();
}).catch(done);