Skip to content

Send an email when answers are saved - #2422

Merged
chao-xian merged 15 commits into
mainfrom
send-email-when-answers-saved
Oct 20, 2026
Merged

chao-xian merged 15 commits into
mainfrom
send-email-when-answers-saved

Conversation

@stephencdaly

@stephencdaly stephencdaly commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this pull request solve?

Trello card: https://trello.com/c/WRUjMeYT/

Screenshot 2026-10-16 at 16 28 07

Things to consider when reviewing

  • Ensure that you consider the wider context.
  • Does it work when run on your machine?
  • Is it clear what the code is doing?
  • Do the commit messages explain why the changes were made?
  • Are there all the unit tests needed?
  • Do the end to end tests need updating before these changes will pass?
  • Has all relevant documentation been updated?

@stephencdaly
stephencdaly force-pushed the send-email-when-answers-saved branch 2 times, most recently from f4d70f7 to b64116b Compare October 16, 2026 11:31
Base automatically changed from save-filling to main October 16, 2026 14:45
@stephencdaly
stephencdaly force-pushed the send-email-when-answers-saved branch 2 times, most recently from 5af0ce9 to e3fe1cd Compare October 16, 2026 15:18
@stephencdaly
stephencdaly marked this pull request as ready for review October 16, 2026 15:28
@stephencdaly
stephencdaly requested review from chao-xian and a balanced review from Copilot and removed request for Copilot October 16, 2026 15:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Resume-link generation and mailer preview behavior contain unresolved correctness issues.

5 open findings
What changed in this PR

Adds email notifications to the save-progress flow, giving users a link to return to their form.

Changes:

  • Stores saved-progress metadata and queues notification emails.
  • Adds email templates, previews, and supporting tests.
  • Shares locale selection, contact details, and email logging.
File Description
spec/​services/​save_form_progress_service_spec.rb Tests metadata storage and email enqueueing.
spec/​services/​form_submission_service_spec.rb Updates locale handling tests.
spec/​services/​api/​v3/​form_document_repository_spec.rb Tests draft retrieval.
spec/​requests/​forms/​save_progress_controller_spec.rb Tests saved mode and email recipient.
spec/​requests/​forms/​check_your_answers_controller_spec.rb Updates email logging assertions.
spec/​models/​incomplete_submission_spec.rb Tests saved form retrieval.
spec/​models/​current_job_logging_attributes_spec.rb Tests generic email ID logging.
spec/​mailers/​submission_batch_mailer_preview.rb Corrects preview class name.
spec/​mailers/​progress_saved_mailer_spec.rb Tests email content and links.
spec/​mailers/​progress_saved_mailer_preview.rb Adds saved-progress email previews.
spec/​lib/​flow/​context_spec.rb Tests submission locale selection.
spec/​jobs/​send_progress_saved_email_job_spec.rb Tests delivery, logging, and failures.
spec/​jobs/​receive_confirmation_bounces_and_complaints_job_spec.rb Updates email ID assertions.
db/​schema.rb Records saved-progress metadata columns.
db/​migrate/​20261015163042_add_submission_reference_to_incomplete_submissions.rb Adds submission reference.
db/​migrate/​20261015162736_add_mode_to_incomplete_submissions.rb Adds saved mode.
db/​migrate/​20261013160007_add_locale_to_incomplete_submissions.rb Adds saved locale.
config/​locales/​en.yml Adds notification text.
config/​locales/​cy.yml Adds notification keys with English text.
app/​views/​submission_confirmation_mailer/​_content.md.erb Reuses shared contact details.
app/​views/​progress_saved_mailer/​progress_saved_email.text.erb Adds plain-text email rendering.
app/​views/​progress_saved_mailer/​progress_saved_email.html.erb Adds HTML email rendering.
app/​views/​progress_saved_mailer/​_content.md.erb Defines notification content.
app/​views/​mailer_shared/​_support_contact_details.md.erb Extracts shared contact details.
app/​services/​save_form_progress_service.rb Saves metadata and queues email.
app/​services/​form_submission_service.rb Uses context locale selection.
app/​services/​api/​v3/​form_document_repository.rb Adds draft lookup.
app/​resources/​api/​v3/​form_document_resource.rb Exposes draft retrieval.
app/​models/​incomplete_submission.rb Resolves saved forms and modes.
app/​models/​current_job_logging_attributes.rb Generalizes email ID logging.
app/​mailers/​progress_saved_mailer.rb Builds saved-progress notifications.
app/​lib/​flow/​context.rb Centralizes locale selection.
app/​jobs/​send_progress_saved_email_job.rb Delivers notifications asynchronously.
app/​jobs/​send_confirmation_email_job.rb Uses generic email ID logging.
app/​jobs/​receive_confirmation_bounces_and_complaints_job.rb Uses generic email ID logging.
app/​jobs/​application_job.rb Adds saved-progress logging support.
app/​controllers/​forms/​save_progress_controller.rb Passes mode and recipient to saving service.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread app/mailers/progress_saved_mailer.rb Outdated
Comment thread app/mailers/progress_saved_mailer.rb Outdated
Comment thread app/models/incomplete_submission.rb Outdated
Comment thread spec/mailers/progress_saved_mailer_preview.rb Outdated
Comment thread spec/mailers/progress_saved_mailer_preview.rb Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread config/locales/cy.yml
Comment thread spec/mailers/progress_saved_mailer_preview.rb Outdated
@stephencdaly
stephencdaly force-pushed the send-email-when-answers-saved branch 2 times, most recently from 1aa1d5e to f70fb00 Compare October 16, 2026 16:44
@chao-xian chao-xian self-assigned this Oct 16, 2026
We want to re-use this mailer content for the email we send when a
user saves their answers.
We need to store the locale so we know whether to include Welsh in the
email.
Store the mode so we can construct the correct link for the email to
continue the saved progress for previews.
We want to use the same logic for getting the locale to store on
IncompleteSubmissions.
Add method we can call directly when we want to get the draft form
as opposed to a version of the live form.
We'll send this email when a user has saved their progress. For now,
link to the form's URL but we'll updated this to link to a dedicated
route for returning to complete a form later.

This mailer uses the same SES configuration set as we use for
confirmation emails. The configuration set defines how we handle
bounces and complaints, which should be the same as for confirmation
emails.
We now generate the submission reference when a user starts a new form
submission, so we can save this alongside their answers so we can
follow their session in the logs when they resume filling in their
form.
Store the submission reference so we can include this in logs for
sending the email to the user, and load it back into their session
when they resume their submission.
We can use this logging attribute for other email types, so rename it to be more generic.
- Fix the base_url for forms_runner
- Set the default mailer host to the same as we use in the production
rails env, so we don't mistakenly think it will be set to the app's
URL.
@chao-xian
chao-xian force-pushed the send-email-when-answers-saved branch from f70fb00 to 517f8ec Compare October 19, 2026 17:20
@github-actions

Copy link
Copy Markdown
Contributor

🎉 A review copy of this PR has been deployed! It is made of up two components

  1. A review copy of forms-runner
  2. A production copy of forms-admin

It may take 5 minutes or so for the application to be fully deployed and working. If it still isn't ready
after 5 minutes, there may be something wrong with the ECS task. You will need to go to the integration AWS account
to debug, or otherwise ask an infrastructure person.

For the sign in details and more information, see the review apps wiki page.

@chao-xian chao-xian left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good! So nice to receive the email which then sends me back to the form I was in the middle of filling in

@chao-xian
chao-xian added this pull request to the merge queue Oct 20, 2026
Merged via the queue into main with commit b615625 Oct 20, 2026
7 checks passed
@chao-xian
chao-xian deleted the send-email-when-answers-saved branch October 20, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants