From c450134dc9b7726c9e0c20f7adc2f221aa7efad4 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Mon, 5 Feb 2024 14:43:06 +0000 Subject: [PATCH 1/6] Add application qualification consent page This adds the page shown when the applicant signs in to the service if qualification requests are needed. --- .../application_form_view_object.rb | 14 ++++- .../application_forms/show.html.erb | 4 +- .../_request_qualification_consent.html.erb | 18 ++++++ ..._complete.html.erb => _submitted.html.erb} | 0 .../qualification_consent_spec.rb | 61 +++++++++++++++++++ 5 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 app/views/teacher_interface/application_forms/show/_request_qualification_consent.html.erb rename app/views/teacher_interface/application_forms/show/{_complete.html.erb => _submitted.html.erb} (100%) create mode 100644 spec/system/teacher_interface/qualification_consent_spec.rb 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 138924c8fc..3305ddadbf 100644 --- a/app/view_objects/teacher_interface/application_form_view_object.rb +++ b/app/view_objects/teacher_interface/application_form_view_object.rb @@ -146,6 +146,15 @@ def request_professional_standing_certificate? ) || false end + def request_qualification_consent? + return false if assessment.nil? + + qualification_requests + .joins(assessment: :application_form) + .consent_respondable + .exists? + end + def show_work_history_under_submission_banner? application_form.qualification_changed_work_history_duration && !work_history_duration.enough_for_submission? @@ -165,7 +174,10 @@ def show_work_history_under_induction_banner? :requires_preliminary_check, to: :application_form - delegate :professional_standing_request, to: :assessment, allow_nil: true + delegate :professional_standing_request, + :qualification_requests, + to: :assessment, + allow_nil: true def task_list_section(key, item_keys) { diff --git a/app/views/teacher_interface/application_forms/show.html.erb b/app/views/teacher_interface/application_forms/show.html.erb index 6bf0e75028..e786d2b63b 100644 --- a/app/views/teacher_interface/application_forms/show.html.erb +++ b/app/views/teacher_interface/application_forms/show.html.erb @@ -10,8 +10,10 @@ <%= render "teacher_interface/application_forms/show/further_information_requested", view_object: @view_object %> <% elsif @view_object.request_professional_standing_certificate? %> <%= render "teacher_interface/application_forms/show/request_professional_standing_certificate", view_object: @view_object %> +<% elsif @view_object.request_qualification_consent? %> + <%= render "teacher_interface/application_forms/show/request_qualification_consent", view_object: @view_object %> <% elsif @view_object.application_form.submitted? %> - <%= render "teacher_interface/application_forms/show/complete", view_object: @view_object %> + <%= render "teacher_interface/application_forms/show/submitted", view_object: @view_object %> <% elsif @view_object.from_ineligible_country? %> <%= render "teacher_interface/application_forms/show/from_ineligible_country", view_object: @view_object %> <% else %> diff --git a/app/views/teacher_interface/application_forms/show/_request_qualification_consent.html.erb b/app/views/teacher_interface/application_forms/show/_request_qualification_consent.html.erb new file mode 100644 index 0000000000..624207f747 --- /dev/null +++ b/app/views/teacher_interface/application_forms/show/_request_qualification_consent.html.erb @@ -0,0 +1,18 @@ +

We need your written consent to verify some of your qualifications

+ +

As part of your QTS application we need to verify some of your qualifications.

+ +

You need to sign and return a consent document for each qualification we need to verify. You will find these documents on the following screen.

+ +

What you need to do

+ +

Download each document, then:

+ + + +<%= govuk_start_button(text: "Start now", href: %i[teacher_interface application_form qualification_requests]) %> diff --git a/app/views/teacher_interface/application_forms/show/_complete.html.erb b/app/views/teacher_interface/application_forms/show/_submitted.html.erb similarity index 100% rename from app/views/teacher_interface/application_forms/show/_complete.html.erb rename to app/views/teacher_interface/application_forms/show/_submitted.html.erb diff --git a/spec/system/teacher_interface/qualification_consent_spec.rb b/spec/system/teacher_interface/qualification_consent_spec.rb new file mode 100644 index 0000000000..bf108408b4 --- /dev/null +++ b/spec/system/teacher_interface/qualification_consent_spec.rb @@ -0,0 +1,61 @@ +require "rails_helper" + +RSpec.describe "Teacher qualification consent", type: :system do + before do + given_the_service_is_open + given_i_am_authorized_as_a_user(teacher) + given_there_is_an_application_form + given_there_is_a_qualification_request + end + + it "save and sign out" do + when_i_visit_the(:teacher_application_page) + then_i_see_the(:teacher_application_page) + and_i_see_qualification_consent_content + end + + it "check your answers" do + when_i_visit_the(:teacher_application_page) + then_i_see_the(:teacher_application_page) + and_i_see_qualification_consent_content + end + + def given_there_is_an_application_form + application_form + end + + def given_there_is_a_qualification_request + qualification_request + end + + def and_i_see_qualification_consent_content + expect(teacher_application_page).to have_content( + "We need your written consent to verify some of your qualifications", + ) + end + + def teacher + @teacher ||= create(:teacher) + end + + def application_form + @application_form ||= + create( + :application_form, + :submitted, + :with_assessment, + :with_teaching_qualification, + statuses: %w[waiting_on_qualification], + teacher:, + ) + end + + def qualification_request + @qualification_request ||= + create( + :qualification_request, + :consent_requested, + assessment: application_form.assessment, + ) + end +end From fd44ec465cbae0f11c28865b47b9e1979936acc1 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Mon, 5 Feb 2024 16:22:56 +0000 Subject: [PATCH 2/6] Add sign out qualification consent content If the applicant signs out of the service we want to show dedicated content if they were asked to submit their qualification consent. --- .../qualification_requests_controller.rb | 13 +++++++ .../teachers/sessions_controller.rb | 19 ++++++++- .../qualification_requests/index.html.erb | 6 +++ .../teachers/sessions/signed_out.html.erb | 39 ++++++++++++------- config/routes.rb | 4 ++ .../teacher_interface/application.rb | 1 + .../qualification_requests.rb | 13 +++++++ spec/support/page_helpers.rb | 6 +-- .../qualification_consent_spec.rb | 27 +++++++++++-- 9 files changed, 106 insertions(+), 22 deletions(-) create mode 100644 app/controllers/teacher_interface/qualification_requests_controller.rb create mode 100644 app/views/teacher_interface/qualification_requests/index.html.erb create mode 100644 spec/support/autoload/page_objects/teacher_interface/qualification_requests.rb diff --git a/app/controllers/teacher_interface/qualification_requests_controller.rb b/app/controllers/teacher_interface/qualification_requests_controller.rb new file mode 100644 index 0000000000..df386ba434 --- /dev/null +++ b/app/controllers/teacher_interface/qualification_requests_controller.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module TeacherInterface + class QualificationRequestsController < BaseController + include HistoryTrackable + + define_history_origin :index + define_history_reset :index + + def index + end + end +end diff --git a/app/controllers/teachers/sessions_controller.rb b/app/controllers/teachers/sessions_controller.rb index be74fcfabf..6ada7331ae 100644 --- a/app/controllers/teachers/sessions_controller.rb +++ b/app/controllers/teachers/sessions_controller.rb @@ -53,6 +53,7 @@ def check_email end def signed_out + @section = params[:section] end protected @@ -61,8 +62,22 @@ def after_sign_in_path_for(resource) stored_location_for(resource) || teacher_interface_root_path end - def after_sign_out_path_for(_resource) - teacher_signed_out_path + def after_sign_out_path_for(resource) + if (application_form = resource.application_form) + view_object = + TeacherInterface::ApplicationFormViewObject.new(application_form:) + + section = + if view_object.request_qualification_consent? + "qualification_consent" + else + "application" + end + + teacher_signed_out_path(section:) + else + teacher_signed_out_path + end end private diff --git a/app/views/teacher_interface/qualification_requests/index.html.erb b/app/views/teacher_interface/qualification_requests/index.html.erb new file mode 100644 index 0000000000..ceed559094 --- /dev/null +++ b/app/views/teacher_interface/qualification_requests/index.html.erb @@ -0,0 +1,6 @@ +<% content_for :page_title, "Consent documents overview" %> +<% content_for :back_link_url, back_history_path(default: teacher_interface_application_form_path) %> + +

Consent documents overview

+ +<%= govuk_button_link_to t("teacher_interface.application_forms.show.draft.save"), destroy_teacher_session_path, secondary: true %> diff --git a/app/views/teachers/sessions/signed_out.html.erb b/app/views/teachers/sessions/signed_out.html.erb index 0ffd76c8d6..52db233dde 100644 --- a/app/views/teachers/sessions/signed_out.html.erb +++ b/app/views/teachers/sessions/signed_out.html.erb @@ -1,19 +1,30 @@ -<% content_for :page_title, "We’ve saved your QTS application progress" %> +<% content_for :page_title, "We’ve saved your progress" %> -

We’ve saved your QTS application progress

+

We’ve saved your progress

-

- You’ve been signed out of the Apply for qualified teacher status in England service. - All the information you’ve added to your application so far has been saved. -

+

You've been signed out of the Apply for qualified teacher status in England service.

-

- We’ll keep your application open for 6 months from the date you started it. - If you do not submit it within this time, you’ll need to make a new application. -

+<% if @section == "qualification_consent" %> +

+ We’ve saved your progress regarding submitting the written consent we need to proceed with your application. +

-

Continuing your application

+

+ <%= govuk_link_to "Sign in", new_teacher_session_url %> to complete your written consent tasks and submit your documents. +

+<% else %> +

+ All the information you’ve added to your application so far has been saved. +

-

- Use your email address to <%= govuk_link_to "sign in", new_teacher_session_url %> and complete your application. -

+

+ We’ll keep your application open for 6 months from the date you started it. + If you do not submit it within this time, you’ll need to make a new application. +

+ +

Continuing your application

+ +

+ Use your email address to <%= govuk_link_to "sign in", new_teacher_session_url %> and complete your application. +

+<% end %> diff --git a/config/routes.rb b/config/routes.rb index 4fc059e455..f3d7bea989 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -344,6 +344,10 @@ path: "/items", only: %i[edit update] end + + resources :qualification_requests, + path: "/qualification-requests", + only: %i[index] end resources :reference_requests, diff --git a/spec/support/autoload/page_objects/teacher_interface/application.rb b/spec/support/autoload/page_objects/teacher_interface/application.rb index c677ceb2a4..5a9469baac 100644 --- a/spec/support/autoload/page_objects/teacher_interface/application.rb +++ b/spec/support/autoload/page_objects/teacher_interface/application.rb @@ -9,6 +9,7 @@ class Application < SitePrism::Page element :check_answers, ".govuk-button:not(.govuk-button--secondary)" element :save_and_sign_out, ".govuk-button.govuk-button--secondary" + element :start_now_button, ".govuk-button:not(.govuk-button--secondary)" section :task_list, TaskList, ".app-task-list" diff --git a/spec/support/autoload/page_objects/teacher_interface/qualification_requests.rb b/spec/support/autoload/page_objects/teacher_interface/qualification_requests.rb new file mode 100644 index 0000000000..e1f21fc27c --- /dev/null +++ b/spec/support/autoload/page_objects/teacher_interface/qualification_requests.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module PageObjects + module TeacherInterface + class QualificationRequests < SitePrism::Page + set_url "/teacher/application/qualification-requests" + + element :check_your_answers_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 abb5fa7dc6..d10100384d 100644 --- a/spec/support/page_helpers.rb +++ b/spec/support/page_helpers.rb @@ -564,9 +564,9 @@ def teacher_personal_information_summary_page PageObjects::TeacherInterface::PersonalInformationSummary.new end - def teacher_qualifications_form_page - @teacher_qualifications_form_page = - PageObjects::TeacherInterface::QualificationForm.new + def teacher_qualification_requests_page + @teacher_qualification_requests_page = + PageObjects::TeacherInterface::QualificationRequests.new end def teacher_reference_received_page diff --git a/spec/system/teacher_interface/qualification_consent_spec.rb b/spec/system/teacher_interface/qualification_consent_spec.rb index bf108408b4..5b609091c2 100644 --- a/spec/system/teacher_interface/qualification_consent_spec.rb +++ b/spec/system/teacher_interface/qualification_consent_spec.rb @@ -11,13 +11,20 @@ it "save and sign out" do when_i_visit_the(:teacher_application_page) then_i_see_the(:teacher_application_page) - and_i_see_qualification_consent_content + and_i_see_qualification_consent_start_now_content + + when_i_click_the_start_button + then_i_see_the(:teacher_qualification_requests_page) + + when_i_click_the_save_and_sign_out_button + then_i_see_the(:teacher_signed_out_page) + and_i_see_qualification_consent_sign_out_content end it "check your answers" do when_i_visit_the(:teacher_application_page) then_i_see_the(:teacher_application_page) - and_i_see_qualification_consent_content + and_i_see_qualification_consent_start_now_content end def given_there_is_an_application_form @@ -28,12 +35,26 @@ def given_there_is_a_qualification_request qualification_request end - def and_i_see_qualification_consent_content + def and_i_see_qualification_consent_start_now_content expect(teacher_application_page).to have_content( "We need your written consent to verify some of your qualifications", ) end + def when_i_click_the_start_button + teacher_application_page.start_now_button.click + end + + def when_i_click_the_save_and_sign_out_button + teacher_qualification_requests_page.save_and_sign_out_button.click + end + + def and_i_see_qualification_consent_sign_out_content + expect(teacher_signed_out_page).to have_content( + "We’ve saved your progress regarding submitting the written consent", + ) + end + def teacher @teacher ||= create(:teacher) end From b45f43b09fd157bb32db3b55dfff36d7fc40d008 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Wed, 7 Feb 2024 14:58:43 +0000 Subject: [PATCH 3/6] Add consent document overview index page This adds the index page for viewing the qualification requests for a consent document overview. --- .../qualification_requests_controller.rb | 1 + app/lib/document_continue_redirection.rb | 2 +- app/models/qualification_request.rb | 6 +- .../application_form_view_object.rb | 5 +- .../qualification_requests_view_object.rb | 80 ++++++++++ .../qualification_requests/index.html.erb | 4 +- config/routes.rb | 7 +- .../lib/document_continue_redirection_spec.rb | 4 +- .../qualification_requests.rb | 2 + .../qualification_consent_spec.rb | 12 ++ ...qualification_requests_view_object_spec.rb | 143 ++++++++++++++++++ 11 files changed, 255 insertions(+), 11 deletions(-) create mode 100644 app/view_objects/teacher_interface/qualification_requests_view_object.rb create mode 100644 spec/view_objects/teacher_interface/qualification_requests_view_object_spec.rb diff --git a/app/controllers/teacher_interface/qualification_requests_controller.rb b/app/controllers/teacher_interface/qualification_requests_controller.rb index df386ba434..e4f0958593 100644 --- a/app/controllers/teacher_interface/qualification_requests_controller.rb +++ b/app/controllers/teacher_interface/qualification_requests_controller.rb @@ -8,6 +8,7 @@ class QualificationRequestsController < BaseController define_history_reset :index def index + @view_object = QualificationRequestsViewObject.new(application_form:) end end end diff --git a/app/lib/document_continue_redirection.rb b/app/lib/document_continue_redirection.rb index 2081847c57..bd3287fdf6 100644 --- a/app/lib/document_continue_redirection.rb +++ b/app/lib/document_continue_redirection.rb @@ -69,6 +69,6 @@ def further_information_request_url end def qualification_request_url - [:teacher_interface, :application_form, documentable] + %i[teacher_interface application_form qualification_requests] end end diff --git a/app/models/qualification_request.rb b/app/models/qualification_request.rb index 8b48a993f0..32cce94642 100644 --- a/app/models/qualification_request.rb +++ b/app/models/qualification_request.rb @@ -53,8 +53,10 @@ class QualificationRequest < ApplicationRecord .merge(ApplicationForm.assessable) end - scope :order_by_role, -> { order("qualifications.start_date": :desc) } - scope :order_by_user, -> { order("qualifications.created_at": :asc) } + scope :order_by_role, + -> { joins(:qualification).order("qualifications.start_date": :desc) } + scope :order_by_user, + -> { joins(:qualification).order("qualifications.created_at": :asc) } def expires_after 6.weeks 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 3305ddadbf..81a114f353 100644 --- a/app/view_objects/teacher_interface/application_form_view_object.rb +++ b/app/view_objects/teacher_interface/application_form_view_object.rb @@ -149,10 +149,7 @@ def request_professional_standing_certificate? def request_qualification_consent? return false if assessment.nil? - qualification_requests - .joins(assessment: :application_form) - .consent_respondable - .exists? + qualification_requests.consent_respondable.exists? end def show_work_history_under_submission_banner? diff --git a/app/view_objects/teacher_interface/qualification_requests_view_object.rb b/app/view_objects/teacher_interface/qualification_requests_view_object.rb new file mode 100644 index 0000000000..fc346c51fd --- /dev/null +++ b/app/view_objects/teacher_interface/qualification_requests_view_object.rb @@ -0,0 +1,80 @@ +# frozen_string_literal: true + +module TeacherInterface + class QualificationRequestsViewObject + include QualificationHelper + + def initialize(application_form:) + @application_form = application_form + end + + def task_list_sections + qualification_requests.map do |qualification_request| + { + title: qualification_title(qualification_request.qualification), + items: task_list_items(qualification_request), + } + end + end + + private + + attr_reader :application_form + + def qualification_requests + @qualification_requests ||= + application_form + .assessment + .qualification_requests + .order_by_user + .consent_respondable + end + + def task_list_items(qualification_request) + institution_name = qualification_request.qualification.institution_name + + [ + { + link: [ + :download, + :teacher_interface, + :application_form, + qualification_request, + ], + name: "Download #{institution_name} consent document", + status: + download_unsigned_consent_document_status(qualification_request), + }, + { + link: [ + :teacher_interface, + :application_form, + qualification_request.signed_consent_document, + ], + name: "Upload #{institution_name} consent document", + status: upload_signed_consent_document_status(qualification_request), + }, + ] + end + + def download_unsigned_consent_document_status(qualification_request) + if qualification_request.unsigned_consent_document_downloaded + :completed + else + :not_started + end + end + + def upload_signed_consent_document_status(qualification_request) + if qualification_request.unsigned_consent_document_downloaded + if qualification_request.signed_consent_document.completed? + :completed + else + :not_started + end + else + :cannot_start + end + end + end +end diff --git a/app/views/teacher_interface/qualification_requests/index.html.erb b/app/views/teacher_interface/qualification_requests/index.html.erb index ceed559094..8da3ffb4dc 100644 --- a/app/views/teacher_interface/qualification_requests/index.html.erb +++ b/app/views/teacher_interface/qualification_requests/index.html.erb @@ -1,6 +1,8 @@ <% content_for :page_title, "Consent documents overview" %> <% content_for :back_link_url, back_history_path(default: teacher_interface_application_form_path) %> -

Consent documents overview

+

Consent documents overview

+ +<%= 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 %> diff --git a/config/routes.rb b/config/routes.rb index f3d7bea989..180c0bea5d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -347,7 +347,12 @@ resources :qualification_requests, path: "/qualification-requests", - only: %i[index] + only: %i[index] do + member do + get "download" + get "upload" + end + end end resources :reference_requests, diff --git a/spec/lib/document_continue_redirection_spec.rb b/spec/lib/document_continue_redirection_spec.rb index dc583aff1d..876e7bbf37 100644 --- a/spec/lib/document_continue_redirection_spec.rb +++ b/spec/lib/document_continue_redirection_spec.rb @@ -135,7 +135,7 @@ it do is_expected.to eq( - [:teacher_interface, :application_form, qualification_request], + %i[teacher_interface application_form qualification_requests], ) end end @@ -152,7 +152,7 @@ it do is_expected.to eq( - [:teacher_interface, :application_form, qualification_request], + %i[teacher_interface application_form qualification_requests], ) end end diff --git a/spec/support/autoload/page_objects/teacher_interface/qualification_requests.rb b/spec/support/autoload/page_objects/teacher_interface/qualification_requests.rb index e1f21fc27c..53db529dbe 100644 --- a/spec/support/autoload/page_objects/teacher_interface/qualification_requests.rb +++ b/spec/support/autoload/page_objects/teacher_interface/qualification_requests.rb @@ -5,6 +5,8 @@ module TeacherInterface class QualificationRequests < SitePrism::Page set_url "/teacher/application/qualification-requests" + section :task_list, TaskList, ".app-task-list" + element :check_your_answers_button, ".govuk-button:not(.govuk-button--secondary)" element :save_and_sign_out_button, ".govuk-button.govuk-button--secondary" diff --git a/spec/system/teacher_interface/qualification_consent_spec.rb b/spec/system/teacher_interface/qualification_consent_spec.rb index 5b609091c2..13ae01a714 100644 --- a/spec/system/teacher_interface/qualification_consent_spec.rb +++ b/spec/system/teacher_interface/qualification_consent_spec.rb @@ -25,6 +25,10 @@ when_i_visit_the(:teacher_application_page) then_i_see_the(:teacher_application_page) and_i_see_qualification_consent_start_now_content + + when_i_click_the_start_button + then_i_see_the(:teacher_qualification_requests_page) + and_i_see_the_download_and_upload_tasks end def given_there_is_an_application_form @@ -55,6 +59,14 @@ def and_i_see_qualification_consent_sign_out_content ) end + def and_i_see_the_download_and_upload_tasks + task_list = teacher_qualification_requests_page.task_list + expect(task_list.sections.count).to eq(1) + + task_list_section = task_list.sections.first + expect(task_list_section.items.count).to eq(2) + end + def teacher @teacher ||= create(:teacher) end diff --git a/spec/view_objects/teacher_interface/qualification_requests_view_object_spec.rb b/spec/view_objects/teacher_interface/qualification_requests_view_object_spec.rb new file mode 100644 index 0000000000..8b3a0e8882 --- /dev/null +++ b/spec/view_objects/teacher_interface/qualification_requests_view_object_spec.rb @@ -0,0 +1,143 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe TeacherInterface::QualificationRequestsViewObject do + subject(:view_object) { described_class.new(application_form:) } + + let(:application_form) do + create(:application_form, :verification_stage, :with_assessment) + end + + describe "#task_list_sections" do + subject(:task_list_sections) { view_object.task_list_sections } + + it { is_expected.to be_empty } + + context "with a qualification request" do + let!(:qualification_request) do + create( + :qualification_request, + :consent_requested, + assessment: application_form.assessment, + qualification: + create( + :qualification, + application_form:, + title: "BSc Maths", + institution_name: "University of Maths", + ), + ) + end + + it do + is_expected.to eq( + [ + { + title: "BSc Maths (University of Maths)", + items: [ + { + name: "Download University of Maths consent document", + link: [ + :download, + :teacher_interface, + :application_form, + qualification_request, + ], + status: :not_started, + }, + { + name: "Upload University of Maths consent document", + link: [ + :teacher_interface, + :application_form, + qualification_request.signed_consent_document, + ], + status: :cannot_start, + }, + ], + }, + ], + ) + end + + context "when the unsigned consent document is downloaded" do + before do + qualification_request.update!( + unsigned_consent_document_downloaded: true, + ) + end + + it do + is_expected.to eq( + [ + { + title: "BSc Maths (University of Maths)", + items: [ + { + name: "Download University of Maths consent document", + link: [ + :download, + :teacher_interface, + :application_form, + qualification_request, + ], + status: :completed, + }, + { + name: "Upload University of Maths consent document", + link: [ + :teacher_interface, + :application_form, + qualification_request.signed_consent_document, + ], + status: :not_started, + }, + ], + }, + ], + ) + end + + context "when the signed consent document is uploaded" do + before do + qualification_request.signed_consent_document.update!( + completed: true, + ) + end + + it do + is_expected.to eq( + [ + { + title: "BSc Maths (University of Maths)", + items: [ + { + name: "Download University of Maths consent document", + link: [ + :download, + :teacher_interface, + :application_form, + qualification_request, + ], + status: :completed, + }, + { + name: "Upload University of Maths consent document", + link: [ + :teacher_interface, + :application_form, + qualification_request.signed_consent_document, + ], + status: :completed, + }, + ], + }, + ], + ) + end + end + end + end + end +end From 1e78047239c86d8ec6d4695d6d022023baa29783 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Wed, 7 Feb 2024 15:46:11 +0000 Subject: [PATCH 4/6] 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 From a6049f310e012d53f8e8466811431356cbe19f12 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Thu, 8 Feb 2024 10:09:43 +0000 Subject: [PATCH 5/6] Add upload consent document page This makes it possible for the applicant to upload their consent documents. --- .../documents/edit_uploads.html.erb | 58 +++++++++---------- .../teacher_interface/uploads/new.html.erb | 6 +- .../qualification_consent_spec.rb | 30 ++++++++++ 3 files changed, 63 insertions(+), 31 deletions(-) diff --git a/app/views/teacher_interface/documents/edit_uploads.html.erb b/app/views/teacher_interface/documents/edit_uploads.html.erb index 3879db2c10..55d41c61dd 100644 --- a/app/views/teacher_interface/documents/edit_uploads.html.erb +++ b/app/views/teacher_interface/documents/edit_uploads.html.erb @@ -1,38 +1,38 @@ <% content_for :page_title, title_with_error_prefix("Check your uploaded files", error: @form.errors.any?) %> <% content_for :back_link_url, back_history_path(default: teacher_interface_application_form_path) %> -

Check your uploaded files – <%= I18n.t("document.document_type.#{@document.document_type}") %> document

- -

Files added

- -<%= govuk_summary_list do |summary_list| - @document.uploads.order(:created_at).each_with_index do |upload, index| - summary_list.with_row do |row| - if @document.allow_multiple_uploads? - row.with_key(text: "File #{index + 1}") - end +<%= form_with model: @form, url: [:teacher_interface, :application_form, @document], method: :patch do |f| %> + <%= f.govuk_error_summary %> - row.with_value { upload_link_to(upload) } - - if @document.allow_multiple_uploads? - row.with_action( - text: "Delete", - href: delete_teacher_interface_application_form_document_upload_path(@document, upload), - visually_hidden_text: upload.attachment.filename - ) - else - row.with_action( - text: "Change", - href: new_teacher_interface_application_form_document_upload_path(@document), - visually_hidden_text: upload.attachment.filename - ) +

Check your uploaded files – <%= I18n.t("document.document_type.#{@document.document_type}") %> document

+ +

Files added

+ + <%= govuk_summary_list do |summary_list| + @document.uploads.order(:created_at).each_with_index do |upload, index| + summary_list.with_row do |row| + if @document.allow_multiple_uploads? + row.with_key(text: "File #{index + 1}") + end + + row.with_value { upload_link_to(upload) } + + if @document.allow_multiple_uploads? + row.with_action( + text: "Delete", + href: delete_teacher_interface_application_form_document_upload_path(@document, upload), + visually_hidden_text: upload.attachment.filename + ) + else + row.with_action( + text: "Change", + href: new_teacher_interface_application_form_document_upload_path(@document), + visually_hidden_text: upload.attachment.filename + ) + end end end - end -end %> - -<%= form_with model: @form, url: [:teacher_interface, :application_form, @document], method: :patch do |f| %> - <%= f.govuk_error_summary %> + end %> <% if @document.allow_multiple_uploads? %> <%= f.govuk_radio_buttons_fieldset :add_another, diff --git a/app/views/teacher_interface/uploads/new.html.erb b/app/views/teacher_interface/uploads/new.html.erb index b7570d9176..305b02e9cf 100644 --- a/app/views/teacher_interface/uploads/new.html.erb +++ b/app/views/teacher_interface/uploads/new.html.erb @@ -3,7 +3,7 @@ <%= render "upload_timeout_error" if @form.timeout_error %> -<% if @document.uploads.empty? %> +<% if @document.uploads.empty? || !@document.allow_multiple_uploads? %> <% if @document.english_language_proficiency? %>

Upload your English language proficiency test

This document must confirm that you have an English language proficiency test from an approved provider at level B2 of the Common European Framework of Reference for Languages (CEFR) scale.

@@ -69,7 +69,9 @@

<%= I18n.t("application_form.qualifications.upload.transcript.description") %>

<% elsif @document.signed_consent? %> -

Upload your signed consent document

+

Upload consent document

+

<%= qualification_title(@document.documentable.qualification) %>

+

Upload the signed document. Do not send it by email.

<% elsif @document.unsigned_consent? %>

Upload your unsigned consent document

<% elsif @document.written_statement? %> diff --git a/spec/system/teacher_interface/qualification_consent_spec.rb b/spec/system/teacher_interface/qualification_consent_spec.rb index cfdb6e59d8..21a2a64f68 100644 --- a/spec/system/teacher_interface/qualification_consent_spec.rb +++ b/spec/system/teacher_interface/qualification_consent_spec.rb @@ -38,6 +38,15 @@ when_i_check_the_downloaded_checkbox then_i_see_the(:teacher_qualification_requests_page) + + when_i_click_the_upload_task + then_i_see_the(:teacher_upload_document_page) + + when_i_upload_a_file + then_i_see_the(:teacher_check_document_page) + + when_i_dont_need_to_upload_another_file + then_i_see_the(:teacher_qualification_requests_page) end def given_there_is_an_application_form @@ -91,6 +100,27 @@ def when_i_check_the_downloaded_checkbox teacher_qualification_request_download_page.continue_button.click end + def when_i_click_the_upload_task + teacher_qualification_requests_page + .task_list + .sections + .first + .items + .second + .click + end + + def when_i_upload_a_file + teacher_upload_document_page.form.original_attachment.attach_file Rails.root.join( + file_fixture("upload.pdf"), + ) + teacher_upload_document_page.form.continue_button.click + end + + def when_i_dont_need_to_upload_another_file + teacher_check_document_page.form.continue_button.click + end + def teacher @teacher ||= create(:teacher) end From 54cc40e75d112c9885bde71e263a9d68e1e692fe Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Fri, 9 Feb 2024 20:18:25 +0000 Subject: [PATCH 6/6] Allow submitting consent documents This adds the functionality to submit consent documentsonce they've been signed. --- .../qualification_requests_controller.rb | 20 ++++++++++++- .../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, 147 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..e2d311e2cd 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,23 @@ 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 + .consent_respondable + .update_all(consent_received_at: Time.zone.now) + + TeacherMailer.with(application_form:).consent_submitted.deliver_later + + 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