diff --git a/app/controllers/assessor_interface/reference_requests_controller.rb b/app/controllers/assessor_interface/reference_requests_controller.rb index 8bcfecfb6d..e870f1194f 100644 --- a/app/controllers/assessor_interface/reference_requests_controller.rb +++ b/app/controllers/assessor_interface/reference_requests_controller.rb @@ -5,6 +5,7 @@ class ReferenceRequestsController < BaseController include HistoryTrackable before_action :set_individual_variables, except: :index + skip_before_action :track_history, only: :resend_email define_history_origin :index @@ -99,8 +100,8 @@ def update_verify_failed if @form.save redirect_to [ :assessor_interface, - requestable.application_form, - requestable.assessment, + application_form, + assessment, :reference_requests, ] else @@ -108,6 +109,27 @@ def update_verify_failed end end + def resend_email + if reference_request.requested? && !reference_request.received? + DeliverEmail.call( + application_form:, + mailer: RefereeMailer, + action: :reference_requested, + reference_request:, + ) + + flash[:info] = "The reference requested email has been resent." + end + + redirect_to [ + :verify, + :assessor_interface, + application_form, + assessment, + reference_request, + ] + end + private def set_individual_variables diff --git a/app/policies/assessor_interface/reference_request_policy.rb b/app/policies/assessor_interface/reference_request_policy.rb index d3e673f953..3faee75252 100644 --- a/app/policies/assessor_interface/reference_request_policy.rb +++ b/app/policies/assessor_interface/reference_request_policy.rb @@ -25,4 +25,8 @@ def update_verify_failed? end alias_method :edit_verify_failed?, :update_verify_failed? + + def resend_email? + user.assess_permission || user.verify_permission + end end diff --git a/app/views/assessor_interface/reference_requests/edit_verify.html.erb b/app/views/assessor_interface/reference_requests/edit_verify.html.erb index f891ced85c..acad41c29a 100644 --- a/app/views/assessor_interface/reference_requests/edit_verify.html.erb +++ b/app/views/assessor_interface/reference_requests/edit_verify.html.erb @@ -1,6 +1,7 @@ <% work_history = @reference_request.work_history %> <% can_edit_work_history = policy([:assessor_interface, work_history]).edit? %> <% can_update_verify_reference_request = @assessment.verify? && policy([:assessor_interface, @reference_request]).update_verify? %> +<% can_resend_email_reference_request = @assessment.verify? && policy([:assessor_interface, @reference_request]).resend_email? %> <% title = can_update_verify_reference_request ? "Review reference" : "View reference" %> @@ -34,16 +35,20 @@ end end - if can_edit_work_history - summary_list.with_row do |row| - row.with_key { "Job title of reference" } - row.with_value { work_history.contact_job } + summary_list.with_row do |row| + row.with_key { "Job title of reference" } + row.with_value { work_history.contact_job } + + if can_edit_work_history row.with_action(text: "Change", href: [:edit, :assessor_interface, @application_form, work_history]) end + end + + summary_list.with_row do |row| + row.with_key { "Email address of reference" } + row.with_value { work_history.contact_email } - summary_list.with_row do |row| - row.with_key { "Email address of reference" } - row.with_value { work_history.contact_email } + if can_edit_work_history row.with_action(text: "Change", href: [:edit, :assessor_interface, @application_form, work_history]) end end @@ -55,6 +60,18 @@ <% end %> <%= render "shared/reference_request_summary", reference_request: @reference_request, changeable: false %> + <% elsif @reference_request.requested? && can_resend_email_reference_request %> + <%= govuk_details(summary_text: "Resend reference request email") do %> + <%= govuk_warning_text(text: "Only resend reference requests if you have been asked to do so.") %> + + <% if (timeline_event = @application_form.timeline_events.email_sent.where(mailer_class_name: "RefereeMailer", mailer_action_name: "reference_requested").order(created_at: :desc).first) %> +

This email was last sent on <%= timeline_event.created_at.to_fs(:date_and_time) %>

+ <% end %> + + <%= govuk_button_link_to "Resend reference request email", [:resend_email, :assessor_interface, @application_form, @assessment, @reference_request] %> + +

Resending this email will not affect the original reminder schedule. Reminders will be sent automatically 2 weeks and 4 weeks after the original reference request email was sent.

+ <% end %> <% end %> <% if @reference_request.expired? %> diff --git a/config/routes.rb b/config/routes.rb index 63f6676006..afde3c0815 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -190,6 +190,7 @@ post "verify", to: "reference_requests#update_verify" get "verify-failed", to: "reference_requests#edit_verify_failed" post "verify-failed", to: "reference_requests#update_verify_failed" + get "resend-email", to: "reference_requests#resend_email" end end end diff --git a/spec/policies/assessor_interface/reference_request_policy_spec.rb b/spec/policies/assessor_interface/reference_request_policy_spec.rb index 5d09a92d77..d8ce26440f 100644 --- a/spec/policies/assessor_interface/reference_request_policy_spec.rb +++ b/spec/policies/assessor_interface/reference_request_policy_spec.rb @@ -62,6 +62,12 @@ it_behaves_like "a policy method requiring the verify permission" end + describe "#resend_email?" do + subject(:resend_email?) { policy.resend_email? } + it_behaves_like "a policy method requiring the assess permission" + it_behaves_like "a policy method requiring the verify permission" + end + describe "#destroy?" do subject(:destroy?) { policy.destroy? } it_behaves_like "a policy method without permission" diff --git a/spec/support/autoload/page_objects/assessor_interface/verify_reference_request.rb b/spec/support/autoload/page_objects/assessor_interface/verify_reference_request.rb index 3b41e26ade..5bf2e0a0c7 100644 --- a/spec/support/autoload/page_objects/assessor_interface/verify_reference_request.rb +++ b/spec/support/autoload/page_objects/assessor_interface/verify_reference_request.rb @@ -13,6 +13,11 @@ class VerifyReferenceRequest < VerifyRequestablePage elements :keys, ".govuk-summary-list__key" elements :values, ".govuk-summary-list__value" end + + section :send_email_details, ".govuk-details" do + element :summary, ".govuk-details__summary" + element :button, ".govuk-button" + end end end end diff --git a/spec/system/assessor_interface/verifying_references_spec.rb b/spec/system/assessor_interface/verifying_references_spec.rb index e8df45cfcc..437af8ab99 100644 --- a/spec/system/assessor_interface/verifying_references_spec.rb +++ b/spec/system/assessor_interface/verifying_references_spec.rb @@ -8,7 +8,38 @@ given_there_is_an_application_form_with_reference_request end + it "resend emails" do + when_i_visit_the(:assessor_application_page, reference:) + and_i_click_verify_references + then_i_see_the( + :assessor_reference_requests_page, + reference:, + assessment_id:, + ) + and_the_reference_request_status_is("WAITING ON") + + when_i_click_on_the_reference_request + then_i_see_the( + :assessor_verify_reference_request_page, + reference:, + assessment_id:, + id: reference_request.id, + ) + and_i_can_resend_the_email + + when_i_click_on_resend_email_summary + and_i_click_on_send_email_button + then_i_see_the( + :assessor_verify_reference_request_page, + reference:, + assessment_id:, + id: reference_request.id, + ) + end + it "verify received" do + given_the_reference_request_is_received + when_i_visit_the(:assessor_application_page, reference:) and_i_click_verify_references then_i_see_the( @@ -26,6 +57,7 @@ id: reference_request.id, ) and_i_see_the_reference_summary + and_i_cant_resend_the_email and_i_submit_yes_on_the_verify_form then_i_see_the( :assessor_reference_requests_page, @@ -79,6 +111,7 @@ assessment_id:, id: reference_request.id, ) + and_i_can_resend_the_email and_i_submit_yes_on_the_verify_form then_i_see_the( :assessor_verify_failed_reference_request_page, @@ -103,8 +136,12 @@ def given_there_is_an_application_form_with_reference_request application_form end + def given_the_reference_request_is_received + reference_request.received! + end + def given_the_reference_request_is_overdue - reference_request.update!(expired_at: Time.zone.now, received_at: nil) + reference_request.expired! end def and_i_click_verify_references @@ -179,7 +216,19 @@ def and_i_see_the_reference_summary ).to eq("Yes") expect( assessor_verify_reference_request_page.responses.values[10].text, - ).to eq(reference_request.additional_information_response) + ).to eq("None provided") + end + + def and_i_cant_resend_the_email + expect(assessor_verify_reference_request_page).to_not have_css( + ".govuk-details", + ) + end + + def and_i_can_resend_the_email + expect( + assessor_verify_reference_request_page.send_email_details, + ).to be_visible end def and_i_submit_yes_on_the_verify_form @@ -211,6 +260,14 @@ def then_i_see_the_verify_references_task_is_completed ).to eq("COMPLETED") end + def when_i_click_on_resend_email_summary + assessor_verify_reference_request_page.send_email_details.summary.click + end + + def and_i_click_on_send_email_button + assessor_verify_reference_request_page.send_email_details.button.click + end + def reference_request_task_item assessor_reference_requests_page.task_list.sections.first.items.first end @@ -242,7 +299,7 @@ def application_form ) create(:assessment_section, :passed, assessment:) create( - :received_reference_request, + :requested_reference_request, assessment:, work_history:, contact_response: true,