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:
Kevin Ansfield 2020-04-20 15:35:33 +01:00
parent 9981ea336c
commit c5f7adf917

View File

@ -83,10 +83,9 @@ const addEmail = async (postModel, options) => {
const membersToSendTo = members.filter((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
if (!emails.length) {
if (!membersToSendTo.length) {
return null;
}
@ -94,10 +93,20 @@ const addEmail = async (postModel, options) => {
const existing = await models.Email.findOne({post_id: postId}, knexOptions);
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({
post_id: postId,
status: 'pending',
email_count: emails.length,
email_count: membersToSendTo.length,
subject: emailTmpl.subject,
html: emailTmpl.html,
plaintext: emailTmpl.plaintext,