mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-27 21:03:29 +03:00
478eb6ead6
refs https://github.com/TryGhost/Toolbox/issues/500 refs https://ghost.notion.site/Data-Types-e5dc54dd0078443f9afd6b2abda443c4 - There current notification logic for incompatible integrations did not take into account the source of the trigger, which might have been causing emails to instance owners that did not ever set up custom integration - so they had nothing to fix. - The "internal" and "core" integrations are maintained/controlled by the Ghost team, so there should never be a notification going out to the instance owner about possible incompatibility in the code they do not control. - Along with changed updated the unit test threshold in the packages that were touched to 100%. As that's the standard for all new packages.
78 lines
2.6 KiB
JavaScript
78 lines
2.6 KiB
JavaScript
const internalContext = {
|
|
internal: true
|
|
};
|
|
|
|
class VersionNotificationsDataService {
|
|
/**
|
|
* @param {Object} options
|
|
* @param {Object} options.UserModel - ghost user model
|
|
* @param {Object} options.ApiKeyModel - ghost api key model
|
|
* @param {Object} options.settingsService - ghost settings service
|
|
*/
|
|
constructor({UserModel, ApiKeyModel, settingsService}) {
|
|
this.UserModel = UserModel;
|
|
this.ApiKeyModel = ApiKeyModel;
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* This method is for internal use only.
|
|
*
|
|
* @param {String} key - api key identification value, it's "secret" in case of Content API key and "id" for Admin API
|
|
* @param {String} type - one of "content" or "admin" values
|
|
* @returns {Promise<Object>} Integration JSON object
|
|
*/
|
|
async getIntegration(key, type) {
|
|
let queryOptions = null;
|
|
|
|
if (type === 'content') {
|
|
queryOptions = {secret: key};
|
|
} else if (type === 'admin') {
|
|
queryOptions = {id: key};
|
|
}
|
|
|
|
const apiKey = await this.ApiKeyModel.findOne(queryOptions, {withRelated: ['integration']});
|
|
|
|
return apiKey.relations.integration.toJSON();
|
|
}
|
|
}
|
|
|
|
module.exports = VersionNotificationsDataService;
|