From a1dbc0d25e31bb0811d9f844855c7da3aa4c4638 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Wed, 7 Feb 2024 15:46:11 +0000 Subject: [PATCH] Add download consent document page This adds a page that allows applicants to download their consent document before uploading the signed one. --- app/assets/stylesheets/application.sass.scss | 1 + .../check_your_answers_summary/component.rb | 47 +---------------- .../teacher_interface/base_controller.rb | 9 +++- .../teacher_interface/documents_controller.rb | 2 +- .../qualification_requests_controller.rb | 45 +++++++++++++++++ .../teacher_interface/uploads_controller.rb | 2 +- .../qualification_request_download_form.rb | 19 +++++++ app/helpers/document_helper.rb | 50 +++++++++++++++++++ app/models/reference_request.rb | 2 - .../edit_download.html.erb | 23 +++++++++ config/locales/teacher_interface.en.yml | 4 ++ config/routes.rb | 4 +- spec/factories/qualification_requests.rb | 7 +++ ...ualification_request_download_form_spec.rb | 43 ++++++++++++++++ .../qualification_request_download.rb | 14 ++++++ spec/support/page_helpers.rb | 5 ++ .../qualification_consent_spec.rb | 24 +++++++++ 17 files changed, 247 insertions(+), 54 deletions(-) create mode 100644 app/forms/teacher_interface/qualification_request_download_form.rb create mode 100644 app/helpers/document_helper.rb create mode 100644 app/views/teacher_interface/qualification_requests/edit_download.html.erb create mode 100644 spec/forms/teacher_interface/qualification_request_download_form_spec.rb create mode 100644 spec/support/autoload/page_objects/teacher_interface/qualification_request_download.rb diff --git a/app/assets/stylesheets/application.sass.scss b/app/assets/stylesheets/application.sass.scss index ecd075f9f7..2ce91c1155 100644 --- a/app/assets/stylesheets/application.sass.scss +++ b/app/assets/stylesheets/application.sass.scss @@ -4,6 +4,7 @@ $govuk-assets-path: "/"; $moj-images-path: "/"; @import "govuk-frontend/govuk/all"; +@import "@ministryofjustice/frontend/moj/components/ticket-panel/ticket-panel"; @import "@ministryofjustice/frontend/moj/components/timeline/timeline"; @import "dfe-autocomplete/src/dfe-autocomplete"; @import "location-autocomplete.min"; diff --git a/app/components/check_your_answers_summary/component.rb b/app/components/check_your_answers_summary/component.rb index 482a932735..7b9a155ff5 100644 --- a/app/components/check_your_answers_summary/component.rb +++ b/app/components/check_your_answers_summary/component.rb @@ -117,42 +117,7 @@ def format_date(date, field) end def format_document(document, field) - scope = - ( - if field[:translation] - document.translated_uploads - else - document.original_uploads - end - ) - - if document.optional? && !document.available - "The applicant has indicated that they haven't done an induction period " \ - "and don't have this document.".html_safe - else - uploads = - scope - .order(:created_at) - .select { |upload| upload.attachment.present? } - - [ - format_array(uploads, field), - if malware_scan_active && scope.scan_result_suspect.exists? - "#{scope.count} #{"file upload".pluralize(scope.count)} has been scanned as malware and deleted." - elsif request.path.starts_with?("/assessor") && - convert_to_pdf_active && !uploads.all?(&:is_pdf?) - helpers.govuk_link_to( - "Download as PDF (opens in a new tab)", - url_helpers.assessor_interface_application_form_document_pdf_path( - document, - field[:translation] ? "translated" : "original", - ), - target: :_blank, - rel: :noopener, - ) - end, - ].compact_blank.join("

").html_safe - end + helpers.document_link_to(document, translated: field[:translation]) end def format_array(list, field) @@ -162,15 +127,5 @@ def format_array(list, field) def url_helpers @url_helpers ||= Rails.application.routes.url_helpers end - - def malware_scan_active - @malware_scan_active ||= - FeatureFlags::FeatureFlag.active?(:fetch_malware_scan_result) - end - - def convert_to_pdf_active - @convert_to_pdf_active = - FeatureFlags::FeatureFlag.active?(:convert_documents_to_pdf) - end end end diff --git a/app/controllers/teacher_interface/base_controller.rb b/app/controllers/teacher_interface/base_controller.rb index c5163739d4..5a8956c5d6 100644 --- a/app/controllers/teacher_interface/base_controller.rb +++ b/app/controllers/teacher_interface/base_controller.rb @@ -27,7 +27,7 @@ def document .assessment &.further_information_requests &.flat_map(&:items) || [] - ), + ) + (application_form.assessment&.qualification_requests || []), ).find(params[:document_id] || params[:id]) end @@ -37,11 +37,16 @@ def redirect_unless_application_form_is_draft end end - def redirect_unless_draft_or_further_information + def redirect_unless_draft_or_additional_information if document.for_further_information_request? unless document.documentable.further_information_request.requested? redirect_to %i[teacher_interface application_form] end + elsif document.for_qualification_request? + if document.documentable.consent_requested_at.nil? || + document.documentable.consent_received_at.present? + redirect_to %i[teacher_interface application_form] + end else redirect_unless_application_form_is_draft end diff --git a/app/controllers/teacher_interface/documents_controller.rb b/app/controllers/teacher_interface/documents_controller.rb index ab568a6ad5..f2753fc9bb 100644 --- a/app/controllers/teacher_interface/documents_controller.rb +++ b/app/controllers/teacher_interface/documents_controller.rb @@ -5,7 +5,7 @@ class DocumentsController < BaseController include HandleApplicationFormSection include HistoryTrackable - before_action :redirect_unless_draft_or_further_information + before_action :redirect_unless_draft_or_additional_information before_action :load_application_form before_action :load_document diff --git a/app/controllers/teacher_interface/qualification_requests_controller.rb b/app/controllers/teacher_interface/qualification_requests_controller.rb index e4f0958593..d94717b569 100644 --- a/app/controllers/teacher_interface/qualification_requests_controller.rb +++ b/app/controllers/teacher_interface/qualification_requests_controller.rb @@ -2,13 +2,58 @@ module TeacherInterface class QualificationRequestsController < BaseController + include HandleApplicationFormSection include HistoryTrackable + before_action :load_qualification_request, except: :index + define_history_origin :index define_history_reset :index def index @view_object = QualificationRequestsViewObject.new(application_form:) end + + def edit_download + @form = + QualificationRequestDownloadForm.new( + qualification_request:, + downloaded: + qualification_request.unsigned_consent_document_downloaded, + ) + end + + def update_download + @form = + QualificationRequestDownloadForm.new( + qualification_request:, + downloaded: + params.dig( + :teacher_interface_qualification_request_download_form, + :downloaded, + ), + ) + + handle_application_form_section( + form: @form, + if_success_then_redirect: + teacher_interface_application_form_qualification_requests_path, + if_failure_then_render: :edit_download, + ) + end + + private + + attr_reader :qualification_request + + def load_qualification_request + @qualification_request = + QualificationRequest + .joins(assessment: :application_form) + .includes(:qualification, :application_form) + .find_by!(id: params[:id], assessment: { application_form: }) + + @qualification = qualification_request.qualification + end end end diff --git a/app/controllers/teacher_interface/uploads_controller.rb b/app/controllers/teacher_interface/uploads_controller.rb index 4606c65014..a206fdcded 100644 --- a/app/controllers/teacher_interface/uploads_controller.rb +++ b/app/controllers/teacher_interface/uploads_controller.rb @@ -12,7 +12,7 @@ class UploadsController < BaseController skip_before_action :authenticate_teacher! before_action -> { authenticate_or_redirect(:teacher) } - before_action :redirect_unless_draft_or_further_information + before_action :redirect_unless_draft_or_additional_information before_action :load_application_form before_action :load_document before_action :load_upload, only: %i[delete destroy show] diff --git a/app/forms/teacher_interface/qualification_request_download_form.rb b/app/forms/teacher_interface/qualification_request_download_form.rb new file mode 100644 index 0000000000..656dc2b157 --- /dev/null +++ b/app/forms/teacher_interface/qualification_request_download_form.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module TeacherInterface + class QualificationRequestDownloadForm < BaseForm + attr_accessor :qualification_request + attribute :downloaded, :boolean + + validates :qualification_request, presence: true + validates :downloaded, presence: true + + def update_model + if downloaded + qualification_request.update!( + unsigned_consent_document_downloaded: true, + ) + end + end + end +end diff --git a/app/helpers/document_helper.rb b/app/helpers/document_helper.rb new file mode 100644 index 0000000000..4b85bfac11 --- /dev/null +++ b/app/helpers/document_helper.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +module DocumentHelper + include UploadHelper + + def document_link_to(document, translated: false) + scope = + ( + if translated + document.translated_uploads + else + document.original_uploads + end + ) + + if document.optional? && !document.available + "The applicant has indicated that they haven't done an induction period " \ + "and don't have this document.".html_safe + else + uploads = + scope.order(:created_at).select { |upload| upload.attachment.present? } + + malware_scan_active = + FeatureFlags::FeatureFlag.active?(:fetch_malware_scan_result) + convert_to_pdf_active = + FeatureFlags::FeatureFlag.active?(:convert_documents_to_pdf) + + [ + uploads + .map { |upload| upload_link_to(upload) } + .join("
") + .html_safe, + if malware_scan_active && scope.scan_result_suspect.exists? + "#{scope.count} #{"file upload".pluralize(scope.count)} has been scanned as malware and deleted." + elsif request.path.starts_with?("/assessor") && convert_to_pdf_active && + !uploads.all?(&:is_pdf?) + helpers.govuk_link_to( + "Download as PDF (opens in a new tab)", + url_helpers.assessor_interface_application_form_document_pdf_path( + document, + translated ? "translated" : "original", + ), + target: :_blank, + rel: :noopener, + ) + end, + ].compact_blank.join("

").html_safe + end + end +end diff --git a/app/models/reference_request.rb b/app/models/reference_request.rb index 92ad9a6dfb..0d61d0c917 100644 --- a/app/models/reference_request.rb +++ b/app/models/reference_request.rb @@ -81,8 +81,6 @@ class ReferenceRequest < ApplicationRecord validates :satisfied_response, inclusion: [true, false] end - delegate :application_form, to: :assessment - def responses_given? [ contact_response, diff --git a/app/views/teacher_interface/qualification_requests/edit_download.html.erb b/app/views/teacher_interface/qualification_requests/edit_download.html.erb new file mode 100644 index 0000000000..b059fc3aed --- /dev/null +++ b/app/views/teacher_interface/qualification_requests/edit_download.html.erb @@ -0,0 +1,23 @@ +<% content_for :page_title, "Download consent document" %> +<% content_for :back_link_url, back_history_path(default: teacher_interface_application_form_qualification_requests_path) %> + +<%= form_with model: @form, url: [:download, :teacher_interface, :application_form, @qualification_request] do |f| %> + <%= f.govuk_error_summary %> + +

Download consent document

+ +

<%= qualification_title(@qualification) %>

+ +
+
+

Download the consent document

+

<%= document_link_to(@qualification_request.unsigned_consent_document) %>

+
+
+ + <%= f.govuk_check_boxes_fieldset :downloaded, multiple: false, small: true, legend: nil do %> + <%= f.govuk_check_box :downloaded, true, false, link_errors: true, label: { text: "I have downloaded the consent document." } %> + <% end %> + + <%= render "shared/save_submit_buttons", f: %> +<% end %> diff --git a/config/locales/teacher_interface.en.yml b/config/locales/teacher_interface.en.yml index 69a2faa432..a562ccaa5d 100644 --- a/config/locales/teacher_interface.en.yml +++ b/config/locales/teacher_interface.en.yml @@ -300,6 +300,10 @@ en: invalid: Enter the certificate date in the format 27 3 1980 future: Certificate date must be in the past comparison: Certificate date must be after completion date + teacher_interface/qualification_request_download_form: + attributes: + downloaded: + blank: Confirm that you have downloaded the consent document. teacher_interface/reference_request_children_response_form: attributes: children_response: diff --git a/config/routes.rb b/config/routes.rb index 180c0bea5d..4b8630e1a7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -349,8 +349,8 @@ path: "/qualification-requests", only: %i[index] do member do - get "download" - get "upload" + get "download", to: "qualification_requests#edit_download" + post "download", to: "qualification_requests#update_download" end end end diff --git a/spec/factories/qualification_requests.rb b/spec/factories/qualification_requests.rb index a3c86b3031..04294bc49d 100644 --- a/spec/factories/qualification_requests.rb +++ b/spec/factories/qualification_requests.rb @@ -41,6 +41,13 @@ trait :consent_required do signed_consent_document_required { true } + + after(:create) do |qualification_request, _evaluator| + create( + :upload, + document: qualification_request.unsigned_consent_document, + ) + end end trait :consent_requested do diff --git a/spec/forms/teacher_interface/qualification_request_download_form_spec.rb b/spec/forms/teacher_interface/qualification_request_download_form_spec.rb new file mode 100644 index 0000000000..7158cd8b21 --- /dev/null +++ b/spec/forms/teacher_interface/qualification_request_download_form_spec.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe TeacherInterface::QualificationRequestDownloadForm, + type: :model do + let(:qualification_request) { create(:qualification_request) } + + subject(:form) { described_class.new(qualification_request:, downloaded:) } + + describe "validations" do + let(:downloaded) { "" } + + it { is_expected.to validate_presence_of(:qualification_request) } + it { is_expected.to validate_presence_of(:downloaded) } + end + + describe "#save" do + subject(:save) { form.save(validate: false) } + + context "with a positive response" do + let(:downloaded) { "true" } + + it "sets unsigned_consent_document_downloaded" do + expect { save }.to change( + qualification_request, + :unsigned_consent_document_downloaded, + ).to(true) + end + end + + context "with a negative response" do + let(:downloaded) { "false" } + + it "doesn't set unsigned_consent_document_downloaded" do + expect { save }.to_not change( + qualification_request, + :unsigned_consent_document_downloaded, + ) + end + end + end +end diff --git a/spec/support/autoload/page_objects/teacher_interface/qualification_request_download.rb b/spec/support/autoload/page_objects/teacher_interface/qualification_request_download.rb new file mode 100644 index 0000000000..3ae1638c18 --- /dev/null +++ b/spec/support/autoload/page_objects/teacher_interface/qualification_request_download.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module PageObjects + module TeacherInterface + class QualificationRequestDownload < SitePrism::Page + set_url "/teacher/application/qualification-requests/{id}/download" + + element :downloaded_checkbox, ".govuk-checkboxes__input", visible: false + + element :continue_button, ".govuk-button:not(.govuk-button--secondary)" + element :save_and_sign_out_button, ".govuk-button.govuk-button--secondary" + end + end +end diff --git a/spec/support/page_helpers.rb b/spec/support/page_helpers.rb index d10100384d..e6a7a51d37 100644 --- a/spec/support/page_helpers.rb +++ b/spec/support/page_helpers.rb @@ -569,6 +569,11 @@ def teacher_qualification_requests_page PageObjects::TeacherInterface::QualificationRequests.new end + def teacher_qualification_request_download_page + @teacher_qualification_request_download_page = + PageObjects::TeacherInterface::QualificationRequestDownload.new + end + def teacher_reference_received_page @teacher_reference_received_page ||= PageObjects::TeacherInterface::ReferenceReceived.new diff --git a/spec/system/teacher_interface/qualification_consent_spec.rb b/spec/system/teacher_interface/qualification_consent_spec.rb index 13ae01a714..cfdb6e59d8 100644 --- a/spec/system/teacher_interface/qualification_consent_spec.rb +++ b/spec/system/teacher_interface/qualification_consent_spec.rb @@ -29,6 +29,15 @@ when_i_click_the_start_button then_i_see_the(:teacher_qualification_requests_page) and_i_see_the_download_and_upload_tasks + + when_i_click_the_download_task + then_i_see_the( + :teacher_qualification_request_download_page, + id: qualification_request.id, + ) + + when_i_check_the_downloaded_checkbox + then_i_see_the(:teacher_qualification_requests_page) end def given_there_is_an_application_form @@ -67,6 +76,21 @@ def and_i_see_the_download_and_upload_tasks expect(task_list_section.items.count).to eq(2) end + def when_i_click_the_download_task + teacher_qualification_requests_page + .task_list + .sections + .first + .items + .first + .click + end + + def when_i_check_the_downloaded_checkbox + teacher_qualification_request_download_page.downloaded_checkbox.check + teacher_qualification_request_download_page.continue_button.click + end + def teacher @teacher ||= create(:teacher) end