Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .review_apps/ecs_task_definition.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ locals {
{ name = "SETTINGS__FORMS_ADMIN__BASE_URL", value = "https://${local.admin_app_hostname}" },
{ name = "SETTINGS__FORMS_API__BASE_URL", value = "http://localhost:3000" },
{ name = "SETTINGS__FORMS_ENV", value = "review" },
{ name = "SETTINGS__FEATURES__FILLER_ANSWER_EMAIL_ENABLED", value = "true" }

##
# Settings for AWS SES email sending, and S3 CSV submission and file upload
Expand Down
12 changes: 8 additions & 4 deletions app/controllers/forms/check_your_answers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@ def setup_check_your_answers
end

def back_link
previous_step = current_context.previous_step(CheckYourAnswersStep::CHECK_YOUR_ANSWERS_PAGE_SLUG)

if previous_step.present?
previous_step.repeatable? ? add_another_answer_path(form_id: current_context.form.id, form_slug: current_context.form.form_slug, page_slug: previous_step.id) : form_page_path(current_context.form.id, current_context.form.form_slug, previous_step.id)
if FeatureService.enabled?("filler_answer_email_enabled")
copy_of_answers_path(form_id: current_context.form.id, form_slug: current_context.form.form_slug)
else
previous_step = current_context.previous_step(CheckYourAnswersStep::CHECK_YOUR_ANSWERS_PAGE_SLUG)

if previous_step.present?
previous_step.repeatable? ? add_another_answer_path(form_id: current_context.form.id, form_slug: current_context.form.form_slug, page_slug: previous_step.id) : form_page_path(current_context.form.id, current_context.form.form_slug, previous_step.id)
end
end
end
end
Expand Down
49 changes: 49 additions & 0 deletions app/controllers/forms/copy_of_answers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module Forms
class CopyOfAnswersController < BaseController
before_action :redirect_if_feature_disabled

def show
return redirect_to form_page_path(current_context.form.id, current_context.form.form_slug, current_context.next_page_slug) unless can_visit_copy_of_answers?

@back_link = back_link
@copy_of_answers_input = CopyOfAnswersInput.new
end

def save
@copy_of_answers_input = CopyOfAnswersInput.new(copy_of_answers_params)

unless @copy_of_answers_input.valid?
@back_link = back_link
return render :show, status: :unprocessable_content
end

current_context.save_copy_of_answers_preference(@copy_of_answers_input.wants_copy?)

redirect_to check_your_answers_path(form_id: current_context.form.id, form_slug: current_context.form.form_slug)
end

private

def copy_of_answers_params
params.require(:copy_of_answers_input).permit(:copy_of_answers)
end

def can_visit_copy_of_answers?
current_context.can_visit?(CheckYourAnswersStep::CHECK_YOUR_ANSWERS_PAGE_SLUG)
end

def back_link
previous_step = current_context.previous_step(CheckYourAnswersStep::CHECK_YOUR_ANSWERS_PAGE_SLUG)

if previous_step.present?
previous_step.repeatable? ? add_another_answer_path(form_id: current_context.form.id, form_slug: current_context.form.form_slug, page_slug: previous_step.id) : form_page_path(current_context.form.id, current_context.form.form_slug, previous_step.id)
end
end

def redirect_if_feature_disabled
return if FeatureService.enabled?("filler_answer_email_enabled")

redirect_to check_your_answers_path(form_id: current_context.form.id, form_slug: current_context.form.form_slug)
end
end
end
10 changes: 9 additions & 1 deletion app/controllers/forms/page_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,15 @@ def next_step_changing
end

def next_step_in_form_path
form_page_path(@form.id, @form.form_slug, @step.next_page_slug_after_routing)
if @step.next_page_slug_after_routing == CheckYourAnswersStep::CHECK_YOUR_ANSWERS_PAGE_SLUG
if FeatureService.enabled?("filler_answer_email_enabled")
copy_of_answers_path(form_id: @form.id, form_slug: @form.form_slug)
else
check_answers_path
end
else
form_page_path(@form.id, @form.form_slug, @step.next_page_slug_after_routing)
end
end

def check_answers_path
Expand Down
18 changes: 18 additions & 0 deletions app/input_objects/copy_of_answers_input.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class CopyOfAnswersInput
include ActiveModel::Model
include ActiveModel::Validations

attr_accessor :copy_of_answers

RADIO_OPTIONS = { yes: "yes", no: "no" }.freeze

validates :copy_of_answers, presence: true, inclusion: { in: RADIO_OPTIONS.values }

def wants_copy?
copy_of_answers == RADIO_OPTIONS[:yes]
end

def values
RADIO_OPTIONS.keys
end
end
2 changes: 1 addition & 1 deletion app/lib/flow/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(form:, store:)
delegate :support_details, to: :form
delegate :find_or_create, :previous_step, :next_page_slug, :next_step, :can_visit?, :completed_steps, :all_steps, to: :journey
delegate :clear_stored_answer, :clear, :form_submitted?, :answers, :locales_used, to: :answer_store
delegate :save_submission_details, :get_submission_reference, :requested_email_confirmation?, :clear_submission_details, to: :confirmation_details_store
delegate :save_submission_details, :get_submission_reference, :requested_email_confirmation?, :clear_submission_details, :save_copy_of_answers_preference, :wants_copy_of_answers?, to: :confirmation_details_store

def save_step(step, locale: :en, context: nil)
return false unless step.valid?(context)
Expand Down
10 changes: 10 additions & 0 deletions app/lib/store/confirmation_details_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class ConfirmationDetailsStore
CONFIRMATION_KEY = :confirmation_details
SUBMISSION_REFERENCE_KEY = :submission_reference
REQUESTED_EMAIL_KEY = :requested_email_confirmation
COPY_OF_ANSWERS_KEY = :wants_copy_of_answers

def initialize(store, form_id)
@store = store
Expand All @@ -24,6 +25,15 @@ def requested_email_confirmation?
@store.dig(CONFIRMATION_KEY, @form_key, REQUESTED_EMAIL_KEY.to_s)
end

def save_copy_of_answers_preference(wants_copy)
@store[CONFIRMATION_KEY][@form_key] ||= {}
@store[CONFIRMATION_KEY][@form_key][COPY_OF_ANSWERS_KEY.to_s] = wants_copy
end

def wants_copy_of_answers?
@store.dig(CONFIRMATION_KEY, @form_key, COPY_OF_ANSWERS_KEY.to_s)
end

def clear_submission_details
@store[CONFIRMATION_KEY][@form_key] = nil
end
Expand Down
24 changes: 24 additions & 0 deletions app/views/forms/copy_of_answers/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<% set_page_title(form_title(form_name: @current_context.form.name, page_name: t('.title'), mode: @mode, error: @copy_of_answers_input&.errors&.any?)) %>

<% content_for :back_link do %>
<% if @back_link.present? %>
<%= link_to t("forms.back"), @back_link, class: "govuk-back-link" %>
<% end %>
<% end %>

<%= form_with(model: @copy_of_answers_input, method: :post, url: save_copy_of_answers_path(form_id: @form.id, form_slug: @form.form_slug)) do |f| %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<% if @copy_of_answers_input&.errors&.any? %>
<%= f.govuk_error_summary(t("error_summary_title")) %>
<% end %>

<%= f.govuk_collection_radio_buttons :copy_of_answers,
@copy_of_answers_input.values, ->(option) { option }, ->(option) { t("helpers.label.copy_of_answers_input.options.#{option}") },
legend: { text: t('.heading'), tag: 'h1', size: 'l' },
hint: { text: t('.hint') } %>

<%= f.govuk_submit(t("continue")) %>
</div>
</div>
<% end %>
13 changes: 13 additions & 0 deletions config/locales/cy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ cy:
add_another_answer:
blank: Dewiswch ydw os ydych angen ychwanegu ateb arall
max_answers_reached: Dewiswch ydw os ydych angen ychwanegu ateb arall
copy_of_answers_input:
attributes:
copy_of_answers:
blank: PLACEHOLDER! Dewiswch ydw os hoffech dderbyn copi o'ch atebion
email_confirmation_input:
attributes:
confirmation_email_address:
Expand Down Expand Up @@ -373,6 +377,11 @@ cy:
radios_legend: Ydych chi angen ychwanegu ateb arall?
title: Ychwanegu neu ddileu ateb i %{page_title}
back: Yn ôl
copy_of_answers:
show:
heading: PLACEHOLDER! Ydych chi eisiau copi o'ch atebion?
hint: PLACEHOLDER! Byddwn ond yn defnyddio'r cyfeiriad e-bost rydych yn ei ddarparu yma i anfon cadarnhad bod eich ffurflen wedi'i chyflwyno'n llwyddiannus. Ni fydd yn cynnwys copi o'ch atebion.
title: PLACEHOLDER! Ydych chi eisiau copi o'ch atebion?
remove_answer:
show:
address_heading: Dileu cyfeiriad
Expand Down Expand Up @@ -409,6 +418,10 @@ cy:
options:
'no': Na
'yes': Ydw
copy_of_answers_input:
options:
'no': Na
'yes': Ydw
email_confirmation_input:
confirmation_email_address: Pa gyfeiriad e-bost ydych chi eisiau i ni anfon eich cadarnhad ato?
send_confirmation_options:
Expand Down
13 changes: 13 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ en:
add_another_answer:
blank: Select ‘Yes’ if you need to add another answer
max_answers_reached: You cannot add another answer
copy_of_answers_input:
attributes:
copy_of_answers:
blank: Select 'Yes' if you want to get a copy of your answers
email_confirmation_input:
attributes:
confirmation_email_address:
Expand Down Expand Up @@ -373,6 +377,11 @@ en:
radios_legend: Do you need to add another answer?
title: Add or remove answer to %{page_title}
back: Back
copy_of_answers:
show:
heading: Do you want to get an email with a copy of your answers?
hint: You’ll need a GOV.UK One Login for this - you’ll be able to create one now if you do not already have one.
title: Do you want a copy of your answers?
remove_answer:
show:
address_heading: Remove an address
Expand Down Expand Up @@ -409,6 +418,10 @@ en:
options:
'no': 'No'
'yes': 'Yes'
copy_of_answers_input:
options:
'no': 'No'
'yes': 'Yes'
email_confirmation_input:
confirmation_email_address: What email address do you want us to send your confirmation to?
send_confirmation_options:
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
get "/:form_id" => "forms/base#redirect_to_friendly_url_start", as: :form_id, constraints: form_id_constraints
scope "/:form_id/:form_slug(.:locale)", constraints: form_constraints do
get "/" => "forms/base#redirect_to_friendly_url_start", as: :form
get "/copy-of-answers" => "forms/copy_of_answers#show", as: :copy_of_answers
post "/copy-of-answers" => "forms/copy_of_answers#save", as: :save_copy_of_answers
get "/#{CheckYourAnswersStep::CHECK_YOUR_ANSWERS_PAGE_SLUG}" => "forms/check_your_answers#show", as: :check_your_answers
post "/#{CheckYourAnswersStep::CHECK_YOUR_ANSWERS_PAGE_SLUG}" => "forms/check_your_answers#submit_answers", as: :form_submit_answers
get "/submitted" => "forms/submitted#submitted", as: :form_submitted
Expand Down
8 changes: 8 additions & 0 deletions spec/features/email_confirmation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
ActiveResource::HttpMock.respond_to do |mock|
mock.get "/api/v2/forms/1/live", req_headers, form.to_json, 200
end

allow(FeatureService).to receive(:enabled?).with("filler_answer_email_enabled").and_return(true)
end

scenario "opting out of email submission returns the confirmation page without confirmation email text" do
Expand All @@ -39,6 +41,12 @@ def fill_in_form

fill_in question_text, with: text_answer
click_button "Continue"

# Copy of answers page
expect(page.find("h1")).to have_text I18n.t("forms.copy_of_answers.show.heading")
choose "No"
click_button "Continue"

expect(page.find("h1")).to have_text I18n.t("form.check_your_answers.title")
expect(page).to have_text question_text
expect(page).to have_text text_answer
Expand Down
14 changes: 14 additions & 0 deletions spec/features/fill_in_and_submit_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
end

allow(ReferenceNumberService).to receive(:generate).and_return(reference)
allow(FeatureService).to receive(:enabled?).with("filler_answer_email_enabled").and_return(true)
end

scenario "As a form filler" do
Expand All @@ -24,6 +25,10 @@

when_i_fill_in_the_question
and_i_click_on_continue
then_i_should_see_the_copy_of_answers_page

when_i_choose_not_to_receive_a_copy
and_i_click_on_continue
then_i_should_see_the_check_your_answers_page

when_i_opt_out_of_email_confirmation
Expand All @@ -50,6 +55,15 @@ def and_i_click_on_continue
click_button "Continue"
end

def then_i_should_see_the_copy_of_answers_page
expect(page.find("h1")).to have_text "Do you want to get an email with a copy of your answers?"
expect_page_to_have_no_axe_errors(page)
end

def when_i_choose_not_to_receive_a_copy
choose "No"
end

def then_i_should_see_the_check_your_answers_page
expect(page.find("h1")).to have_text "Check your answers before submitting your form"
expect(page).to have_text question_text
Expand Down
14 changes: 14 additions & 0 deletions spec/features/fill_in_and_submit_form_with_csv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
end

allow(ReferenceNumberService).to receive(:generate).and_return(reference)
allow(FeatureService).to receive(:enabled?).with("filler_answer_email_enabled").and_return(true)

travel_to Time.parse("2029-01-24T05:05:50+00:00")
end
Expand All @@ -32,6 +33,10 @@
when_i_fill_in_the_question
and_i_click_on_continue

then_i_should_see_the_copy_of_answers_page
when_i_choose_not_to_receive_a_copy
and_i_click_on_continue

then_i_should_see_the_check_your_answers_page
when_i_opt_out_of_email_confirmation
and_i_submit_my_form
Expand All @@ -58,6 +63,15 @@ def and_i_click_on_continue
click_button "Continue"
end

def then_i_should_see_the_copy_of_answers_page
expect(page.find("h1")).to have_text "Do you want to get an email with a copy of your answers?"
expect_page_to_have_no_axe_errors(page)
end

def when_i_choose_not_to_receive_a_copy
choose "No"
end

def then_i_should_see_the_check_your_answers_page
expect(page.find("h1")).to have_text "Check your answers before submitting your form"
expect_page_to_have_no_axe_errors(page)
Expand Down
14 changes: 14 additions & 0 deletions spec/features/fill_in_autocomplete_question_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
end

allow(ReferenceNumberService).to receive(:generate).and_return(reference)
allow(FeatureService).to receive(:enabled?).with("filler_answer_email_enabled").and_return(true)
end

scenario "As a form filler" do
Expand All @@ -27,6 +28,10 @@
then_i_should_see_the_options
when_i_choose_an_option
and_i_click_on_continue
then_i_should_see_the_copy_of_answers_page

when_i_choose_not_to_receive_a_copy
and_i_click_on_continue
then_i_should_see_the_check_your_answers_page

when_i_opt_out_of_email_confirmation
Expand Down Expand Up @@ -66,6 +71,15 @@ def and_i_click_on_continue
click_button "Continue"
end

def then_i_should_see_the_copy_of_answers_page
expect(page.find("h1")).to have_text "Do you want to get an email with a copy of your answers?"
expect_page_to_have_no_axe_errors(page)
end

def when_i_choose_not_to_receive_a_copy
choose "No"
end

def then_i_should_see_the_check_your_answers_page
expect(page.find("h1")).to have_text "Check your answers before submitting your form"
expect(page).to have_text question_text
Expand Down
Loading
Loading