48c7c9b73a
refs https://github.com/TryGhost/Toolbox/issues/292 - The version notification data service serves as data manger for version compatibility service - There's not much logic mostly fetching data from proficed services and filtering/serializing it into a needed format
50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
const internalContext = {
|
|
internal: true
|
|
};
|
|
|
|
class VersionNotificationsDataService {
|
|
constructor({UserModel, settingsService}) {
|
|
this.UserModel = UserModel;
|
|
this.settingsService = settingsService;
|
|
}
|
|
|
|
async fetchNotification(acceptVersion) {
|
|
const setting = await this.settingsService.read('version_notifications', internalContext);
|
|
const versionNotifications = JSON.parse(setting.version_notifications.value);
|
|
|
|
return versionNotifications.find(version => version === acceptVersion);
|
|
}
|
|
|
|
async saveNotification(acceptVersion) {
|
|
const setting = await this.settingsService.read('version_notifications', internalContext);
|
|
const versionNotifications = JSON.parse(setting.version_notifications.value);
|
|
|
|
if (!versionNotifications.find(version => version === acceptVersion)) {
|
|
versionNotifications.push(acceptVersion);
|
|
|
|
return this.settingsService.edit([{
|
|
key: 'version_notifications',
|
|
value: JSON.stringify(versionNotifications)
|
|
}], {
|
|
context: internalContext
|
|
});
|
|
}
|
|
}
|
|
|
|
async getNotificationEmails() {
|
|
const data = await this.UserModel.findAll(Object.assign({
|
|
withRelated: ['roles'],
|
|
filter: 'status:active'
|
|
}, internalContext));
|
|
|
|
const adminEmails = data
|
|
.toJSON()
|
|
.filter(user => ['Owner', 'Administrator'].includes(user.roles[0].name))
|
|
.map(user => user.email);
|
|
|
|
return adminEmails;
|
|
}
|
|
}
|
|
|
|
module.exports = VersionNotificationsDataService;
|