0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-01 02:41:39 -05:00

Added dynamic fields isEnabled/isConfig on bulk email settings

no issue

Adds 2 new dynamic calculated fields on bulk email settings -

`isEnabled` - If mailgun is configured either with config or admin settings
`isConfig` - If mail is configured via config directly
This commit is contained in:
Rish 2019-11-13 09:21:33 +05:30 committed by Rishabh Garg
parent 572e56f90a
commit 05e9f01f30
2 changed files with 21 additions and 15 deletions

View file

@ -49,6 +49,12 @@ module.exports = {
if (['cover_image', 'icon', 'logo'].includes(setting.key)) {
setting = url.forSetting(setting);
}
//CASE: Ensure we don't store calculated fields `isEnabled/Config` in bulk email settings
if (setting.key === 'bulk_email_settings') {
const {apiKey, domain, baseUrl, provider} = setting.value ? JSON.parse(setting.value) : '';
setting.value = JSON.stringify({apiKey, domain, baseUrl, provider});
}
});
// CASE: deprecated, won't accept

View file

@ -140,22 +140,22 @@ const action = (attrs) => {
};
const settings = (attrs) => {
// We don't send mail provider API key in settings API if set in config
if (_.isArray(attrs)) {
const membersSubscriptionSettingsObj = attrs.find(({key}) => {
return key === 'members_subscription_settings';
}) || {};
const membersSubscriptionSettings = membersSubscriptionSettingsObj.value;
if (membersSubscriptionSettings && config.get('mailgunApiKey')) {
let membersSubscriptionSettingsJson = JSON.parse(membersSubscriptionSettings);
delete membersSubscriptionSettingsJson.mailgunApiKey;
delete membersSubscriptionSettingsJson.mailgunDomain;
attrs.forEach((attr) => {
if (attr.key === 'members_subscription_settings') {
attr.value = JSON.stringify(membersSubscriptionSettingsJson);
}
});
}
attrs.forEach((attr) => {
if (attr.key === 'bulk_email_settings') {
let {provider, apiKey, domain, baseUrl} = attr.value ? JSON.parse(attr.value) : {};
const bulkEmailConfig = config.get('bulkEmail');
const hasMailgunConfig = !!(bulkEmailConfig && bulkEmailConfig.mailgun);
const hasMailgunSetting = !!(apiKey && baseUrl && domain);
attr.value = JSON.stringify({
provider, apiKey, domain, baseUrl,
isEnabled: (hasMailgunConfig || hasMailgunSetting),
isConfig: hasMailgunConfig
});
}
});
}
};