mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-08 02:52:39 -05: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:
parent
f3b4a538af
commit
9df217b04e
5 changed files with 86 additions and 1 deletions
|
@ -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();
|
||||
}
|
||||
};
|
|
@ -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": {
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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'},
|
||||
|
|
|
@ -50,6 +50,9 @@ const defaultSettingsKeys = [
|
|||
'portal_button',
|
||||
'portal_plans',
|
||||
'bulk_email_settings',
|
||||
'mailgun_api_key',
|
||||
'mailgun_domain',
|
||||
'mailgun_base_url',
|
||||
'amp',
|
||||
'labs',
|
||||
'slack',
|
||||
|
|
Loading…
Add table
Reference in a new issue