mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Fixed "view sent email" showing mailgun template variables
no issue - the `email.{html,plaintext}` fields are only used to display what was sent in the email so it doesn't make sense to store the mailgun-specific content which can be confusing when viewing in the admin area - store the raw serialized post content with a basic no-data replacement of replacement strings rather than the output of full data fetching and mailgun transformation
This commit is contained in:
parent
9981ea336c
commit
c5f7adf917
1 changed files with 12 additions and 3 deletions
|
@ -83,10 +83,9 @@ const addEmail = async (postModel, options) => {
|
||||||
const membersToSendTo = members.filter((member) => {
|
const membersToSendTo = members.filter((member) => {
|
||||||
return membersService.contentGating.checkPostAccess(postModel.toJSON(), member);
|
return membersService.contentGating.checkPostAccess(postModel.toJSON(), member);
|
||||||
});
|
});
|
||||||
const {emailTmpl, emails} = await getEmailData(postModel, membersToSendTo);
|
|
||||||
|
|
||||||
// NOTE: don't create email object when there's nobody to send the email to
|
// NOTE: don't create email object when there's nobody to send the email to
|
||||||
if (!emails.length) {
|
if (!membersToSendTo.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,10 +93,20 @@ const addEmail = async (postModel, options) => {
|
||||||
const existing = await models.Email.findOne({post_id: postId}, knexOptions);
|
const existing = await models.Email.findOne({post_id: postId}, knexOptions);
|
||||||
|
|
||||||
if (!existing) {
|
if (!existing) {
|
||||||
|
// get email contents and perform replacements using no member data so
|
||||||
|
// we have a decent snapshot of email content for later display
|
||||||
|
const {emailTmpl, replacements} = await postEmailSerializer.serialize(postModel, {isBrowserPreview: true});
|
||||||
|
replacements.forEach((replacement) => {
|
||||||
|
emailTmpl[replacement.format] = emailTmpl[replacement.format].replace(
|
||||||
|
replacement.match,
|
||||||
|
replacement.fallback || ''
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
return models.Email.add({
|
return models.Email.add({
|
||||||
post_id: postId,
|
post_id: postId,
|
||||||
status: 'pending',
|
status: 'pending',
|
||||||
email_count: emails.length,
|
email_count: membersToSendTo.length,
|
||||||
subject: emailTmpl.subject,
|
subject: emailTmpl.subject,
|
||||||
html: emailTmpl.html,
|
html: emailTmpl.html,
|
||||||
plaintext: emailTmpl.plaintext,
|
plaintext: emailTmpl.plaintext,
|
||||||
|
|
Loading…
Add table
Reference in a new issue