Skip to content
Open
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
8 changes: 8 additions & 0 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ def forms_with_welsh_translation
forms_feature_report(tag, params[:action], forms)
end

def forms_with_copy_of_answers_enabled
tag = params[:tag]
forms = Reports::FormDocumentsService.form_documents(tag:)
forms = Reports::FeatureReportService.new(forms).forms_with_copy_of_answers_enabled

forms_feature_report(tag, params[:action], forms)
end

def users
data = Reports::UsersReportService.new.user_data

Expand Down
7 changes: 7 additions & 0 deletions app/services/reports/feature_report_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def report
steps_with_answer_type: HashWithIndifferentAccess.new,
forms_with_exit_pages: 0,
forms_with_welsh_translation: 0,
forms_with_copy_of_answers_enabled: 0,
}

form_documents.each do |form|
Expand All @@ -38,6 +39,7 @@ def report
report[:forms_with_s3_submissions] += 1 if Reports::FormDocumentsService.has_s3_submissions(form)
report[:forms_with_exit_pages] += 1 if Reports::FormDocumentsService.has_exit_pages?(form)
report[:forms_with_welsh_translation] += 1 if Reports::FormDocumentsService.has_welsh_translation(form)
report[:forms_with_copy_of_answers_enabled] += 1 if Reports::FormDocumentsService.copy_of_answers_enabled?(form)

answer_types_in_form = form["content"]["steps"].map { |step| step["data"]["answer_type"] }

Expand Down Expand Up @@ -180,6 +182,11 @@ def forms_with_welsh_translation
.select { |form| Reports::FormDocumentsService.has_welsh_translation(form) }
end

def forms_with_copy_of_answers_enabled
form_documents
.select { |form| Reports::FormDocumentsService.copy_of_answers_enabled?(form) }
end

private

def questions_details(form, step)
Expand Down
10 changes: 7 additions & 3 deletions app/services/reports/form_documents_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ class << self
def form_documents(tag:)
form_document_tags = tag == "live-or-archived" ? %w[live archived] : tag
form_documents = FormDocument.joins(form: { group_form: { group: :organisation } })
.where(tag: form_document_tags, language: "en")
.where.not(organisation: { "internal": true })
.select("form_documents.*", "organisation.name AS organisation_name", "organisation.id AS organisation_id", "groups.external_id AS group_external_id", "groups.name AS group_name", "welsh_completed AS welsh_completed")
.where(tag: form_document_tags, language: "en")
.where.not(organisation: { "internal": true })
.select("form_documents.*", "organisation.name AS organisation_name", "organisation.id AS organisation_id", "groups.external_id AS group_external_id", "groups.name AS group_name", "welsh_completed AS welsh_completed")

if tag == "draft"
form_documents = form_documents.where(form: { "state": %w[draft live_with_draft archived_with_draft] })
Expand Down Expand Up @@ -76,6 +76,10 @@ def has_welsh_translation(form_document)
form_document["welsh_completed"].present?
end

def copy_of_answers_enabled?(form_document)
form_document.dig("content", "send_copy_of_answers") == "enabled"
end

private

def secondary_skip_conditions(form_document)
Expand Down
4 changes: 4 additions & 0 deletions app/services/reports/forms_csv_report_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class Reports::FormsCsvReportService
"Submission formats",
"Daily submissions CSV enabled",
"Weekly submissions CSV enabled",
"Has Welsh translation",
"Copy of answers enabled",
].freeze

attr_reader :form_documents
Expand Down Expand Up @@ -79,6 +81,8 @@ def form_row(form)
form["content"]["submission_format"]&.sort&.join(" "),
form["content"]["send_daily_submission_batch"],
form["content"]["send_weekly_submission_batch"],
Reports::FormDocumentsService.has_welsh_translation(form),
Reports::FormDocumentsService.copy_of_answers_enabled?(form),
]
end
end
4 changes: 4 additions & 0 deletions app/views/reports/features.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
<%= row.with_key(text: t(".features.forms_with_welsh_translation", tag: tag_label(tag)).upcase_first) %>
<%= row.with_value(text: govuk_link_to(data[:forms_with_welsh_translation], report_forms_with_welsh_translation_path, no_visited_state: true)) %>
<% end %>
<%= summary_list.with_row do |row| %>
<%= row.with_key(text: t(".features.forms_with_copy_of_answers_enabled", tag: tag_label(tag)).upcase_first) %>
<%= row.with_value(text: govuk_link_to(data[:forms_with_copy_of_answers_enabled], report_forms_with_copy_of_answers_enabled_path, no_visited_state: true)) %>
<% end %>
<% end %>

<h2 class="govuk-heading-m govuk-visually-hidden"><%= t(".answer_types.heading") %></h2>
Expand Down
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,7 @@ en:
copied_forms: "%{tag} forms that are copies"
forms_with_add_another_answer: "%{tag} forms with add another answer"
forms_with_branch_routes: "%{tag} forms with branch routes"
forms_with_copy_of_answers_enabled: "%{tag} forms that allow people to ask for a copy of their answers"
forms_with_csv_submission_email_attachments: "%{tag} forms with CSV email attachments"
forms_with_daily_submission_csv: "%{tag} forms getting a daily CSV of completed forms"
forms_with_exit_pages: "%{tag} forms with exit pages"
Expand Down Expand Up @@ -1867,6 +1868,10 @@ en:
download_csv: Download data about all %{tag} forms with branch routes as a CSV file
empty: There are no %{tag} forms with branch routes
heading: "%{tag} forms with branch routes"
forms_with_copy_of_answers_enabled:
download_csv: Download data about all %{tag} forms that allow people to ask for a copy of their answers (as a CSV)
empty: There are no %{tag} forms that allow people to ask for a copy of their answers
heading: "%{tag} forms that allow people to ask for a copy of their answers"
forms_with_csv_submission_email_attachments:
download_csv: Download data about all %{tag} forms with CSV submission email attachments enabled (as a CSV)
empty: There are no %{tag} forms with CSV submission email attachments enabled
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
get "forms-with-s3-submissions", to: "reports#forms_with_s3_submissions", as: :report_forms_with_s3_submissions
get "forms-with-exit-pages", to: "reports#forms_with_exit_pages", as: :report_forms_with_exit_pages
get "forms-with-welsh-translation", to: "reports#forms_with_welsh_translation", as: :report_forms_with_welsh_translation
get "forms-with-copy-of-answers-enabled", to: "reports#forms_with_copy_of_answers_enabled", as: :report_forms_with_copy_of_answers_enabled
get "selection-questions-summary", to: "reports#selection_questions_summary", as: :report_selection_questions_summary
get "selection-questions-with-autocomplete", to: "reports#selection_questions_with_autocomplete", as: :report_selection_questions_with_autocomplete
get "selection-questions-with-radios", to: "reports#selection_questions_with_radios", as: :report_selection_questions_with_radios
Expand Down
50 changes: 50 additions & 0 deletions spec/requests/reports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,31 @@
end
end

describe "#forms_with_copy_of_answers_enabled" do
let(:path) { report_forms_with_copy_of_answers_enabled_path(tag: :live) }
let(:form) { create(:form, :live, send_copy_of_answers: "enabled") }
let(:forms) { [form] }

include_examples "unauthorized user is forbidden"

context "when the user is a super admin" do
before do
login_as_super_admin_user

get path
end

it "returns http code 200 with the expected report data" do
expect(response).to have_http_status(:ok)
expect(response).to render_template("reports/feature_report")

node = Capybara.string(response.body)
expect(node).to have_xpath "//thead/tr/th[1]", text: "Form name"
expect(node).to have_xpath "//tbody/tr[1]/td[1]", text: form.name
end
end
end

describe "#users" do
let(:path) { report_users_path }

Expand Down Expand Up @@ -686,6 +711,31 @@
end
end

describe "#forms_with_copy_of_answers_enabled as csv" do
let(:form) { create(:form, :live, send_copy_of_answers: "enabled") }
let(:forms) { [form, *create_list(:form, 2, :live)] }
let(:expected_csv_filename) { "live_forms_with_copy_of_answers_enabled_report-2025-05-15 15:31:57 UTC.csv" }

before do
login_as_super_admin_user

travel_to Time.utc(2025, 5, 15, 15, 31, 57)

get report_forms_with_copy_of_answers_enabled_path(tag: :live, format: :csv)
end

it_behaves_like "csv response"

it "has expected response body" do
csv = CSV.parse(response.body, headers: true)
expect(csv.headers).to eq Reports::FormsCsvReportService::FORM_CSV_HEADERS
expect(csv.length).to eq 1
expect(csv.by_col["Form name"]).to eq [
form.name,
]
end
end

describe "#live_questions_csv" do
let(:forms) do
live_forms = create_list(:form, 2, :live, pages_count: 3)
Expand Down
44 changes: 33 additions & 11 deletions spec/services/reports/feature_report_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,23 @@
let(:group) { create(:group) }

let(:form_with_all_answer_types) do
create(:form, :live, :with_support, submission_type: "email", submission_format: %w[csv], payment_url: "https://www.gov.uk/payments/organisation/service", pages: [
create(:page, :with_address_settings, is_repeatable: true),
create(:page, :with_date_settings),
create(:page, answer_type: "email"),
create(:page, :with_full_name_settings),
create(:page, answer_type: "national_insurance_number"),
create(:page, answer_type: "number"),
create(:page, answer_type: "phone_number"),
create(:page, :with_selection_settings, is_optional: true),
create(:page, :with_single_line_text_settings, is_repeatable: true),
])
create(:form, :live,
:with_support,
submission_type: "email",
submission_format: %w[csv],
payment_url: "https://www.gov.uk/payments/organisation/service",
send_copy_of_answers: "enabled",
pages: [
create(:page, :with_address_settings, is_repeatable: true),
create(:page, :with_date_settings),
create(:page, answer_type: "email"),
create(:page, :with_full_name_settings),
create(:page, answer_type: "national_insurance_number"),
create(:page, answer_type: "number"),
create(:page, answer_type: "phone_number"),
create(:page, :with_selection_settings, is_optional: true),
create(:page, :with_single_line_text_settings, is_repeatable: true),
])
end
let(:form_with_a_few_answer_types) do
create(:form,
Expand Down Expand Up @@ -116,6 +122,7 @@
},
forms_with_exit_pages: 1,
forms_with_welsh_translation: 1,
forms_with_copy_of_answers_enabled: 1,
})
end
end
Expand Down Expand Up @@ -512,4 +519,19 @@
]
end
end

describe "#forms_with_copy_of_answers_enabled" do
it "returns live forms with copy of answers enabled" do
forms = described_class.new(form_documents).forms_with_copy_of_answers_enabled
expect(forms.length).to eq 1
expect(forms).to match [
a_hash_including(
"form_id" => form_with_all_answer_types.id,
"content" => a_hash_including(
"name" => form_with_all_answer_types.name,
),
),
]
end
end
end
35 changes: 22 additions & 13 deletions spec/services/reports/forms_csv_report_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,30 @@
"organisation_id" => organisation_id,
"group_name" => group_name,
"group_external_id" => group_external_id,
"welsh_completed" => form.welsh_completed,
})
end
end
let(:form) do
create(:form, :live, :with_support, submission_type: "email", submission_format: %w[csv json],
payment_url: "https://www.gov.uk/payments/organisation/service", send_daily_submission_batch: true,
send_weekly_submission_batch: true, pages: [
create(:page, :with_address_settings, is_repeatable: true),
create(:page, :with_date_settings),
create(:page, answer_type: "email"),
create(:page, :with_full_name_settings),
create(:page, answer_type: "national_insurance_number"),
create(:page, answer_type: "number"),
create(:page, answer_type: "phone_number"),
create(:page, :with_selection_settings, is_optional: true),
create(:page, :with_single_line_text_settings, is_repeatable: true),
])
create(:form, :live,
:with_support,
:with_welsh_translation,
submission_type: "email",
submission_format: %w[csv json],
payment_url: "https://www.gov.uk/payments/organisation/service",
send_daily_submission_batch: true,
send_weekly_submission_batch: true,
pages: [
create(:page, :with_address_settings, is_repeatable: true),
create(:page, :with_date_settings),
create(:page, answer_type: "email"),
create(:page, :with_full_name_settings),
create(:page, answer_type: "national_insurance_number"),
create(:page, answer_type: "number"),
create(:page, answer_type: "phone_number"),
create(:page, :with_selection_settings, is_optional: true),
create(:page, :with_single_line_text_settings, is_repeatable: true),
])
end
let(:forms) { [form, create(:form, :live)] }

Expand Down Expand Up @@ -76,6 +83,8 @@
"csv json",
"true",
"true",
"true",
"false",
)
end
end
Expand Down
5 changes: 5 additions & 0 deletions spec/views/reports/features.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
forms_with_s3_submissions: 5,
forms_with_exit_pages: 1,
forms_with_welsh_translation: 1,
forms_with_copy_of_answers_enabled: 2,
}
end
let(:tag) { "live" }
Expand Down Expand Up @@ -148,6 +149,10 @@
expect(rendered).to have_css(".govuk-summary-list__row", text: "Live forms with Welsh translation#{report[:forms_with_welsh_translation]}")
end

it "includes the number of live forms that allow people to ask for a copy of their answers" do
expect(rendered).to have_css(".govuk-summary-list__row", text: "Live forms that allow people to ask for a copy of their answers#{report[:forms_with_copy_of_answers]}")
end

it "has a link to the selection questions summary report" do
expect(rendered).to have_link href: report_selection_questions_summary_path
end
Expand Down