From a14181fb456d425385c18be79a60c6b09f29f72e Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 24 Jan 2021 18:18:52 -0800 Subject: [PATCH 1/2] Send separate nightly email for comments --- api/services/emailService.ts | 205 ++++++++++++++++++++++++++++++++++- 1 file changed, 203 insertions(+), 2 deletions(-) diff --git a/api/services/emailService.ts b/api/services/emailService.ts index d0783870e..e3aef9663 100644 --- a/api/services/emailService.ts +++ b/api/services/emailService.ts @@ -160,6 +160,43 @@ export async function sendInvitationEmail(params: ISendInvitationEmailAttrs) { return sendEmail(email); } +export async function sendNewCommentEmailToCampaignAdminAsync (emails: string[], newContributionComments: string[], newExpenditureComments: string[], contributionComments: string, expendituresComments: string): Promise { + const host = process.env.HOST_URL || 'http://localhost:3000'; + const email: ISESEmailParams = { + Destination: { + ToAddresses: emails, + CcAddresses: ['OpenElections@portlandoregon.gov'], + }, + Message: { + Body: { + Html: { + Charset: 'UTF-8', + Data: commentEmailHtml(newContributionComments, newExpenditureComments) + }, + Text: { + Charset: 'UTF-8', + Data: 'This is a daily transaction summary for your campaign\'s Contribution and Expenditure comments.\r\n' + + `${contributionComments.replace(new RegExp('

', 'g'), '\r\n\r\n').replace(new RegExp('
', 'g'), '\r\n')}\r\n` + + `${expendituresComments.replace(new RegExp('

', 'g'), '\r\n\r\n').replace(new RegExp('
', 'g'), '\r\n')}\r\n` + + 'In accordance with Portland City Code 2.16.170, if you believe a determination was made in error, you may file a Request for Reconsideration with the Director within seven days of this notification being sent. You may make this request by filling out a Request for Reconsideration form on the program website at www.portlandoregon.gov/OAE and submitting it to OpenElections@portlandoregon.gov.\r\n' + + `If you would like more information about the transaction(s), please go to your campaign portal at ${host}.\r\n` + + 'Sincerely,\r\n' + + 'Susan Mottet\r\n' + + 'Director, Open and Accountable Elections\r\n' + + 'https://www.portlandoregon.gov/OAE' + }, + }, + Subject: { + Charset: 'UTF-8', + Data: `Important message from the City's OAE program about a transaction`, + } + }, + Source: 'no-reply@openelectionsportland.org', + ReplyToAddresses: ['susan.Mottet@portlandoregon.gov'] + }; + return sendEmail(email); +} + export async function sendActivityEmailToCampaignAdminsAsync(campaignId: number): Promise { const to: Date = new Date(); @@ -215,6 +252,7 @@ export async function sendActivityEmailToCampaignAdminsAsync(campaignId: number) const contributionsText: string = newContributionUpdates.length > 0 ? `Contributions:

The following contributions have been created or updated in the last 24 hours.

${newContributionUpdates.join('
')}` : ''; const contributionComments: string = newContributionComments.length > 0 ? `Contribution Comments:

The following contributions have been commented on in the last 24 hours.

${newContributionComments.join('
')}` : ''; + console.log('What is this stuff?', contributionComments, newContributionComments); const expendituresText: string = newExpenditureUpdates.length > 0 ? `Expenditures:

The following expenditures have been created or updated in the last 24 hours.

${newExpenditureUpdates.join('
')}` : ''; @@ -255,6 +293,7 @@ export async function sendActivityEmailToCampaignAdminsAsync(campaignId: number) Source: 'no-reply@openelectionsportland.org', ReplyToAddresses: ['susan.Mottet@portlandoregon.gov'] }; + await sendNewCommentEmailToCampaignAdminAsync(emails, newContributionComments, newExpenditureComments, contributionComments, expendituresComments); return sendEmail(email); } @@ -880,7 +919,7 @@ export function summaryEmailHtml(newContributionUpdates, newExpenditureUpdates, - The following expenditures have been commented on in the last 24 hours + The following expenditures have been commented on in the last 24 hours: ${newExpenditureUpdates.filter(item => !!item && item.trim() !== '').map((item: string): string => { @@ -969,5 +1008,167 @@ export function summaryEmailHtml(newContributionUpdates, newExpenditureUpdates, -`; } +`; +} +export function commentEmailHtml(newContributionComments, newExpenditureComments) { + const host = process.env.HOST_URL || 'http://localhost:3000'; + return ` + + + + 24 Hr Summary Email + + + + + + + + + + +
+ + +
+ + + + +
+ + + Open & Accountable Elections Portland +
+ + +
+ + + + + ${newContributionComments.filter(item => !!item && item.trim() !== '') && ( + ` + + + + + ` + )} + ${newContributionComments.filter(item => !!item && item.trim() !== '').map((item: string): string => { + return ``; + })} + ${newExpenditureComments.filter(item => !!item && item.trim() !== '') && ( + ` + + + + + ` + )} + ${newExpenditureComments.filter(item => !!item && item.trim() !== '').map((item: string): string => { + return ``; + })} + + + + + + + + + + + + + + + + + + +
+ This is a daily summary for your campaign's Contribution and Expenditure comments. +
+ Contribution Comments +
+ The following contributions have been commented on in the last 24 hours: +
${item}
+ Expenditure Comments +
+ The following expenditures have been commented on in the last 24 hours: +
${item}
+ In accordance with Portland City Code 2.16.170, if you believe a determination was made in error, you may file a Request for Reconsideration with the Director within seven days of this notification being sent. You may make this request by filling out a Request for Reconsideration form on the program website at https://www.portlandoregon.gov/OAE and submitting it to OpenElections@portlandoregon.gov. +
+ If you would like more information about the transaction(s), please go to your campaign portal. +
+ Sincerely, +
+ Susan Mottet +
+ Director, Open and Accountable Elections +
+ + https://www.portlandoregon.gov/OAE +
+
+ + + + + +`; +} From 843160768fde2c4e865f5df7cde5aeb452ad7fc8 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 4 Feb 2021 09:42:05 -0600 Subject: [PATCH 2/2] rm comment --- api/services/emailService.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/api/services/emailService.ts b/api/services/emailService.ts index e3aef9663..5a418fbf7 100644 --- a/api/services/emailService.ts +++ b/api/services/emailService.ts @@ -252,7 +252,6 @@ export async function sendActivityEmailToCampaignAdminsAsync(campaignId: number) const contributionsText: string = newContributionUpdates.length > 0 ? `Contributions:

The following contributions have been created or updated in the last 24 hours.

${newContributionUpdates.join('
')}` : ''; const contributionComments: string = newContributionComments.length > 0 ? `Contribution Comments:

The following contributions have been commented on in the last 24 hours.

${newContributionComments.join('
')}` : ''; - console.log('What is this stuff?', contributionComments, newContributionComments); const expendituresText: string = newExpenditureUpdates.length > 0 ? `Expenditures:

The following expenditures have been created or updated in the last 24 hours.

${newExpenditureUpdates.join('
')}` : '';