diff --git a/app/controllers/assessor_interface/consent_requests_controller.rb b/app/controllers/assessor_interface/consent_requests_controller.rb index ccdbf4ab49..1353a134d7 100644 --- a/app/controllers/assessor_interface/consent_requests_controller.rb +++ b/app/controllers/assessor_interface/consent_requests_controller.rb @@ -4,7 +4,10 @@ module AssessorInterface class ConsentRequestsController < BaseController include HistoryTrackable - before_action :set_variables, except: :new + before_action :set_collection_variables, + only: %i[new edit_request update_request] + before_action :set_member_variables, + only: %i[edit_upload update_upload edit_review update_review] skip_before_action :track_history, only: :new @@ -23,6 +26,34 @@ def new ] end + def edit_request + end + + def update_request + if consent_requests.present? + ActiveRecord::Base.transaction do + consent_requests.each do |requestable| + RequestRequestable.call(requestable:, user: current_staff) + end + + application_form.reload + ApplicationFormStatusUpdater.call( + application_form:, + user: current_staff, + ) + end + + TeacherMailer.with(application_form:).consent_requested.deliver_later + end + + redirect_to [ + :assessor_interface, + application_form, + assessment, + :qualification_requests, + ] + end + def edit_upload @form = UploadUnsignedConsentDocumentForm.new(consent_request:) end @@ -92,7 +123,14 @@ def consent_request @consent_request ||= consent_requests.find(params[:id]) end - def set_variables + def set_collection_variables + authorize %i[assessor_interface consent_request] + @consent_requests = consent_requests + @application_form = application_form + @assessment = assessment + end + + def set_member_variables @consent_request = authorize [:assessor_interface, consent_request] @application_form = application_form @assessment = assessment diff --git a/app/policies/assessor_interface/consent_request_policy.rb b/app/policies/assessor_interface/consent_request_policy.rb index a4f2d0e218..2df7b20e0c 100644 --- a/app/policies/assessor_interface/consent_request_policy.rb +++ b/app/policies/assessor_interface/consent_request_policy.rb @@ -11,6 +11,12 @@ def update_upload? alias_method :edit_upload?, :update_upload? + def update_request? + user.verify_permission + end + + alias_method :edit_request?, :update_request? + def update_review? user.assess_permission end diff --git a/app/services/verify_assessment.rb b/app/services/verify_assessment.rb index b5ed5ea040..d71b23589a 100644 --- a/app/services/verify_assessment.rb +++ b/app/services/verify_assessment.rb @@ -66,9 +66,7 @@ def create_professional_standing_request def create_qualification_requests qualifications.map do |qualification| - QualificationRequest - .create!(assessment:, qualification:) - .tap { |requestable| RequestRequestable.call(requestable:, user:) } + QualificationRequest.create!(assessment:, qualification:) end 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 117090bc86..be50c4c77a 100644 --- a/app/view_objects/assessor_interface/qualification_requests_view_object.rb +++ b/app/view_objects/assessor_interface/qualification_requests_view_object.rb @@ -136,14 +136,29 @@ def send_consent_document_in_all_qualifications? end def send_consent_document_task_item + all_documents_completed = + consent_requests + .map(&:unsigned_consent_document) + .all? { |document| document.completed? && document.downloadable? } + + all_consents_requested = consent_requests.all?(&:requested?) + { - name: "Send consent document to applicant", - link: "#", + name: + "Send consent #{"document".pluralize(consent_requests.count)} to applicant", + link: + if all_documents_completed && !all_consents_requested + [ + :request, + :assessor_interface, + application_form, + assessment, + :consent_requests, + ] + end, status: - if consent_requests.map(&:unsigned_consent_document).all?( - &:completed? - ) - consent_requests.all?(&:requested?) ? "completed" : "not_started" + if all_documents_completed + all_consents_requested ? "completed" : "not_started" else "cannot_start" end, diff --git a/app/views/assessor_interface/consent_requests/edit_request.html.erb b/app/views/assessor_interface/consent_requests/edit_request.html.erb new file mode 100644 index 0000000000..0014cbfeec --- /dev/null +++ b/app/views/assessor_interface/consent_requests/edit_request.html.erb @@ -0,0 +1,21 @@ +<% 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) %> + +
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.
+ + diff --git a/config/routes.rb b/config/routes.rb index da2aacea7c..48bb6c6f55 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -101,6 +101,11 @@ end resources :consent_requests, path: "/consent-requests", only: %i[new] do + collection do + get "request", to: "consent_requests#edit_request" + post "request", to: "consent_requests#update_request" + end + member do get "upload", to: "consent_requests#edit_upload" post "upload", to: "consent_requests#update_upload" diff --git a/spec/policies/assessor_interface/consent_request_policy_spec.rb b/spec/policies/assessor_interface/consent_request_policy_spec.rb index b80b02cfd6..52b695e265 100644 --- a/spec/policies/assessor_interface/consent_request_policy_spec.rb +++ b/spec/policies/assessor_interface/consent_request_policy_spec.rb @@ -50,6 +50,16 @@ it_behaves_like "a policy method requiring the verify permission" end + describe "#update_request?" do + subject(:update?) { policy.update_request? } + it_behaves_like "a policy method requiring the verify permission" + end + + describe "#edit_request?" do + subject(:edit?) { policy.edit_request? } + it_behaves_like "a policy method requiring the verify permission" + end + describe "#update_review?" do subject(:update_review?) { policy.update_review? } it_behaves_like "a policy method requiring the assess permission" diff --git a/spec/services/verify_assessment_spec.rb b/spec/services/verify_assessment_spec.rb index 4309b9f84f..2e91c87144 100644 --- a/spec/services/verify_assessment_spec.rb +++ b/spec/services/verify_assessment_spec.rb @@ -85,21 +85,9 @@ end end - describe "creating qualification request" do - subject(:qualification_request) do - QualificationRequest.find_by(assessment:, qualification:) - end - - it { is_expected.to be_nil } - - context "after calling the service" do - before { call } - - it { is_expected.to_not be_nil } - - it "sets the attributes correctly" do - expect(qualification_request.requested?).to be true - end + describe "qualification request" do + it "creates a qualification request" do + expect { call }.to change(QualificationRequest, :count).by(1) end end 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..31bfe7128a --- /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}" \ + "/consent-requests/request" + + 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 4be5069b20..d630f2917d 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 71eaf9e306..a11b710f7e 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 791410b21d..a18e8b43e7 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 @@ -160,7 +160,7 @@ { name: "Upload consent document", link: [ - :edit, + :upload, :assessor_interface, application_form, assessment, @@ -170,7 +170,7 @@ }, { name: "Send consent document to applicant", - link: "#", + link: nil, status: "cannot_start", }, {