Skip to content

Commit 23f44c7

Browse files
authored
Merge pull request #2778 from govuk-forms/add-page-to-enable-copy-of-answers
Add task to enable form fillers to get a copy of their answers
2 parents 6fa9df7 + 545f47d commit 23f44c7

19 files changed

Lines changed: 469 additions & 25 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module Forms
2+
class CopyOfAnswersController < FormsController
3+
before_action :check_user_has_permission
4+
before_action :check_feature_flag
5+
6+
def new
7+
@copy_of_answers_input = Forms::CopyOfAnswersInput.new(form: current_form).assign_form_values
8+
end
9+
10+
def create
11+
@copy_of_answers_input = Forms::CopyOfAnswersInput.new(copy_of_answers_input_params)
12+
13+
if @copy_of_answers_input.submit
14+
redirect_to form_path(current_form.id), success: success_message
15+
else
16+
render :new, status: :unprocessable_content
17+
end
18+
end
19+
20+
private
21+
22+
def check_user_has_permission
23+
authorize current_form, :can_view_form?
24+
end
25+
26+
def check_feature_flag
27+
raise NotFoundError unless FeatureService.enabled?(:send_filler_answers)
28+
end
29+
30+
def copy_of_answers_input_params
31+
params.require(:forms_copy_of_answers_input).permit(:send_copy_of_answers).merge(form: current_form)
32+
end
33+
34+
def success_message
35+
return nil unless current_form.send_copy_of_answers_previously_changed?
36+
37+
if current_form.send_copy_of_answers.to_sym == :enabled
38+
t("banner.success.form.copy_of_answers_enabled")
39+
else
40+
t("banner.success.form.copy_of_answers_disabled")
41+
end
42+
end
43+
end
44+
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Forms::CopyOfAnswersInput < BaseInput
2+
attr_accessor :form, :send_copy_of_answers
3+
4+
validates :send_copy_of_answers, presence: true, inclusion: { in: %w[enabled disabled] }
5+
6+
def submit
7+
return false if invalid?
8+
9+
form.send_copy_of_answers = send_copy_of_answers
10+
form.save_draft!
11+
end
12+
13+
def assign_form_values
14+
self.send_copy_of_answers = form.send_copy_of_answers
15+
self
16+
end
17+
end

app/models/form.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Form < ApplicationRecord
3737
enum :send_copy_of_answers, {
3838
disabled: "disabled",
3939
enabled: "enabled",
40-
}
40+
}, prefix: :send_copy_of_answers
4141

4242
# ActiveRecord doesn't support enums with arrays
4343
# enum :submission_format, {

app/services/form_task_list_service.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def initialize(form:, current_user:)
2020
def all_sections
2121
[
2222
create_form_section(section_number: 1),
23-
payment_link_subsection,
23+
create_form_optional_subsection,
2424
how_you_get_completed_forms_section(section_number: 2),
2525
how_you_get_completed_forms_optional_subsection,
2626
privacy_and_contact_details_section(section_number: 3),
@@ -61,21 +61,22 @@ def create_form_section_tasks
6161
]
6262
end
6363

64-
def payment_link_subsection
64+
def create_form_optional_subsection
65+
rows = [
66+
{ task_name: I18n.t("forms.task_list_#{create_or_edit}.create_form_optional_subsection.payment_link"), path: payment_link_path(@form.id), status: @task_statuses[:payment_link_status] },
67+
]
68+
if FeatureService.enabled?(:send_filler_answers)
69+
rows << { task_name: I18n.t("forms.task_list_#{create_or_edit}.create_form_optional_subsection.copy_of_answers"), path: copy_of_answers_path(@form.id), status: @task_statuses[:copy_of_answers_status] }
70+
end
71+
6572
{
66-
title: I18n.t("forms.task_list.optional_tasks_title", count: 1),
67-
rows: payment_link_subsection_tasks,
73+
title: I18n.t("forms.task_list.optional_tasks_title", count: rows.count),
74+
rows: rows,
6875
section_number: nil,
6976
subsection: true,
7077
}
7178
end
7279

73-
def payment_link_subsection_tasks
74-
[
75-
{ task_name: I18n.t("forms.task_list_#{create_or_edit}.payment_link_subsection.payment_link"), path: payment_link_path(@form.id), status: @task_statuses[:payment_link_status] },
76-
]
77-
end
78-
7980
def how_you_get_completed_forms_section(section_number:)
8081
{
8182
title: I18n.t("forms.task_list_#{create_or_edit}.how_you_get_completed_forms_section.title"),
@@ -251,6 +252,7 @@ def status_counts
251252

252253
def remove_optional_statuses(statuses)
253254
statuses.delete(:payment_link_status)
255+
statuses.delete(:copy_of_answers_status)
254256
statuses.delete(:submission_attachments_status)
255257
statuses.delete(:batch_submissions_status)
256258
end

app/services/task_status_service.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def all_task_statuses
2929
declaration_status:,
3030
what_happens_next_status:,
3131
payment_link_status:,
32+
copy_of_answers_status:,
3233
privacy_policy_status:,
3334
support_contact_details_status:,
3435
submission_attachments_status:,
@@ -86,6 +87,12 @@ def payment_link_status
8687
:optional
8788
end
8889

90+
def copy_of_answers_status
91+
return :completed if @form.send_copy_of_answers_enabled?
92+
93+
:optional
94+
end
95+
8996
def privacy_policy_status
9097
return :completed if @form.privacy_policy_url.present?
9198

app/views/forms/_made_live_form.html.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@
140140
<% end %>
141141
<% end %>
142142

143+
<% if form_document.send_copy_of_answers == "enabled" %>
144+
<h3 class="govuk-heading-m"><%= t(".copy_of_answers.title") %></h3>
145+
<p><%= t(".copy_of_answers.enabled") %></p>
146+
<% end %>
147+
143148
<h3 class="govuk-heading-m"><%= t(".how_you_get_completed_forms.title") %></h3>
144149

145150
<h4 class="govuk-heading-s"><%= t('.how_you_get_completed_forms.submission_email') %></h4>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<% set_page_title(title_with_error_prefix(t('page_titles.copy_of_answers'), @copy_of_answers_input.errors.any?)) %>
2+
3+
<% content_for :back_link, govuk_back_link_to(form_path(@copy_of_answers_input.form.id), t("back_link.form_create")) %>
4+
5+
<div class="govuk-grid-row">
6+
<div class="govuk-grid-column-two-thirds">
7+
<%= form_with(model: @copy_of_answers_input, url: copy_of_answers_create_path(@copy_of_answers_input.form.id)) do |f| %>
8+
<% if @copy_of_answers_input&.errors.any? %>
9+
<%= f.govuk_error_summary %>
10+
<% end %>
11+
12+
<h1 class="govuk-heading-l">
13+
<span class="govuk-caption-l"><%= @copy_of_answers_input.form.name %></span>
14+
<%= t("page_titles.copy_of_answers") %>
15+
</h1>
16+
17+
<%= t(".body_html") %>
18+
19+
<%= f.govuk_check_boxes_fieldset :send_copy_of_answers, multiple: false, legend: { tag: 'h2', size: 'm'} do %>
20+
<%= f.govuk_check_box :send_copy_of_answers, "enabled", "disabled", multiple: false, link_errors: true %>
21+
<% end %>
22+
23+
<%= f.govuk_submit t("save_and_continue") %>
24+
<% end %>
25+
</div>
26+
</div>
27+

app/views/forms/what_happens_next/new.html.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424

2525
<%= t("what_happens_next.how_this_content_is_used_html") %>
2626

27+
<% if FeatureService.enabled?(:send_filler_answers) %>
28+
<p><%= t("what_happens_next.confirmation_email_send_filler_answers_enabled") %></p>
29+
<% else %>
30+
<p><%= t("what_happens_next.confirmation_email") %></p>
31+
<% end %>
32+
2733
<%= govuk_inset_text do %>
2834
<%= t("what_happens_next.reference_numbers") %>
2935
<% end %>

config/locales/en.yml

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ en:
7272
attributes:
7373
agreed:
7474
accepted: You must agree to the terms of use to continue
75+
forms/copy_of_answers_input:
76+
attributes:
77+
send_copy_of_answers:
78+
blank: Sorry, there was a problem. Please try again.
79+
inclusion: Sorry, there was a problem. Please try again.
7580
forms/delete_confirmation_input:
7681
blank: Select ‘Yes’ to delete the draft
7782
forms/submission_attachments_input:
@@ -236,6 +241,8 @@ en:
236241
weekly_enabled: You’ll get a weekly batch of form submissions
237242
change_name: Your form name has been saved
238243
copied: Your form has been copied
244+
copy_of_answers_disabled: People will not have the option to ask for a copy of their answers
245+
copy_of_answers_enabled: People will have the option to ask for a copy of their answers
239246
declaration_saved: Your declaration has been saved
240247
declaration_saved_and_completed: Your declaration has been saved and marked as complete
241248
page_moved: "‘%{question_text}’ has moved %{direction} to number %{question_number}"
@@ -398,6 +405,15 @@ en:
398405
<p>The CSVs will include each submission’s answers in plain text separated by commas - plus the date and time of submission.</p>
399406
<p>If you make changes to the form such as adding, moving or deleting a question, the structure of the CSV will change. Forms completed before and after the change will be split into separate CSV files.</p>
400407
<p>You’ll continue to receive individual completed form submissions in the usual way. If your form has any file upload questions, the uploaded files will only be attached to the individual submissions.</p>
408+
copy_of_answers:
409+
new:
410+
body_html: |
411+
<p>You can give people who complete your form the option to get an email with a copy of their answers. We’ll ask if they want this after they’ve answered all the questions in your form. People only get a copy of their answers if they ask for it: you cannot make it mandatory.</p>
412+
<p>We use GOV.UK One Login to make sure answers are not sent to the wrong email address. If the person filling in the form does not have a GOV.UK One Login already, they’ll be asked to create one before submitting the form.</p>
413+
<h2 class="govuk-heading-m">Why you might not want to give people the option to get a copy of their answers</h2>
414+
<p>If someone already has a GOV.UK One Login, it will usually be linked to their personal email address. So there’s a chance the answers will be sent to their personal email address, even if they’re filling in the form in a work capacity.</p>
415+
<p>If they need to create a new GOV.UK One Login, this adds an extra step - meaning there’s a chance they might not come back and complete the form.</p>
416+
<p>So only allow this option if there’s a real need for people to be able to request a copy of their answers.</p>
401417
delete_confirmation:
402418
delete:
403419
hint_for_archived_draft: Deleting this draft will not remove the archived form.
@@ -423,6 +439,9 @@ en:
423439
cy: Previous Welsh form URL
424440
en: Previous English form URL
425441
contact_details: Your form’s contact details for support
442+
copy_of_answers:
443+
enabled: You’ve opted to let people ask to be sent a copy of their answers after they’ve filled in the form.
444+
title: People can ask for a copy of their answers
426445
declaration: Declaration
427446
declaration_description: Your form’s declaration is shown to people when they have answered all the questions, just before they submit the form.
428447
draft_create: Create a draft to edit
@@ -491,6 +510,9 @@ en:
491510
one: Optional task
492511
other: Optional tasks
493512
task_list_create:
513+
create_form_optional_subsection:
514+
copy_of_answers: Give people the option to ask for a copy of their answers
515+
payment_link: Add a link to a payment page on GOV.UK Pay
494516
create_form_section:
495517
declaration: Add a declaration for people to agree to
496518
name: Edit the name of your form
@@ -526,8 +548,6 @@ en:
526548
Only a group admin can make a form live.
527549
528550
<a href="%{group_members_path}">View the members of the group</a> to find a group admin.
529-
payment_link_subsection:
530-
payment_link: Add a link to a payment page on GOV.UK Pay
531551
privacy_and_contact_details_section:
532552
contact_details: Provide contact details for support
533553
privacy_policy: Provide a link to privacy information for this form
@@ -536,6 +556,9 @@ en:
536556
add_welsh: Add a Welsh version of your form
537557
title: Create a Welsh version of your form (optional)
538558
task_list_edit:
559+
create_form_optional_subsection:
560+
copy_of_answers: Give people the option to ask for a copy of their answers
561+
payment_link: Add a link to a payment page on GOV.UK Pay
539562
create_form_section:
540563
declaration: Edit the declaration for people to agree to
541564
name: Edit the name of your form
@@ -554,8 +577,6 @@ en:
554577
make_live: Make your changes live
555578
share_preview: Share a preview of your draft form
556579
title: Make your changes live
557-
payment_link_subsection:
558-
payment_link: Add a link to a payment page on GOV.UK Pay
559580
privacy_and_contact_details_section:
560581
contact_details: Edit the contact details for support
561582
privacy_policy: Edit the link to privacy information for this form
@@ -951,6 +972,9 @@ en:
951972
weekly: Get a weekly CSV of submissions
952973
forms_copy_input:
953974
name: What is the name of your form?
975+
forms_copy_of_answers_input:
976+
send_copy_of_answers_options:
977+
enabled: Give people the option to get a copy of their answers by email - I’m ok with the risk
954978
forms_make_changes_live:
955979
confirm: Are you sure you want to make your draft live?
956980
forms_make_language_live_input:
@@ -1119,6 +1143,8 @@ en:
11191143
agreed: Do you agree to these terms?
11201144
forms_batch_submissions_input:
11211145
batch_frequencies: Do you want to get a daily or weekly CSV of submissions to this form?
1146+
forms_copy_of_answers_input:
1147+
send_copy_of_answers: Do you want to give people the option to get a copy of their answers by email?
11221148
forms_submission_attachments_input:
11231149
submission_format: Do you want to get a CSV or JSON file of each completed form?
11241150
forms_submission_type_input:
@@ -1492,6 +1518,7 @@ en:
14921518
confirm_email_success: Email address confirmed
14931519
contact_details: Provide contact details for support
14941520
copy: What is the name of your form?
1521+
copy_of_answers: Give people the option to get a copy of their answers by email
14951522
date_settings: Are you asking for someone’s date of birth?
14961523
declaration: Add a declaration for people to agree to
14971524
delete_secondary_skip: Are you sure you want to delete the route for any other answer?
@@ -2163,6 +2190,8 @@ en:
21632190
name: Super admin
21642191
save: Save
21652192
what_happens_next:
2193+
confirmation_email: The optional email confirmation will also include the contact details you provide for the form, and the date and time of submission. It will not include a copy of their answers.
2194+
confirmation_email_send_filler_answers_enabled: The optional email confirmation will also include the contact details you provide for the form, and the date and time of submission. If you’ve given people the option to ask for a copy of their answers - and the person filling in the form requests this - their answers will be added to the confirmation email.
21662195
example:
21672196
body: We’ll send you an email to let you know the outcome. You’ll usually get a response within 10 working days.
21682197
heading: Example
@@ -2174,10 +2203,5 @@ en:
21742203
<li>shown to people when they’ve completed and submitted a form</li>
21752204
<li>included in an email confirmation, if they choose to receive this</li>
21762205
</ul>
2177-
2178-
<p>
2179-
The optional email confirmation will also include the contact details you provide for the form,
2180-
and the date and time of submission. It will not include a copy of their answers.
2181-
</p>
21822206
instructions: Add some information to tell people what will happen after they’ve submitted their form, and when - so they know what to expect.
21832207
reference_numbers: GOV.UK Forms adds a unique reference number to the confirmation page and optional email confirmation. This will also be included in submission emails sent to your processing email address.

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@
8282
post "/submission-attachments" => "forms/submission_attachments#create", as: :submission_attachments_create
8383
get "/batch-submissions" => "forms/batch_submissions#new", as: :batch_submissions
8484
post "/batch-submissions" => "forms/batch_submissions#create", as: :batch_submissions_create
85+
get "/copy-of-answers" => "forms/copy_of_answers#new", as: :copy_of_answers
86+
post "/copy-of-answers" => "forms/copy_of_answers#create", as: :copy_of_answers_create
8587
get "/metrics" => "forms/metrics#metrics_csv", as: :metrics_csv
8688

8789
resource :routes, only: %i[show create]

0 commit comments

Comments
 (0)