diff --git a/app/models/question/file.rb b/app/models/question/file.rb index 5340a34e0..3d94dbf16 100644 --- a/app/models/question/file.rb +++ b/app/models/question/file.rb @@ -32,6 +32,12 @@ def show_answer original_filename end + def show_answer_in_email + return nil if original_filename.blank? + + I18n.t("mailer.submission.file_attached", filename: original_filename) + end + def before_save if file.blank? # set to a blank string so that we serialize the answer correctly when an optional question isn't answered diff --git a/app/views/aws_ses_form_submission_mailer/submission_email.html.erb b/app/views/aws_ses_form_submission_mailer/submission_email.html.erb index e35ea6966..e813e6563 100644 --- a/app/views/aws_ses_form_submission_mailer/submission_email.html.erb +++ b/app/views/aws_ses_form_submission_mailer/submission_email.html.erb @@ -1,28 +1,27 @@

- This is a completed "<%= @mailer_options.title %>" form. + <%= I18n.t("mailer.submission.title", title: @mailer_options.title) %>

- This form was submitted at <%= @mailer_options.timestamp.strftime("%l:%M%P").strip %> on <%= @mailer_options.timestamp.strftime("%-d %B %Y") %> + <%= I18n.t("mailer.submission.time", time: @mailer_options.timestamp.strftime("%l:%M%P").strip, date: @mailer_options.timestamp.strftime("%-d %B %Y") ) %>

- GOV.​UK Forms reference number: <%= @mailer_options.submission_reference %>
+ <%= I18n.t("mailer.submission.reference", submission_reference: @mailer_options.submission_reference) %> +

+

+ <%= I18n.t("mailer.submission.check_before_using") %>

-
+
<%= @answer_content.html_safe %> -
+
-
-

You cannot reply to this email

-

- If you need to contact the person who completed this form, you’ll need to contact them directly. -

-

- If you’re experiencing a technical issue with this form, contact the GOV.​UK Forms team with details of the issue and the form it relates to. -

-
+

<%= I18n.t("mailer.submission.cannot_reply.heading") %>

+ <%= I18n.t("mailer.submission.cannot_reply.contact_form_filler").html_safe %> + <%= I18n.t("mailer.submission.cannot_reply.contact_forms_team").html_safe %> + diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb index cbd34d2e9..d8dd991eb 100644 --- a/app/views/layouts/mailer.html.erb +++ b/app/views/layouts/mailer.html.erb @@ -1,13 +1,157 @@ + + - + + - + + + + {{ subject }} + + + + - - <%= yield %> + + + + + +
+ + + + + +
+ + + + + + +
+ + + GOV.UK +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + diff --git a/config/environments/development.rb b/config/environments/development.rb index d83043086..45e7c4bdd 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -70,4 +70,7 @@ # Allow storing session in cookies. This should only be allowed in local # development and testing. In production redis should be used config.unsafe_session_storage = true + + # Configure previews for mailers - https://guides.rubyonrails.org/action_mailer_basics.html#previewing-emails + config.action_mailer.preview_paths << Rails.root.join("spec/mailers/").to_s end diff --git a/config/locales/en.yml b/config/locales/en.yml index 57751ce84..040078a17 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -192,8 +192,17 @@ en: send_confirmation: Do you want to get an email confirming your form has been submitted? mailer: submission: + cannot_reply: + contact_form_filler: "

If you need to contact the person who completed this form, you’ll need to contact them directly.

" + contact_forms_team:

If you’re experiencing a technical issue with this form, contact the GOV.​UK Forms team with details of the issue and the form it relates to.

+ heading: You cannot reply to this email + check_before_using: Check that this data looks safe before you use it + file_attached: "%{filename} (attached to this email)" from: GOV.UK Forms <%{email_address}> + reference: 'GOV.​UK Forms reference number: %{submission_reference}' subject: 'Form submission: %{form_title} - reference: %{reference}' + time: This form was submitted at %{time} on %{date} + title: This is a completed “%{title}” form. mode: phase_banner_tag_preview-archived: Archived preview phase_banner_tag_preview-draft: Draft preview diff --git a/spec/mailers/aws_ses_form_submission_mailer_preview.rb b/spec/mailers/aws_ses_form_submission_mailer_preview.rb new file mode 100644 index 000000000..51d8168e8 --- /dev/null +++ b/spec/mailers/aws_ses_form_submission_mailer_preview.rb @@ -0,0 +1,12 @@ +class AwsSesFormSubmissionMailerPreview < ActionMailer::Preview + def submission_email + AwsSesFormSubmissionMailer.submission_email(answer_content: "

What's your email address?

forms@example.gov.uk

", + submission_email_address: "testing@gov.uk", + mailer_options: FormSubmissionService::MailerOptions.new(title: "Form 1", + preview_mode: false, + timestamp: Time.zone.now, + submission_reference: Faker::Alphanumeric.alphanumeric(number: 8).upcase, + payment_url: nil), + files: {}) + end +end diff --git a/spec/mailers/aws_ses_form_submission_mailer_spec.rb b/spec/mailers/aws_ses_form_submission_mailer_spec.rb index b85fe9d70..16406c653 100644 --- a/spec/mailers/aws_ses_form_submission_mailer_spec.rb +++ b/spec/mailers/aws_ses_form_submission_mailer_spec.rb @@ -26,12 +26,34 @@ expect(mail.subject).to eq("Form submission: #{title} - reference: #{submission_reference}") end + it "has a link to GOV.UK" do + expect(mail.body).to have_link("GOV.UK", href: "https://www.gov.uk") + end + it "includes the answers" do expect(mail.body).to match(answer_content) end + it "includes the form title text" do + expect(mail.body).to have_css("p", text: I18n.t("mailer.submission.title", title:)) + end + + it "includes text about the submission time" do + expect(mail.body).to have_css("p", text: I18n.t("mailer.submission.time", time: submission_timestamp.strftime("%l:%M%P").strip, date: submission_timestamp.strftime("%-d %B %Y"))) + end + it "includes the submission reference" do - expect(mail.body).to match("reference number: #{submission_reference}") + expect(mail.body).to have_css("p", text: I18n.t("mailer.submission.reference", submission_reference:)) + end + + it "includes text about checking the answers" do + expect(mail.body).to have_css("p", text: I18n.t("mailer.submission.check_before_using")) + end + + it "includes the warning about not replying" do + expect(mail.body).to have_css("h2", text: I18n.t("mailer.submission.cannot_reply.heading")) + expect(mail.body).to include(I18n.t("mailer.submission.cannot_reply.contact_form_filler")) + expect(mail.body).to include(I18n.t("mailer.submission.cannot_reply.contact_forms_team")) end describe "submission date/time" do diff --git a/spec/services/aws_ses_submission_service_spec.rb b/spec/services/aws_ses_submission_service_spec.rb index c3a6a12a1..0ca517974 100644 --- a/spec/services/aws_ses_submission_service_spec.rb +++ b/spec/services/aws_ses_submission_service_spec.rb @@ -88,7 +88,7 @@ service.submit expect(AwsSesFormSubmissionMailer).to have_received(:submission_email).with( - { answer_content: "

#{question.question_text}

#{question.original_filename}

", + { answer_content: "

#{question.question_text}

#{I18n.t('mailer.submission.file_attached', filename: question.original_filename)}

", submission_email_address: submission_email, mailer_options: instance_of(FormSubmissionService::MailerOptions), files: { question.original_filename => file_content } }, @@ -148,7 +148,7 @@ expected_csv_content = "Reference,Submitted at,#{question.question_text}\n#{submission_reference},2022-09-14T08:00:00Z,#{question.original_filename}\n" expect(AwsSesFormSubmissionMailer).to have_received(:submission_email).with( - { answer_content: "

#{question.question_text}

#{question.original_filename}

", + { answer_content: "

#{question.question_text}

#{I18n.t('mailer.submission.file_attached', filename: question.original_filename)}

", submission_email_address: submission_email, mailer_options: instance_of(FormSubmissionService::MailerOptions), files: {