Skip to content

Commit f4b0bcd

Browse files
committed
Add mailer to send weekly batch CSV of submissions
This email uses placeholder content for now, re-using the same content as the daily batch email where possible. This will be updated when the actual content is produced.
1 parent 0b67b14 commit f4b0bcd

File tree

9 files changed

+324
-111
lines changed

9 files changed

+324
-111
lines changed

app/mailers/aws_ses_submission_batch_mailer.rb

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,25 @@ def daily_submission_batch_email(form:, date:, mode:, files:)
88
@date = date.strftime("%-d %B %Y")
99
@mode = mode
1010
@filenames = files.keys
11-
@subject = subject
11+
@subject = daily_batch_subject
12+
13+
files.each do |name, file|
14+
attachments[name] = {
15+
encoding: "base64",
16+
content: Base64.encode64(file),
17+
}
18+
end
19+
20+
mail(to: form.submission_email, subject: @subject)
21+
end
22+
23+
def weekly_submission_batch_email(form:, begin_date:, end_date:, mode:, files:)
24+
@form_name = form.name
25+
@begin_date = begin_date.strftime("%-d %B %Y")
26+
@end_date = end_date.strftime("%-d %B %Y")
27+
@mode = mode
28+
@filenames = files.keys
29+
@subject = weekly_batch_subject
1230

1331
files.each do |name, file|
1432
attachments[name] = {
@@ -22,11 +40,19 @@ def daily_submission_batch_email(form:, date:, mode:, files:)
2240

2341
private
2442

25-
def subject
43+
def daily_batch_subject
44+
if @mode.preview?
45+
I18n.t("mailer.submission_batch.daily.subject_preview", form_name: @form_name, date: @date)
46+
else
47+
I18n.t("mailer.submission_batch.daily.subject", form_name: @form_name, date: @date)
48+
end
49+
end
50+
51+
def weekly_batch_subject
2652
if @mode.preview?
27-
I18n.t("mailer.submission_batch.subject_preview", form_name: @form_name, date: @date)
53+
I18n.t("mailer.submission_batch.weekly.subject_preview", form_name: @form_name, begin_date: @begin_date, end_date: @end_date)
2854
else
29-
I18n.t("mailer.submission_batch.subject", form_name: @form_name, date: @date)
55+
I18n.t("mailer.submission_batch.weekly.subject", form_name: @form_name, begin_date: @begin_date, end_date: @end_date)
3056
end
3157
end
3258
end

app/views/aws_ses_submission_batch_mailer/daily_submission_batch_email.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<p><%= I18n.t("mailer.form_name", form_name: @form_name) %></p>
88

99
<% if @filenames.size > 1 %>
10-
<p><%= I18n.t("mailer.submission_batch.multiple_files_explainer", date: @date) %></p>
10+
<p><%= I18n.t("mailer.submission_batch.daily.multiple_files_explainer", date: @date) %></p>
1111
<% else %>
12-
<p><%= I18n.t("mailer.submission_batch.single_file_explainer", date: @date) %></p>
12+
<p><%= I18n.t("mailer.submission_batch.daily.single_file_explainer", date: @date) %></p>
1313
<% end %>
1414

1515
<ul>

app/views/aws_ses_submission_batch_mailer/daily_submission_batch_email.text.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<%= I18n.t("mailer.form_name", form_name: @form_name) %>
66

77
<% if @filenames.size > 1 %>
8-
<%= I18n.t("mailer.submission_batch.multiple_files_explainer", date: @date) %>
8+
<%= I18n.t("mailer.submission_batch.daily.multiple_files_explainer", date: @date) %>
99
<% else %>
10-
<%= I18n.t("mailer.submission_batch.single_file_explainer", date: @date) %>
10+
<%= I18n.t("mailer.submission_batch.daily.single_file_explainer", date: @date) %>
1111
<% end %>
1212

1313
<% @filenames.each do |filename| %>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<% if @mode.preview? %>
2+
<p>
3+
<%= I18n.t("mailer.submission_batch.preview.#{@mode.tag}") %>
4+
</p>
5+
<% end %>
6+
7+
<p><%= I18n.t("mailer.form_name", form_name: @form_name) %></p>
8+
9+
<% if @filenames.size > 1 %>
10+
<p><%= I18n.t("mailer.submission_batch.weekly.multiple_files_explainer", begin_date: @begin_date, end_date: @end_date) %></p>
11+
<% else %>
12+
<p><%= I18n.t("mailer.submission_batch.weekly.single_file_explainer", begin_date: @begin_date, end_date: @end_date) %></p>
13+
<% end %>
14+
15+
<ul>
16+
<% @filenames.each do |filename| %>
17+
<li><%= filename %></li>
18+
<% end %>
19+
</ul>
20+
21+
<p style="margin: 0 0 20px 0; border-left: 10px solid #B1B4B6; padding: 15px;">
22+
<%= I18n.t("mailer.check_before_using") %>
23+
</p>
24+
25+
<p><%= I18n.t("mailer.submission_batch.submissions_are_split") %></p>
26+
27+
<p><%= I18n.t("mailer.submission_batch.file_upload_questions") %></p>
28+
29+
<hr style="border: 0; height: 1px; background: #B1B4B6; margin: 30px 0 30px 0;">
30+
31+
<div
32+
style="margin: 0 0 20px 0; border-left: 10px solid #B1B4B6;
33+
padding: 15px 0 0.1px 15px; font-size: 19px; line-height: 25px;"
34+
>
35+
<h2><%= I18n.t("mailer.cannot_reply.heading") %></h2>
36+
<%= I18n.t("mailer.cannot_reply.contact_forms_team_html").html_safe %>
37+
</div>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<% if @mode.preview? %>
2+
<%= I18n.t("mailer.submission_batch.preview.#{@mode.tag}") %>
3+
<% end %>
4+
5+
<%= I18n.t("mailer.form_name", form_name: @form_name) %>
6+
7+
<% if @filenames.size > 1 %>
8+
<%= I18n.t("mailer.submission_batch.weekly.multiple_files_explainer", begin_date: @begin_date, end_date: @end_date) %>
9+
<% else %>
10+
<%= I18n.t("mailer.submission_batch.weekly.single_file_explainer", begin_date: @begin_date, end_date: @end_date) %>
11+
<% end %>
12+
13+
<% @filenames.each do |filename| %>
14+
<%= filename %>
15+
<% end %>
16+
17+
<%= I18n.t("mailer.check_before_using") %>
18+
19+
<%= I18n.t("mailer.submission_batch.submissions_are_split") %>
20+
21+
<%= I18n.t("mailer.submission_batch.file_upload_questions") %>
22+
23+
---
24+
25+
<%= I18n.t("mailer.cannot_reply.heading") %>
26+
<%= I18n.t("mailer.cannot_reply.contact_forms_team_plain") %>

config/locales/cy.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,16 +450,22 @@ cy:
450450
time: 'Submitted at: %{time} on %{date}'
451451
welsh_submission: At least one of the questions was answered in Welsh
452452
submission_batch:
453+
daily:
454+
multiple_files_explainer: 'All submissions to this form from %{date} are attached to this email in CSV files named:'
455+
single_file_explainer: 'All submissions to this form from %{date} are attached to this email in a CSV file named:'
456+
subject: 'Daily form submissions: ‘%{form_name}’ - %{date}'
457+
subject_preview: 'TEST DAILY FORM SUBMISSIONS: ‘%{form_name}’ - %{date}'
453458
file_upload_questions: For forms with file upload questions, the uploaded files will only be attached to the individual completed form emails.
454-
multiple_files_explainer: 'All submissions to this form from %{date} are attached to this email in CSV files named:'
455459
preview:
456460
archived: These are test submissions to a preview of an archived form.
457461
draft: These are test submissions to a preview of a draft form.
458462
live: These are test submissions to a preview of a live form.
459-
single_file_explainer: 'All submissions to this form from %{date} are attached to this email in a CSV file named:'
460-
subject: 'Daily form submissions: ‘%{form_name}’ - %{date}'
461-
subject_preview: 'TEST DAILY FORM SUBMISSIONS: ‘%{form_name}’ - %{date}'
462463
submissions_are_split: Submissions are split into separate CSV files if the form's been changed in a way that affects the structure of the CSV.
464+
weekly:
465+
multiple_files_explainer: 'All submissions made for this form between %{begin_date} and %{end_date} are attached to this email in CSV files named:'
466+
single_file_explainer: 'All submissions made for this form between %{begin_date} and %{end_date} are attached to this email in a CSV file named:'
467+
subject: 'Weekly form submissions: ‘%{form_name}’ - %{begin_date} to %{end_date}'
468+
subject_preview: 'TEST WEEKLY FORM SUBMISSIONS: ‘%{form_name}’ - %{begin_date} to %{end_date}'
463469
submission_confirmation:
464470
default_support_contact_details: The form’s contact details for support will appear here once they’ve been added.
465471
default_what_happens_next: The form’s information about what happens next will appear here once it has been added.

config/locales/en.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,16 +450,22 @@ en:
450450
time: 'Submitted at: %{time} on %{date}'
451451
welsh_submission: At least one of the questions was answered in Welsh
452452
submission_batch:
453+
daily:
454+
multiple_files_explainer: 'All submissions to this form from %{date} are attached to this email in CSV files named:'
455+
single_file_explainer: 'All submissions to this form from %{date} are attached to this email in a CSV file named:'
456+
subject: 'Daily form submissions: ‘%{form_name}’ - %{date}'
457+
subject_preview: 'TEST DAILY FORM SUBMISSIONS: ‘%{form_name}’ - %{date}'
453458
file_upload_questions: For forms with file upload questions, the uploaded files will only be attached to the individual completed form emails.
454-
multiple_files_explainer: 'All submissions to this form from %{date} are attached to this email in CSV files named:'
455459
preview:
456460
archived: These are test submissions to a preview of an archived form.
457461
draft: These are test submissions to a preview of a draft form.
458462
live: These are test submissions to a preview of a live form.
459-
single_file_explainer: 'All submissions to this form from %{date} are attached to this email in a CSV file named:'
460-
subject: 'Daily form submissions: ‘%{form_name}’ - %{date}'
461-
subject_preview: 'TEST DAILY FORM SUBMISSIONS: ‘%{form_name}’ - %{date}'
462463
submissions_are_split: Submissions are split into separate CSV files if the form's been changed in a way that affects the structure of the CSV.
464+
weekly:
465+
multiple_files_explainer: 'All submissions made for this form between %{begin_date} and %{end_date} are attached to this email in CSV files named:'
466+
single_file_explainer: 'All submissions made for this form between %{begin_date} and %{end_date} are attached to this email in a CSV file named:'
467+
subject: 'Weekly form submissions: ‘%{form_name}’ - %{begin_date} to %{end_date}'
468+
subject_preview: 'TEST WEEKLY FORM SUBMISSIONS: ‘%{form_name}’ - %{begin_date} to %{end_date}'
463469
submission_confirmation:
464470
default_support_contact_details: The form’s contact details for support will appear here once they’ve been added.
465471
default_what_happens_next: The form’s information about what happens next will appear here once it has been added.

spec/mailers/aws_ses_submission_batch_mailer_preview.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,34 @@ def daily_submission_batch_email_with_multiple_files
2727
"batch_2.csv" => "Hello again",
2828
})
2929
end
30+
31+
def weekly_submission_batch_email
32+
form = build(:form, submission_email: "testing@gov.uk")
33+
AwsSesSubmissionBatchMailer.weekly_submission_batch_email(form:,
34+
begin_date: Time.zone.now - 7.days,
35+
end_date: Time.zone.now,
36+
mode: Mode.new("form"),
37+
files: { "batch.csv" => "Hello world" })
38+
end
39+
40+
def weekly_submission_batch_email_preview
41+
form = build(:form, submission_email: "testing@gov.uk")
42+
AwsSesSubmissionBatchMailer.weekly_submission_batch_email(form:,
43+
begin_date: Time.zone.now - 7.days,
44+
end_date: Time.zone.now,
45+
mode: Mode.new("preview-draft"),
46+
files: { "batch.csv" => "Hello world" })
47+
end
48+
49+
def weekly_submission_batch_email_with_multiple_files
50+
form = build(:form, submission_email: "testing@gov.uk")
51+
AwsSesSubmissionBatchMailer.weekly_submission_batch_email(form:,
52+
begin_date: Time.zone.now - 7.days,
53+
end_date: Time.zone.now,
54+
mode: Mode.new("form"),
55+
files: {
56+
"batch.csv" => "Hello world",
57+
"batch_2.csv" => "Hello again",
58+
})
59+
end
3060
end

0 commit comments

Comments
 (0)