From 85b633a02e029939b273385679538c51cd8dd289 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Thu, 22 Feb 2024 09:51:05 +0100 Subject: [PATCH] Add send consent document to applicant page This adds a page which allows the assessor to send the uploaded consent documents to the applicant. --- .../qualification_requests_controller.rb | 20 ++++++++++ .../qualification_request_policy.rb | 7 ++++ .../qualification_requests_view_object.rb | 34 ++++++++++++----- ...dit_send_signed_consent_documents.html.erb | 23 +++++++++++ config/routes.rb | 6 +++ .../qualification_request_policy_spec.rb | 14 +++++++ .../send_signed_consent_documents.rb | 12 ++++++ spec/support/page_helpers.rb | 5 +++ .../verifying_qualifications_spec.rb | 38 ++++++++++++++++++- ...qualification_requests_view_object_spec.rb | 2 +- 10 files changed, 148 insertions(+), 13 deletions(-) create mode 100644 app/views/assessor_interface/qualification_requests/edit_send_signed_consent_documents.html.erb create mode 100644 spec/support/autoload/page_objects/assessor_interface/send_signed_consent_documents.rb diff --git a/app/controllers/assessor_interface/qualification_requests_controller.rb b/app/controllers/assessor_interface/qualification_requests_controller.rb index d008e414ed..cf27b6a282 100644 --- a/app/controllers/assessor_interface/qualification_requests_controller.rb +++ b/app/controllers/assessor_interface/qualification_requests_controller.rb @@ -12,6 +12,8 @@ class QualificationRequestsController < BaseController edit_unsigned_consent_document update_unsigned_consent_document generate_unsigned_consent_document + edit_send_signed_consent_documents + update_send_signed_consent_documents ] before_action :set_member_variables, only: %i[ @@ -77,6 +79,24 @@ def generate_unsigned_consent_document ) end + def edit_send_signed_consent_documents + end + + def update_send_signed_consent_documents + ActiveRecord::Base.transaction do + qualification_requests.consent_method_signed.each(&:consent_requested!) + end + + TeacherMailer.with(application_form:).consent_requested.deliver_later + + redirect_to [ + :assessor_interface, + application_form, + assessment, + :qualification_requests, + ] + end + def edit received = if requestable.received? diff --git a/app/policies/assessor_interface/qualification_request_policy.rb b/app/policies/assessor_interface/qualification_request_policy.rb index b1f685196e..54bdefb662 100644 --- a/app/policies/assessor_interface/qualification_request_policy.rb +++ b/app/policies/assessor_interface/qualification_request_policy.rb @@ -24,6 +24,13 @@ def generate_unsigned_consent_document? user.assess_permission end + def update_send_signed_consent_documents? + user.assess_permission + end + + alias_method :edit_send_signed_consent_documents?, + :update_send_signed_consent_documents? + def update? user.assess_permission end diff --git a/app/view_objects/assessor_interface/qualification_requests_view_object.rb b/app/view_objects/assessor_interface/qualification_requests_view_object.rb index aa5bfbdbe6..d197a9da33 100644 --- a/app/view_objects/assessor_interface/qualification_requests_view_object.rb +++ b/app/view_objects/assessor_interface/qualification_requests_view_object.rb @@ -134,18 +134,32 @@ def send_consent_document_in_all_qualifications? end def send_consent_document_task_item + consent_requests = qualification_requests.consent_method_signed + + all_documents_completed = + consent_requests + .map(&:unsigned_consent_document) + .all? { |document| document.completed? && document.downloadable? } + all_consent_requested = consent_requests.all?(&:consent_requested?) + { - name: "Send consent document to applicant", - link: "#", + name: + "Send consent #{"document".pluralize(consent_requests.count)} to applicant", + link: + if all_documents_completed && !all_consent_requested + [ + :send_signed_consent_documents, + :assessor_interface, + application_form, + assessment, + :qualification_requests, + ] + end, status: - if qualification_requests.map(&:unsigned_consent_document).all?( - &:completed? - ) - if qualification_requests.all?(&:consent_requested?) - "completed" - else - "not_started" - end + if all_documents_completed && all_consent_requested + "completed" + elsif all_documents_completed + "not_started" else "cannot_start" end, diff --git a/app/views/assessor_interface/qualification_requests/edit_send_signed_consent_documents.html.erb b/app/views/assessor_interface/qualification_requests/edit_send_signed_consent_documents.html.erb new file mode 100644 index 0000000000..175e834e20 --- /dev/null +++ b/app/views/assessor_interface/qualification_requests/edit_send_signed_consent_documents.html.erb @@ -0,0 +1,23 @@ +<% consent_requests = @qualification_requests.consent_method_signed %> + +<% title = "Send consent #{"document".pluralize(consent_requests.count)} to applicant" %> + +<% content_for :page_title, title %> +<% content_for :back_link_url, back_history_path(default: assessor_interface_application_form_assessment_qualification_requests_path) %> + +

<%= title %>

+ +

You need to request a signature for the uploaded consent documents for:

+ + + +

Select ‘Continue’ to automatically send an email and the uploaded consent document to the applicant.

+ +
+ <%= govuk_button_to "Continue", [:send_signed_consent_documents, :assessor_interface, @application_form, @assessment, :qualification_requests] %> + <%= render "shared/assessor_interface/cancel_link" %> +
diff --git a/config/routes.rb b/config/routes.rb index 3d8879da92..a2da24d1ce 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -142,6 +142,12 @@ to: "qualification_requests#update_unsigned_consent_document" get "generate-unsigned-consent-document", to: "qualification_requests#generate_unsigned_consent_document" + + get "send-signed-consent-documents", + to: "qualification_requests#edit_send_signed_consent_documents" + post "send-signed-consent-documents", + to: + "qualification_requests#update_send_signed_consent_documents" end member do diff --git a/spec/policies/assessor_interface/qualification_request_policy_spec.rb b/spec/policies/assessor_interface/qualification_request_policy_spec.rb index 1bf48ce3a0..04bf4835be 100644 --- a/spec/policies/assessor_interface/qualification_request_policy_spec.rb +++ b/spec/policies/assessor_interface/qualification_request_policy_spec.rb @@ -46,6 +46,20 @@ it_behaves_like "a policy method requiring the assess permission" end + describe "#update_send_signed_consent_documents?" do + subject(:update_send_signed_consent_documents?) do + policy.update_send_signed_consent_documents? + end + it_behaves_like "a policy method requiring the assess permission" + end + + describe "#edit_send_signed_consent_documents?" do + subject(:edit_send_signed_consent_documents?) do + policy.edit_send_signed_consent_documents? + end + it_behaves_like "a policy method requiring the assess permission" + end + describe "#show?" do subject(:show?) { policy.show? } it_behaves_like "a policy method without permission" diff --git a/spec/support/autoload/page_objects/assessor_interface/send_signed_consent_documents.rb b/spec/support/autoload/page_objects/assessor_interface/send_signed_consent_documents.rb new file mode 100644 index 0000000000..77c5c86bde --- /dev/null +++ b/spec/support/autoload/page_objects/assessor_interface/send_signed_consent_documents.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module PageObjects + module AssessorInterface + class SendSignedConsentDocuments < SitePrism::Page + set_url "/assessor/applications/{reference}/assessments/{assessment_id}" \ + "/qualification-requests/send-signed-consent-documents" + + element :continue_button, ".govuk-button:not(.govuk-button--secondary)" + end + end +end diff --git a/spec/support/page_helpers.rb b/spec/support/page_helpers.rb index e356b20d54..96f4e0d411 100644 --- a/spec/support/page_helpers.rb +++ b/spec/support/page_helpers.rb @@ -231,6 +231,11 @@ def assessor_review_verifications_page PageObjects::AssessorInterface::ReviewVerifications.new end + def assessor_send_signed_consent_documents_page + @assessor_send_signed_consent_documents_page ||= + PageObjects::AssessorInterface::SendSignedConsentDocuments.new + end + def assessor_timeline_page @assessor_timeline_page ||= PageObjects::AssessorInterface::Timeline.new end diff --git a/spec/system/assessor_interface/verifying_qualifications_spec.rb b/spec/system/assessor_interface/verifying_qualifications_spec.rb index e8c89a28a5..7ec93c4c75 100644 --- a/spec/system/assessor_interface/verifying_qualifications_spec.rb +++ b/spec/system/assessor_interface/verifying_qualifications_spec.rb @@ -48,8 +48,16 @@ when_i_upload_the_consent_document then_i_see_the(:assessor_qualification_requests_page, reference:) and_the_upload_consent_document_task_item_is_completed + and_the_send_consent_document_to_applicant_task_is_not_started - and_i_go_back_to_overview + when_i_click_the_send_consent_document_to_applicant_task + then_i_see_the(:assessor_send_signed_consent_documents_page) + + when_i_send_the_signed_consent_documents + then_i_see_the(:assessor_qualification_requests_page, reference:) + and_the_send_consent_document_to_applicant_task_is_completed + + when_i_go_back_to_overview then_i_see_the(:assessor_application_page, reference:) end @@ -135,7 +143,27 @@ def and_the_upload_consent_document_task_item_is_completed expect(upload_consent_document_task_item.status_tag.text).to eq("COMPLETED") end - def and_i_go_back_to_overview + def and_the_send_consent_document_to_applicant_task_is_not_started + expect(send_consent_document_to_applicant_task_item.status_tag.text).to eq( + "NOT STARTED", + ) + end + + def when_i_click_the_send_consent_document_to_applicant_task + send_consent_document_to_applicant_task_item.click + end + + def when_i_send_the_signed_consent_documents + assessor_send_signed_consent_documents_page.continue_button.click + end + + def and_the_send_consent_document_to_applicant_task_is_completed + expect(send_consent_document_to_applicant_task_item.status_tag.text).to eq( + "COMPLETED", + ) + end + + def when_i_go_back_to_overview assessor_qualification_requests_page.continue_button.click end @@ -163,6 +191,12 @@ def upload_consent_document_task_item ) end + def send_consent_document_to_applicant_task_item + assessor_qualification_requests_page.task_lists.third.find_item( + "Send consent document to applicant", + ) + end + def application_form @application_form ||= create( diff --git a/spec/view_objects/assessor_interface/qualification_requests_view_object_spec.rb b/spec/view_objects/assessor_interface/qualification_requests_view_object_spec.rb index c0613c8bc9..f0cd03553f 100644 --- a/spec/view_objects/assessor_interface/qualification_requests_view_object_spec.rb +++ b/spec/view_objects/assessor_interface/qualification_requests_view_object_spec.rb @@ -169,7 +169,7 @@ }, { name: "Send consent document to applicant", - link: "#", + link: nil, status: "cannot_start", }, {