From 3c54bfa1ca7be1a0fe58b55c906dd44b8bf359e6 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Fri, 9 Feb 2024 20:18:25 +0000 Subject: [PATCH] Allow submitting consent documents This adds the functionality to submit consent documentsonce they've been signed. --- .../qualification_requests_controller.rb | 19 +++++++++++- .../application_form_view_object.rb | 11 +++++++ .../qualification_requests_view_object.rb | 23 +++++++++++++++ .../show/_submitted.html.erb | 19 ++++++++++-- .../qualification_requests/check.html.erb | 18 ++++++++++++ .../qualification_requests/index.html.erb | 8 ++++- config/routes.rb | 5 ++++ .../check_qualification_requests.rb | 13 +++++++++ spec/support/page_helpers.rb | 5 ++++ .../qualification_consent_spec.rb | 29 +++++++++++++++++++ 10 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 app/views/teacher_interface/qualification_requests/check.html.erb create mode 100644 spec/support/autoload/page_objects/teacher_interface/check_qualification_requests.rb diff --git a/app/controllers/teacher_interface/qualification_requests_controller.rb b/app/controllers/teacher_interface/qualification_requests_controller.rb index d94717b569..e3585dfbef 100644 --- a/app/controllers/teacher_interface/qualification_requests_controller.rb +++ b/app/controllers/teacher_interface/qualification_requests_controller.rb @@ -5,7 +5,8 @@ class QualificationRequestsController < BaseController include HandleApplicationFormSection include HistoryTrackable - before_action :load_qualification_request, except: :index + before_action :load_qualification_request, + only: %i[edit_download update_download] define_history_origin :index define_history_reset :index @@ -14,6 +15,22 @@ def index @view_object = QualificationRequestsViewObject.new(application_form:) end + def check + @view_object = QualificationRequestsViewObject.new(application_form:) + end + + def submit + @qualification_requests ||= + application_form + .assessment + .qualification_requests + .joins(assessment: :application_form) + .consent_respondable + .update_all(consent_received_at: Time.zone.now) + + redirect_to %i[teacher_interface application_form] + end + def edit_download @form = QualificationRequestDownloadForm.new( diff --git a/app/view_objects/teacher_interface/application_form_view_object.rb b/app/view_objects/teacher_interface/application_form_view_object.rb index 81a114f353..f1740a8db1 100644 --- a/app/view_objects/teacher_interface/application_form_view_object.rb +++ b/app/view_objects/teacher_interface/application_form_view_object.rb @@ -152,6 +152,17 @@ def request_qualification_consent? qualification_requests.consent_respondable.exists? end + def qualification_consent_submitted? + return false if assessment.nil? + + required_qualification_requests = + qualification_requests.where(signed_consent_document_required: true) + + return false if required_qualification_requests.empty? + + required_qualification_requests.all?(&:consent_received?) + end + def show_work_history_under_submission_banner? application_form.qualification_changed_work_history_duration && !work_history_duration.enough_for_submission? diff --git a/app/view_objects/teacher_interface/qualification_requests_view_object.rb b/app/view_objects/teacher_interface/qualification_requests_view_object.rb index fc346c51fd..c781843214 100644 --- a/app/view_objects/teacher_interface/qualification_requests_view_object.rb +++ b/app/view_objects/teacher_interface/qualification_requests_view_object.rb @@ -17,6 +17,29 @@ def task_list_sections end end + def can_submit? + qualification_requests.all? do |qualification_request| + qualification_request.unsigned_consent_document_downloaded && + qualification_request.signed_consent_document.completed? + end + end + + def check_your_answers_fields + qualification_requests.each_with_object( + {}, + ) do |qualification_request, memo| + memo[qualification_request.id] = { + title: qualification_title(qualification_request.qualification), + value: qualification_request.signed_consent_document, + href: [ + :teacher_interface, + :application_form, + qualification_request.signed_consent_document, + ], + } + end + end + private attr_reader :application_form diff --git a/app/views/teacher_interface/application_forms/show/_submitted.html.erb b/app/views/teacher_interface/application_forms/show/_submitted.html.erb index 9f4c05fddf..a20a433a51 100644 --- a/app/views/teacher_interface/application_forms/show/_submitted.html.erb +++ b/app/views/teacher_interface/application_forms/show/_submitted.html.erb @@ -1,10 +1,25 @@ -<%= govuk_panel(title_text: view_object.further_information_request&.received? ? "Further information successfully submitted" : "Application complete") do %> +<% further_information_submitted = view_object.further_information_request&.received? %> +<% qualification_consent_submitted = view_object.qualification_consent_submitted? %> + +<% title_text = if qualification_consent_submitted + "Consent documents successfully submitted" + elsif further_information_submitted + "Further information successfully submitted" + else + "Application complete" + end %> + +<%= govuk_panel(title_text:) do %> Your application reference number
<%= view_object.application_form.reference %> <% end %> -<% if view_object.further_information_request&.received? %> +<% if qualification_consent_submitted %> +

We’ve sent you an email to confirm.

+

Once an assessor has checked the documents to make sure you’ve provided the required information, they’ll continue reviewing your application.

+

You can now close this page.

+<% elsif further_information_submitted %>

You’ve successfully submitted your further information

We’ve sent you an email to confirm that we’ve received it.

The assessor will continue to review your QTS application once they’ve checked that the further information you’ve provided can be accepted.

diff --git a/app/views/teacher_interface/qualification_requests/check.html.erb b/app/views/teacher_interface/qualification_requests/check.html.erb new file mode 100644 index 0000000000..2b28dc4865 --- /dev/null +++ b/app/views/teacher_interface/qualification_requests/check.html.erb @@ -0,0 +1,18 @@ +<% content_for :page_title, "Check your uploaded consent documents" %> +<% content_for :back_link_url, back_history_path(default: teacher_interface_application_form_qualification_requests_path) %> + +

Check your uploaded consent documents

+ +<%= render(CheckYourAnswersSummary::Component.new( + id: "check-your-answers", + model: @assessment, + title: t(".check_your_answers"), + fields: @view_object.check_your_answers_fields +)) %> + +<% if @view_object.can_submit? %> +

Submit your consent documents

+

By selecting the ‘Submit’ button you confirm that, to the best of your knowledge, the details you’ve provided are correct.

+

You will not be able to change your response, add new documents, or delete anything once you submit.

+ <%= govuk_button_to "Submit", submit_teacher_interface_application_form_qualification_requests_path %> +<% end %> diff --git a/app/views/teacher_interface/qualification_requests/index.html.erb b/app/views/teacher_interface/qualification_requests/index.html.erb index 8da3ffb4dc..96cc62cd37 100644 --- a/app/views/teacher_interface/qualification_requests/index.html.erb +++ b/app/views/teacher_interface/qualification_requests/index.html.erb @@ -5,4 +5,10 @@ <%= render(TaskList::Component.new(@view_object.task_list_sections)) %> -<%= govuk_button_link_to t("teacher_interface.application_forms.show.draft.save"), destroy_teacher_session_path, secondary: true %> +
+ <% if @view_object.can_submit? %> + <%= govuk_button_link_to "Continue", check_teacher_interface_application_form_qualification_requests_path %> + <% end %> + + <%= govuk_button_link_to t("teacher_interface.application_forms.show.draft.save"), destroy_teacher_session_path, secondary: true %> +
diff --git a/config/routes.rb b/config/routes.rb index 4b8630e1a7..c3e38c0959 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -352,6 +352,11 @@ get "download", to: "qualification_requests#edit_download" post "download", to: "qualification_requests#update_download" end + + collection do + get "check" + post "submit" + end end end diff --git a/spec/support/autoload/page_objects/teacher_interface/check_qualification_requests.rb b/spec/support/autoload/page_objects/teacher_interface/check_qualification_requests.rb new file mode 100644 index 0000000000..a390584cb7 --- /dev/null +++ b/spec/support/autoload/page_objects/teacher_interface/check_qualification_requests.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module PageObjects + module TeacherInterface + class CheckQualificationRequests < SitePrism::Page + set_url "/teacher/application/qualification-requests/check" + + element :heading, "h1" + section :summary_card, GovukSummaryCard, ".govuk-summary-card" + element :submit_button, ".govuk-button" + end + end +end diff --git a/spec/support/page_helpers.rb b/spec/support/page_helpers.rb index e6a7a51d37..fad7dd1bbc 100644 --- a/spec/support/page_helpers.rb +++ b/spec/support/page_helpers.rb @@ -375,6 +375,11 @@ def teacher_check_qualification_page PageObjects::TeacherInterface::CheckQualification.new end + def teacher_check_qualification_requests_page + @teacher_check_qualification_requests_page = + PageObjects::TeacherInterface::CheckQualificationRequests.new + end + def teacher_check_qualifications_page @teacher_check_qualifications_page ||= PageObjects::TeacherInterface::CheckQualifications.new diff --git a/spec/system/teacher_interface/qualification_consent_spec.rb b/spec/system/teacher_interface/qualification_consent_spec.rb index 21a2a64f68..f1e106f43b 100644 --- a/spec/system/teacher_interface/qualification_consent_spec.rb +++ b/spec/system/teacher_interface/qualification_consent_spec.rb @@ -47,6 +47,14 @@ when_i_dont_need_to_upload_another_file then_i_see_the(:teacher_qualification_requests_page) + + when_i_click_check_your_answers + then_i_see_the(:teacher_check_qualification_requests_page) + and_i_see_the_documents + + when_i_click_submit + then_i_see_the(:teacher_application_page) + and_i_see_the_consent_submitted_status end def given_there_is_an_application_form @@ -121,6 +129,27 @@ def when_i_dont_need_to_upload_another_file teacher_check_document_page.form.continue_button.click end + def when_i_click_check_your_answers + teacher_qualification_requests_page.check_your_answers_button.click + end + + def and_i_see_the_documents + expect(teacher_check_qualification_requests_page.summary_card).to be_visible + end + + def when_i_click_submit + teacher_check_qualification_requests_page.submit_button.click + end + + def and_i_see_the_consent_submitted_status + expect(teacher_submitted_application_page.panel.title.text).to eq( + "Consent documents successfully submitted", + ) + expect(teacher_submitted_application_page.panel.body.text).to eq( + "Your application reference number\n#{@application_form.reference}", + ) + end + def teacher @teacher ||= create(:teacher) end