mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
refs: https://github.com/TryGhost/Team/issues/1625 - Ensure that we maintain a list of exactly which settings can be edited - Bypass this for internal settings changes for now - TODO: use the settingsBreadService internally instead of the api directly
91 lines
2.5 KiB
JavaScript
91 lines
2.5 KiB
JavaScript
const {notifications} = require('../../services/notifications');
|
|
const settingsService = require('../../services/settings/settings-service');
|
|
const settingsBREADService = settingsService.getSettingsBREADServiceInstance();
|
|
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,
|
|
async query(frame) {
|
|
const {allNotifications, notificationsToAdd} = notifications.add({
|
|
notifications: frame.data.notifications
|
|
});
|
|
|
|
if (notificationsToAdd.length){
|
|
return await settingsBREADService.edit([{
|
|
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
|
|
}
|
|
});
|
|
|
|
await settingsBREADService.edit([{
|
|
key: 'notifications',
|
|
value: allNotifications
|
|
}], internalContext);
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Clears all notifications. Method used in tests only
|
|
*
|
|
* @private Not exposed over HTTP
|
|
*/
|
|
destroyAll: {
|
|
statusCode: 204,
|
|
permissions: {
|
|
method: 'destroy'
|
|
},
|
|
async query() {
|
|
const allNotifications = notifications.destroyAll();
|
|
|
|
await settingsBREADService.edit([{
|
|
key: 'notifications',
|
|
value: allNotifications
|
|
}], internalContext);
|
|
}
|
|
}
|
|
};
|