Skip to content

Commit c800018

Browse files
authored
Merge pull request #1741 from alphagov/update-email-submission-body-for-json-submissions
Add JSON file attached message to submission emails
2 parents 2053c77 + 645f95f commit c800018

File tree

11 files changed

+68
-4
lines changed

11 files changed

+68
-4
lines changed

.review_apps/ecs_task_definition.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ locals {
4545
{ name = "SETTINGS__AUTH_PROVIDER", value = "developer" },
4646
{ name = "SETTINGS__FORMS_ENV", value = "review" },
4747
{ name = "SETTINGS__FORMS_RUNNER__URL", value = "https://${local.runner_review_app_hostname}" },
48-
{ name = "ALLOWED_HOST_PATTERNS", value = "localhost:3000" }
48+
{ name = "ALLOWED_HOST_PATTERNS", value = "localhost:3000" },
49+
{ name = "SETTINGS__FEATURES__JSON_SUBMISSION_ENABLED", value = "true" }
4950
]
5051
}
5152

app/mailers/aws_ses_form_submission_mailer.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ class AwsSesFormSubmissionMailer < ApplicationMailer
33
reply_to: Settings.ses_submission_email.reply_to_email_address,
44
delivery_method: Rails.configuration.x.aws_ses_form_submission_mailer["delivery_method"]
55

6-
def submission_email(answer_content_html:, answer_content_plain_text:, submission:, files:, csv_filename: nil)
6+
def submission_email(answer_content_html:, answer_content_plain_text:, submission:, files:, csv_filename: nil, json_filename: nil)
77
@answer_content_html = answer_content_html
88
@answer_content_plain_text = answer_content_plain_text
99
@submission = submission
1010
@subject = email_subject
1111
@csv_filename = csv_filename
12+
@json_filename = json_filename
1213

1314
files.each do |name, file|
1415
attachments[name] = {

app/services/aws_ses_submission_service.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def deliver_submission_email
3939
answer_content_plain_text:,
4040
submission: @submission,
4141
files:,
42-
csv_filename:).deliver_now
42+
csv_filename:,
43+
json_filename:).deliver_now
4344

4445
CurrentJobLoggingAttributes.mail_message_id = mail.message_id
4546
mail.message_id

app/views/aws_ses_form_submission_mailer/submission_email.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
<p><%= I18n.t("mailer.submission.csv_file", filename: @csv_filename) %></p>
3232
<% end %>
3333

34+
<% if @json_filename.present? %>
35+
<p><%= I18n.t("mailer.submission.json_file", filename: @json_filename) %></p>
36+
<% end %>
37+
3438
<%= @answer_content_html.html_safe %>
3539

3640
<hr style="border: 0; height: 1px; background: #B1B4B6; margin: 30px 0 30px 0;">

app/views/aws_ses_form_submission_mailer/submission_email.text.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
<%= I18n.t("mailer.submission.csv_file", filename: @csv_filename) %>
2222
<% end %>
2323

24+
<% if @json_filename.present? %>
25+
<%= I18n.t("mailer.submission.json_file", filename: @json_filename) %>
26+
<% end %>
27+
2428
<%= @answer_content_plain_text %>
2529

2630
---

config/locales/cy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ cy:
433433
csv_file: 'A CSV file of these answers is attached to this email in a file named: %{filename}'
434434
file_attached: "%{filename} (attached to this email)"
435435
from: GOV.UK Forms <%{email_address}>
436+
json_file: 'A JSON file of these answers is attached to this email in a file named: %{filename}'
436437
payment: You can check that a payment has been made by using this reference number to search transactions within GOV.​UK Pay.
437438
preview: This is a test submission from a preview of this form.
438439
question_skipped: This question was skipped

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ en:
433433
csv_file: 'A CSV file of these answers is attached to this email in a file named: %{filename}'
434434
file_attached: "%{filename} (attached to this email)"
435435
from: GOV.UK Forms <%{email_address}>
436+
json_file: 'A JSON file of these answers is attached to this email in a file named: %{filename}'
436437
payment: You can check that a payment has been made by using this reference number to search transactions within GOV.​UK Pay.
437438
preview: This is a test submission from a preview of this form.
438439
question_skipped: This question was skipped

spec/mailers/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Previewing emails
2+
3+
To preview emails listed in `aws_ses_form_submission_mailer_preview.rb` locally, use the route `/rails/mailers` while the rails server is running.

spec/mailers/aws_ses_form_submission_mailer_preview.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,25 @@ def submission_email_with_csv
3737
files: {},
3838
csv_filename: "my_answers.csv")
3939
end
40+
41+
def submission_email_with_json
42+
form_document = build(:v2_form_document, submission_email: "testing@gov.uk", payment_url: "https://www.gov.uk/payments/your-payment-link")
43+
submission = build(:submission, form_document:, is_preview: false)
44+
AwsSesFormSubmissionMailer.submission_email(answer_content_html: "<h3>What's your email address?</h3><p>forms@example.gov.uk</p>",
45+
answer_content_plain_text: "What's your email address?\n\nforms@example.gov.uk",
46+
submission:,
47+
files: {},
48+
json_filename: "my_answers.json")
49+
end
50+
51+
def submission_email_with_csv_and_json
52+
form_document = build(:v2_form_document, submission_email: "testing@gov.uk", payment_url: "https://www.gov.uk/payments/your-payment-link")
53+
submission = build(:submission, form_document:, is_preview: false)
54+
AwsSesFormSubmissionMailer.submission_email(answer_content_html: "<h3>What's your email address?</h3><p>forms@example.gov.uk</p>",
55+
answer_content_plain_text: "What's your email address?\n\nforms@example.gov.uk",
56+
submission:,
57+
files: {},
58+
csv_filename: "my_answers.csv",
59+
json_filename: "my_answers.json")
60+
end
4061
end

spec/mailers/aws_ses_form_submission_mailer_spec.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require "rails_helper"
22

33
describe AwsSesFormSubmissionMailer, type: :mailer do
4-
subject(:mail) { described_class.submission_email(answer_content_html:, answer_content_plain_text:, submission:, files:, csv_filename:) }
4+
subject(:mail) { described_class.submission_email(answer_content_html:, answer_content_plain_text:, submission:, files:, csv_filename:, json_filename:) }
55

66
let(:submission) do
77
build(:submission, form_document: form_document, created_at: submission_timestamp,
@@ -17,6 +17,7 @@
1717
let(:submission_reference) { Faker::Alphanumeric.alphanumeric(number: 8).upcase }
1818
let(:payment_url) { nil }
1919
let(:csv_filename) { nil }
20+
let(:json_filename) { nil }
2021
let(:submission_timestamp) { Time.utc(2022, 12, 14, 13, 0o0, 0o0) }
2122

2223
context "when form filler submits a completed form" do
@@ -256,6 +257,26 @@
256257
expect(part.body).not_to have_text(I18n.t("mailer.submission.csv_file", filename: csv_filename))
257258
end
258259
end
260+
261+
context "when the json file of answers is attached" do
262+
let(:json_filename) { "my_answers.json" }
263+
264+
describe "the html part" do
265+
let(:part) { mail.html_part }
266+
267+
it "includes text about the JSON filename" do
268+
expect(part.body).to have_css("p", text: I18n.t("mailer.submission.json_file", filename: json_filename))
269+
end
270+
end
271+
272+
describe "the plaintext part" do
273+
let(:part) { mail.text_part }
274+
275+
it "includes text about the JSON filename" do
276+
expect(part.body).to have_text(I18n.t("mailer.submission.json_file", filename: json_filename))
277+
end
278+
end
279+
end
259280
end
260281
end
261282

0 commit comments

Comments
 (0)