0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Added new member subscription settings (#11240)

no issue

We added 2 new member subscription settings - `allowSelfSignup` and `fromAddress`- with defaults as `true` and `noreply`, this migration sets default values for both settings for users migrating from previous version and cleans up intermediate naming for `allowSelfSignup`.
This commit is contained in:
Rishabh Garg 2019-10-14 16:58:15 +05:30 committed by GitHub
parent 84d40983d2
commit 1e9d4875f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,67 @@
const _ = require('lodash');
const Promise = require('bluebird');
const common = require('../../../../lib/common');
module.exports.config = {
transaction: true
};
module.exports.up = (options) => {
let localOptions = _.merge({
context: {internal: true}
}, options);
const settingsKey = 'members_subscription_settings';
return localOptions
.transacting('settings')
.then((response) => {
if (!response) {
common.logging.warn('Cannot find settings.');
return;
}
let subscriptionSettingsEntry = response.find((entry) => {
return entry.key === settingsKey;
});
if (!subscriptionSettingsEntry) {
common.logging.warn('Cannot find members subscription settings.');
return;
}
let subscriptionSettings = JSON.parse(subscriptionSettingsEntry.value);
let hasRequirePaymentProperty = Object.prototype.hasOwnProperty.call(subscriptionSettings, 'requirePaymentForSignup');
let hasSelfSignupProperty = Object.prototype.hasOwnProperty.call(subscriptionSettings, 'allowSelfSignup');
let hasFromAddressProperty = Object.prototype.hasOwnProperty.call(subscriptionSettings, 'fromAddress');
if (!hasFromAddressProperty) {
subscriptionSettings.fromAddress = 'noreply';
}
if (!hasRequirePaymentProperty && !hasSelfSignupProperty) {
subscriptionSettings.allowSelfSignup = true;
}
if (hasRequirePaymentProperty) {
if (!hasSelfSignupProperty) {
common.logging.info(`Adding allowSelfSignup property from requirePaymentForSignup in member settings`);
subscriptionSettings.allowSelfSignup = !subscriptionSettings.requirePaymentForSignup;
}
common.logging.info(`Removing requirePaymentForSignup property in member settings`);
delete subscriptionSettings.requirePaymentForSignup;
}
return localOptions
.transacting('settings')
.where('key', settingsKey)
.update({
value: JSON.stringify(subscriptionSettings)
});
});
};
// `up` only runs in order to normalize member subscription settings which was added
// no need for down migration as its non-breaking up migration for future versions only
module.exports.down = () => Promise.resolve();
module.exports.config = {
transaction: true
};