Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Add v3.32.1
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickRe committed Sep 7, 2020
1 parent f1025f8 commit c50aaca
Show file tree
Hide file tree
Showing 26 changed files with 1,649 additions and 1,505 deletions.

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

42 changes: 31 additions & 11 deletions core/server/api/canary/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,39 @@ module.exports = {
}
},

validateMembersFromEmail: {
validateMembersEmailUpdate: {
options: [
'token'
'token',
'action'
],
permissions: false,
validation: {
options: {
token: {
required: true
},
action: {
values: ['fromaddressupdate', 'supportaddressupdate']
}
}
},
async query(frame) {
// This is something you have to do if you want to use the "framework" with access to the raw req/res
frame.response = async function (req, res) {
try {
const updatedFromAddress = membersService.settings.getEmailFromToken({token: frame.options.token});
if (updatedFromAddress) {
const {token, action} = frame.options;
const updatedEmailAddress = membersService.settings.getEmailFromToken({token});
const actionToKeyMapping = {
fromAddressUpdate: 'members_from_address',
supportAddressUpdate: 'members_support_address'
};
if (updatedEmailAddress) {
return models.Settings.edit({
key: 'members_from_address',
value: updatedFromAddress
key: actionToKeyMapping[action],
value: updatedEmailAddress
}).then(() => {
// Redirect to Ghost-Admin settings page
const adminLink = membersService.settings.getAdminRedirectLink();
const adminLink = membersService.settings.getAdminRedirectLink({type: action});
res.redirect(adminLink);
});
} else {
Expand All @@ -115,21 +124,32 @@ module.exports = {
}
},

updateMembersFromEmail: {
updateMembersEmail: {
permissions: {
method: 'edit'
},
data: [
'email',
'type'
],
async query(frame) {
const email = frame.data.from_address;
const {email, type} = frame.data;
if (typeof email !== 'string' || !validator.isEmail(email)) {
throw new BadRequestError({
message: i18n.t('errors.api.settings.invalidEmailReceived')
});
}

if (!type || !['fromAddressUpdate', 'supportAddressUpdate'].includes(type)) {
throw new BadRequestError({
message: 'Invalid email type recieved'
});
}
try {
// Send magic link to update fromAddress
await membersService.settings.sendFromAddressUpdateMagicLink({
email
await membersService.settings.sendEmailAddressUpdateMagicLink({
email,
type
});
} catch (err) {
throw new BadRequestError({
Expand Down
45 changes: 15 additions & 30 deletions core/server/api/shared/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,41 +101,26 @@ module.exports = {
* @param {Object} apiConfig
* @return {Promise}
*/
get(result, apiConfig = {}) {
async get(result, apiConfig = {}) {
let headers = {};

return Promise.resolve()
.then(() => {
let header;
if (apiConfig.disposition) {
const dispositionHeader = await disposition[apiConfig.disposition.type](result, apiConfig.disposition);

if (apiConfig.disposition) {
header = disposition[apiConfig.disposition.type](result, apiConfig.disposition);
}
if (dispositionHeader) {
Object.assign(headers, dispositionHeader);
}
}

return header;
})
.then((header) => {
if (header) {
Object.assign(headers, header);
}
})
.then(() => {
let header;
if (apiConfig.cacheInvalidate) {
const cacheInvalidationHeader = cacheInvalidate(result, apiConfig.cacheInvalidate);

if (apiConfig.cacheInvalidate) {
header = cacheInvalidate(result, apiConfig.cacheInvalidate);
}
if (cacheInvalidationHeader) {
Object.assign(headers, cacheInvalidationHeader);
}
}

return header;
})
.then((header) => {
if (header) {
Object.assign(headers, header);
}
})
.then(() => {
debug(headers);
return headers;
});
debug(headers);
return headers;
}
};
2 changes: 1 addition & 1 deletion core/server/data/importer/importers/data/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class SettingsImporter extends BaseImporter {
}

// CASE: we do not import "from address" for members settings as that needs to go via validation with magic link
if (obj.key === 'members_from_address') {
if ((obj.key === 'members_from_address') || (obj.key === 'members_support_address')) {
obj.value = null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const logging = require('../../../../../shared/logging');

module.exports = {
config: {
transaction: true
},

async up({transacting: knex}) {
const fromAddressSetting = await knex('settings')
.select('value')
.where('key', 'members_from_address')
.first();
const fromAddressValue = fromAddressSetting ? fromAddressSetting.value : 'noreply';
logging.info(`Updating members_support_address setting to members group with value ${fromAddressValue}`);
await knex('settings')
.update({
group: 'members',
flags: 'PUBLIC,RO',
value: fromAddressValue
})
.where({
key: 'members_support_address'
});
},

async down() {}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const logging = require('../../../../../shared/logging');

module.exports = {
config: {
transaction: true
},

async up({transacting: knex}) {
logging.info('Updating members_reply_address setting to members group');
await knex('settings')
.update({
group: 'members'
})
.where({
key: 'members_reply_address'
});
},

async down() {}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const logging = require('../../../../../shared/logging');
module.exports = {
config: {
transaction: true
},

async up({transacting: knex}) {
logging.info('Updating routes_hash to group: core, type: string, flags: null');

await knex('settings')
.update({
group: 'core',
type: 'string',
flags: null
})
.where('key', 'routes_hash');
},

async down() {}
};
17 changes: 17 additions & 0 deletions core/server/data/schema/default-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"defaultValue": null,
"type": "string"
},
"routes_hash": {
"defaultValue": null,
"type": "string"
},
"next_update_check": {
"defaultValue": null,
"type": "number"
Expand Down Expand Up @@ -241,6 +245,19 @@
"flags": "RO",
"type": "string"
},
"members_support_address": {
"defaultValue": "noreply",
"flags": "PUBLIC,RO",
"type": "string"
},
"members_reply_address": {
"defaultValue": "newsletter",
"validations": {
"isEmpty": false,
"isIn": [["newsletter", "support"]]
},
"type": "string"
},
"stripe_product_name": {
"defaultValue": "Ghost Subscription",
"type": "string"
Expand Down
5 changes: 5 additions & 0 deletions core/server/services/bulk-email/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ module.exports = {
}

const blogTitle = settingsCache.get('title') ? settingsCache.get('title').replace(/"/g, '\\"') : '';
let supportAddress = message.supportAddress;
delete message.supportAddress;
const replyAddressOption = settingsCache.get('members_reply_address');
const replyToAddress = (replyAddressOption === 'support') ? supportAddress : fromAddress;
fromAddress = blogTitle ? `"${blogTitle}"<${fromAddress}>` : fromAddress;

const chunkedRecipients = _.chunk(recipients, BATCH_SIZE);
Expand All @@ -94,6 +98,7 @@ module.exports = {
const batchData = {
to: toAddresses,
from: fromAddress,
'h:Reply-To': replyToAddress || fromAddress,
'recipient-variables': recipientVariables
};

Expand Down
1 change: 1 addition & 0 deletions core/server/services/mega/mega.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const getEmailData = async (postModel, memberModels = []) => {
const {emailTmpl, replacements} = await postEmailSerializer.serialize(postModel);

emailTmpl.from = membersService.config.getEmailFromAddress();
emailTmpl.supportAddress = membersService.config.getEmailSupportAddress();

// update templates to use Mailgun variable syntax for replacements
replacements.forEach((replacement) => {
Expand Down
2 changes: 1 addition & 1 deletion core/server/services/members/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function createApiInstance(config) {
logging.warn(message.text);
}
let msg = Object.assign({
from: config.getEmailFromAddress(),
from: config.getAuthEmailFromAddress(),
subject: 'Signin',
forceTextContent: true
}, message);
Expand Down
14 changes: 14 additions & 0 deletions core/server/services/members/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ class MembersConfigProvider {
return fromAddress;
}

getEmailSupportAddress() {
const supportAddress = this._settingsCache.get('members_support_address') || 'noreply';

// Any fromAddress without domain uses site domain, like default setting `noreply`
if (supportAddress.indexOf('@') < 0) {
return `${supportAddress}@${this._getDomain()}`;
}
return supportAddress;
}

getAuthEmailFromAddress() {
return this.getEmailSupportAddress() || this.getEmailFromAddress();
}

getPublicPlans() {
const CURRENCY_SYMBOLS = {
USD: '$',
Expand Down
2 changes: 2 additions & 0 deletions core/server/services/members/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ events.on('settings.edited', function updateSettingFromModel(settingModel) {
if (![
'members_allow_free_signup',
'members_from_address',
'members_support_address',
'members_reply_address',
'stripe_publishable_key',
'stripe_secret_key',
'stripe_product_name',
Expand Down
7 changes: 6 additions & 1 deletion core/server/services/members/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ const updateMemberData = async function (req, res) {
const data = _.pick(req.body, 'name', 'subscribed');
const member = await membersService.ssr.getMemberDataFromSession(req, res);
if (member) {
const updatedMember = await membersService.api.members.update(data, {id: member.id});
const options = {
id: member.id,
withRelated: ['stripeSubscriptions', 'stripeSubscriptions.customer']
};
const updatedMember = await membersService.api.members.update(data, options);

res.json(formattedMemberResponse(updatedMember.toJSON()));
} else {
res.json(null);
Expand Down
26 changes: 20 additions & 6 deletions core/server/services/members/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function createSettingsInstance(config) {
logging.warn(message.text);
}
let msg = Object.assign({
from: config.getEmailFromAddress(),
from: config.getAuthEmailFromAddress(),
subject: 'Update email address',
forceTextContent: true
}, message);
Expand Down Expand Up @@ -70,21 +70,35 @@ function createSettingsInstance(config) {
getSubject
});

const sendFromAddressUpdateMagicLink = ({email, payload = {}}) => {
return magicLinkService.sendMagicLink({email, payload, subject: email, type: 'updateFromAddress'});
const sendEmailAddressUpdateMagicLink = ({email, payload = {}, type = 'fromAddressUpdate'}) => {
magicLinkService.transporter = {
sendMail(message) {
if (process.env.NODE_ENV !== 'production') {
logging.warn(message.text);
}
let msg = Object.assign({
from: email,
subject: 'Update email address',
forceTextContent: true
}, message);

return ghostMailer.send(msg);
}
};
return magicLinkService.sendMagicLink({email, payload, subject: email, type});
};

const getEmailFromToken = ({token}) => {
return magicLinkService.getUserFromToken(token);
};

const getAdminRedirectLink = () => {
const getAdminRedirectLink = ({type}) => {
const adminUrl = urlUtils.urlFor('admin', true);
return urlUtils.urlJoin(adminUrl, '#/settings/labs/?fromAddressUpdate=success');
return urlUtils.urlJoin(adminUrl, `#/settings/labs/?${type}=success`);
};

return {
sendFromAddressUpdateMagicLink,
sendEmailAddressUpdateMagicLink,
getEmailFromToken,
getAdminRedirectLink
};
Expand Down
3 changes: 2 additions & 1 deletion core/server/services/settings/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ module.exports = {
og_description: 'og_description',
twitter_image: 'twitter_image',
twitter_title: 'twitter_title',
twitter_description: 'twitter_description'
twitter_description: 'twitter_description',
members_support_address: 'members_support_address'
};
Loading

0 comments on commit c50aaca

Please sign in to comment.