mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 17:32:15 +03:00
a7dec233ba
refs https://github.com/TryGhost/Team/issues/754 - This is fixing the root cause of an error being saved in `settings` table under `notifications` key. There needs to be a follow up to this fixing any possible instances that might have been affected byt the bug
97 lines
2.6 KiB
JavaScript
97 lines
2.6 KiB
JavaScript
const {notifications} = require('../../services/notifications');
|
|
const api = require('./index');
|
|
const internalContext = {context: {internal: true}};
|
|
|
|
module.exports = {
|
|
docName: 'notifications',
|
|
|
|
browse: {
|
|
permissions: true,
|
|
query(frame) {
|
|
return notifications.browse({
|
|
user: {
|
|
id: frame.user && frame.user.id
|
|
}
|
|
});
|
|
}
|
|
},
|
|
|
|
add: {
|
|
statusCode(result) {
|
|
if (result.notifications.length) {
|
|
return 201;
|
|
} else {
|
|
return 200;
|
|
}
|
|
},
|
|
permissions: true,
|
|
query(frame) {
|
|
const {allNotifications, notificationsToAdd} = notifications.add({
|
|
notifications: frame.data.notifications
|
|
});
|
|
|
|
if (notificationsToAdd.length){
|
|
return api.settings.edit({
|
|
settings: [{
|
|
key: 'notifications',
|
|
// @NOTE: We always need to store all notifications!
|
|
value: allNotifications.concat(notificationsToAdd)
|
|
}]
|
|
}, internalContext).then(() => {
|
|
return notificationsToAdd;
|
|
});
|
|
}
|
|
}
|
|
},
|
|
|
|
destroy: {
|
|
statusCode: 204,
|
|
options: ['notification_id'],
|
|
validation: {
|
|
options: {
|
|
notification_id: {
|
|
required: true
|
|
}
|
|
}
|
|
},
|
|
permissions: true,
|
|
async query(frame) {
|
|
const allNotifications = await notifications.destroy({
|
|
notificationId: frame.options.notification_id,
|
|
user: {
|
|
id: frame.user && frame.user.id
|
|
}
|
|
});
|
|
|
|
return api.settings.edit({
|
|
settings: [{
|
|
key: 'notifications',
|
|
value: allNotifications
|
|
}]
|
|
}, internalContext).return();
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Clears all notifications. Method used in tests only
|
|
*
|
|
* @private Not exposed over HTTP
|
|
*/
|
|
destroyAll: {
|
|
statusCode: 204,
|
|
permissions: {
|
|
method: 'destroy'
|
|
},
|
|
query() {
|
|
const allNotifications = notifications.destroyAll();
|
|
|
|
return api.settings.edit({
|
|
settings: [{
|
|
key: 'notifications',
|
|
value: allNotifications
|
|
}]
|
|
}, internalContext).return();
|
|
}
|
|
}
|
|
};
|