2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Added mailgun_{domain,api_key,base_url} settings (#11992)

refs #10318

 - Adds new default settings
 - Adds migration for populating settings with bulk_email_settings data
 - Fixes regression tests
This commit is contained in:
Fabien 'egg' O'Carroll 2020-07-03 11:00:20 +02:00 committed by GitHub
parent f3b4a538af
commit 9df217b04e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 86 additions and 1 deletions

View file

@ -0,0 +1,64 @@
const logging = require('../../../../../shared/logging');
module.exports = {
config: {
transaction: true
},
async up({transacting: knex}) {
const defaultValue = {
provider: 'mailgun',
apiKey: null,
domain: null,
baseUrl: null
};
const bulkEmailSettingsJSON = await knex('settings').where({
key: 'bulk_email_settings'
}).select().first();
let bulkEmailSettings;
try {
bulkEmailSettings = JSON.parse(bulkEmailSettingsJSON.value) || defaultValue;
} catch (err) {
logging.warn(`Error parsing bulk_email_settings JSON. Using defaults`);
bulkEmailSettings = defaultValue;
}
const operations = [{
key: 'mailgun_api_key',
value: bulkEmailSettings.apiKey
}, {
key: 'mailgun_domain',
value: bulkEmailSettings.domain
}, {
key: 'mailgun_base_url',
value: bulkEmailSettings.baseUrl
}];
for (const operation of operations) {
logging.info(`Updating ${operation.key} setting's value, group, type & flags.`);
await knex('settings')
.where({
key: operation.key
})
.update({
group: 'email',
type: 'string',
flags: null,
value: operation.value
});
}
},
async down({transacting: knex}) {
const settingsToDelete = [
'mailgun_api_key',
'mailgun_domain',
'mailgun_base_url'
];
logging.info(`Deleting settings: ${settingsToDelete.join(', ')}`);
await knex('settings').whereIn('key', settingsToDelete).del();
}
};

View file

@ -296,6 +296,18 @@
"bulk_email_settings": {
"defaultValue": "{\"provider\":\"mailgun\", \"apiKey\": \"\", \"domain\": \"\", \"baseUrl\": \"\"}",
"type": "object"
},
"mailgun_domain": {
"defaultValue": null,
"type": "string"
},
"mailgun_api_key": {
"defaultValue": null,
"type": "string"
},
"mailgun_base_url": {
"defaultValue": null,
"type": "string"
}
},
"amp": {

View file

@ -50,6 +50,9 @@ const defaultSettingsKeyTypes = [
{key: 'portal_button', type: 'portal'},
{key: 'portal_plans', type: 'portal'},
{key: 'bulk_email_settings', type: 'bulk_email'},
{key: 'mailgun_api_key', type: 'bulk_email'},
{key: 'mailgun_domain', type: 'bulk_email'},
{key: 'mailgun_base_url', type: 'bulk_email'},
{key: 'amp', type: 'blog'},
{key: 'labs', type: 'blog'},
{key: 'slack', type: 'blog'},
@ -95,7 +98,7 @@ describe('Settings API (canary)', function () {
for (const defaultSetting of defaultSettingsKeyTypes) {
should.exist(settings.find((setting) => {
return setting.key === defaultSetting.key && setting.type === defaultSetting.type;
}));
}), `Expected to find a setting with key ${defaultSetting.key} and type ${defaultSetting.type}`);
}
localUtils.API.checkResponse(jsonResponse, 'settings');

View file

@ -47,6 +47,9 @@ const defaultSettingsKeyTypes = [
{key: 'portal_button', type: 'portal'},
{key: 'portal_plans', type: 'portal'},
{key: 'bulk_email_settings', type: 'bulk_email'},
{key: 'mailgun_api_key', type: 'bulk_email'},
{key: 'mailgun_domain', type: 'bulk_email'},
{key: 'mailgun_base_url', type: 'bulk_email'},
{key: 'amp', type: 'blog'},
{key: 'labs', type: 'blog'},
{key: 'slack', type: 'blog'},

View file

@ -50,6 +50,9 @@ const defaultSettingsKeys = [
'portal_button',
'portal_plans',
'bulk_email_settings',
'mailgun_api_key',
'mailgun_domain',
'mailgun_base_url',
'amp',
'labs',
'slack',