diff --git a/app/controllers/assessor_interface/assessment_recommendation_award_controller.rb b/app/controllers/assessor_interface/assessment_recommendation_award_controller.rb index a02b0f1ac7..004001a996 100644 --- a/app/controllers/assessor_interface/assessment_recommendation_award_controller.rb +++ b/app/controllers/assessor_interface/assessment_recommendation_award_controller.rb @@ -13,7 +13,6 @@ class AssessmentRecommendationAwardController < BaseController end skip_before_action :track_history, only: :show - define_history_origin :edit def show redirect_to [ diff --git a/app/controllers/assessor_interface/assessment_recommendation_decline_controller.rb b/app/controllers/assessor_interface/assessment_recommendation_decline_controller.rb index c558d2aaa3..59421cae59 100644 --- a/app/controllers/assessor_interface/assessment_recommendation_decline_controller.rb +++ b/app/controllers/assessor_interface/assessment_recommendation_decline_controller.rb @@ -12,7 +12,6 @@ class AssessmentRecommendationDeclineController < BaseController end skip_before_action :track_history, only: :show - define_history_origin :edit def show redirect_to [ diff --git a/app/controllers/assessor_interface/assessment_recommendation_review_controller.rb b/app/controllers/assessor_interface/assessment_recommendation_review_controller.rb index e73e852ce1..00c58019d1 100644 --- a/app/controllers/assessor_interface/assessment_recommendation_review_controller.rb +++ b/app/controllers/assessor_interface/assessment_recommendation_review_controller.rb @@ -12,7 +12,6 @@ class AssessmentRecommendationReviewController < BaseController end skip_before_action :track_history, only: :show - define_history_origin :edit def show redirect_to [ diff --git a/app/controllers/assessor_interface/assessment_recommendation_verify_controller.rb b/app/controllers/assessor_interface/assessment_recommendation_verify_controller.rb index 46f445f424..b9750383d3 100644 --- a/app/controllers/assessor_interface/assessment_recommendation_verify_controller.rb +++ b/app/controllers/assessor_interface/assessment_recommendation_verify_controller.rb @@ -12,7 +12,6 @@ class AssessmentRecommendationVerifyController < BaseController end skip_before_action :track_history, only: :show - define_history_origin :verify_qualifications define_history_check :edit def show diff --git a/app/controllers/assessor_interface/further_information_requests_controller.rb b/app/controllers/assessor_interface/further_information_requests_controller.rb index 118c59bfb8..81de688598 100644 --- a/app/controllers/assessor_interface/further_information_requests_controller.rb +++ b/app/controllers/assessor_interface/further_information_requests_controller.rb @@ -13,12 +13,10 @@ class FurtherInformationRequestsController < BaseController end before_action :load_application_form_and_assessment, - only: %i[preview new show edit] + only: %i[preview new edit] before_action :load_new_further_information_request, only: %i[preview new] before_action :load_view_object, only: %i[edit update] - define_history_origin :preview - def preview end @@ -26,22 +24,15 @@ def new end def create - further_information_request = - ActiveRecord::Base.transaction do - assessment.request_further_information! - CreateFurtherInformationRequest.call(assessment:, user: current_staff) - end - - redirect_to [ - :assessor_interface, - application_form, - assessment, - further_information_request, - ] - end - - def show - @further_information_request = further_information_request + ActiveRecord::Base.transaction do + CreateFurtherInformationRequest.call(assessment:, user: current_staff) + assessment.request_further_information! + end + + redirect_to [:status, :assessor_interface, application_form] + rescue CreateFurtherInformationRequest::AlreadyExists + flash[:warning] = "Further information has already been requested." + render :preview, status: :unprocessable_entity end def edit diff --git a/app/policies/assessor_interface/further_information_request_policy.rb b/app/policies/assessor_interface/further_information_request_policy.rb index 0998db6858..5138eb264e 100644 --- a/app/policies/assessor_interface/further_information_request_policy.rb +++ b/app/policies/assessor_interface/further_information_request_policy.rb @@ -1,10 +1,6 @@ # frozen_string_literal: true class AssessorInterface::FurtherInformationRequestPolicy < ApplicationPolicy - def show? - true - end - def create? user.assess_permission end diff --git a/app/services/create_further_information_request.rb b/app/services/create_further_information_request.rb index c0b9f6adca..aff6be0600 100644 --- a/app/services/create_further_information_request.rb +++ b/app/services/create_further_information_request.rb @@ -9,37 +9,46 @@ def initialize(assessment:, user:) end def call - further_information_request = - ActiveRecord::Base.transaction do - requestable = - FurtherInformationRequest.create!( - assessment:, - items: - FurtherInformationRequestItemsFactory.call( - assessment_sections: assessment.sections, - ), - ) + raise AlreadyExists if assessment.further_information_requests.exists? - RequestRequestable.call(requestable:, user:) + create_and_request + send_email + end + + class AlreadyExists < StandardError + end + + private + + attr_reader :assessment, :user + + delegate :application_form, to: :assessment + + def create_and_request + ActiveRecord::Base.transaction do + requestable = + FurtherInformationRequest.create!( + assessment:, + items: + FurtherInformationRequestItemsFactory.call( + assessment_sections: assessment.sections, + ), + ) - application_form.reload + RequestRequestable.call(requestable:, user:) - ApplicationFormStatusUpdater.call(application_form:, user:) + application_form.reload - requestable - end + ApplicationFormStatusUpdater.call(application_form:, user:) + requestable + end + end + + def send_email TeacherMailer .with(application_form:) .further_information_requested .deliver_later - - further_information_request end - - private - - attr_reader :assessment, :user - - delegate :application_form, to: :assessment end diff --git a/app/views/assessor_interface/application_forms/status.html.erb b/app/views/assessor_interface/application_forms/status.html.erb index e0613bcfca..0090d8a87b 100644 --- a/app/views/assessor_interface/application_forms/status.html.erb +++ b/app/views/assessor_interface/application_forms/status.html.erb @@ -2,12 +2,14 @@ "Application sent for review" elsif @view_object.assessment.verify? "Verifications requested" + elsif @view_object.assessment.request_further_information? + "Further information email sent successfully" else "QTS application #{@view_object.application_form.reference} has been #{@view_object.status.downcase}" end %> <% content_for :page_title, title %> -<% content_for :back_link_url, back_history_path(default: assessor_interface_application_form_path(@view_object.application_form)) %> +<% content_for :back_link_url, back_history_path(origin: true, default: assessor_interface_application_form_path(@view_object.application_form)) %> <% if @view_object.application_form.awarded_at.present? %> <%= govuk_panel(text: title) %> @@ -20,6 +22,8 @@ <% elsif @view_object.assessment.verify? %>

You have submitted your verification requests.

These will now be verified by an admin. You do not need to do anything further with this application unless it is flagged for review.

+<% elsif @view_object.assessment.request_further_information? %> +

You’ve successfully sent your further information request email to the applicant.

<% elsif @view_object.application_form.declined_at.present? %>

The application will be deleted after 90 days unless the applicant chooses to appeal.

<% elsif @view_object.application_form.dqt_trn_request.present? %> diff --git a/app/views/assessor_interface/further_information_requests/show.erb b/app/views/assessor_interface/further_information_requests/show.erb deleted file mode 100644 index 50a28ee8ba..0000000000 --- a/app/views/assessor_interface/further_information_requests/show.erb +++ /dev/null @@ -1,9 +0,0 @@ -<% content_for :back_link_url, back_history_path(default: assessor_interface_application_form_path(@application_form)) %> - -<%= govuk_panel(title_text: "Further information email sent successfully") %> - -

You’ve successfully sent your further information request email to the applicant.

-

You can now return to the application itself, or go back to your list of applications.

- -<%= govuk_button_link_to "See application overview", assessor_interface_application_form_path(@application_form) %> -<%= govuk_button_link_to "Back to application list", assessor_interface_application_forms_path, secondary: true %> diff --git a/config/routes.rb b/config/routes.rb index b4397b8042..4cecac5622 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -104,7 +104,7 @@ resources :further_information_requests, path: "/further-information-requests", - only: %i[new create show edit update] do + only: %i[new create edit update] do get "preview", to: "further_information_requests#preview", on: :collection diff --git a/spec/policies/assessor_interface/further_information_request_policy_spec.rb b/spec/policies/assessor_interface/further_information_request_policy_spec.rb index ab1607418d..73f2065ee5 100644 --- a/spec/policies/assessor_interface/further_information_request_policy_spec.rb +++ b/spec/policies/assessor_interface/further_information_request_policy_spec.rb @@ -17,7 +17,7 @@ describe "#show?" do subject(:show?) { policy.show? } - it_behaves_like "a policy method with permission" + it_behaves_like "a policy method without permission" end describe "#preview?" do diff --git a/spec/services/create_further_information_request_spec.rb b/spec/services/create_further_information_request_spec.rb index 9aed43e1e7..3b99c6dbb8 100644 --- a/spec/services/create_further_information_request_spec.rb +++ b/spec/services/create_further_information_request_spec.rb @@ -45,4 +45,14 @@ it "records a requestable requested timeline event" do expect { call }.to have_recorded_timeline_event(:requestable_requested) end + + context "with an existing request" do + before { create(:further_information_request, assessment:) } + + it "raises an error" do + expect { call }.to raise_error( + CreateFurtherInformationRequest::AlreadyExists, + ) + end + end end diff --git a/spec/support/autoload/page_objects/assessor_interface/further_information_request.rb b/spec/support/autoload/page_objects/assessor_interface/further_information_request.rb deleted file mode 100644 index 4b2a2d40f0..0000000000 --- a/spec/support/autoload/page_objects/assessor_interface/further_information_request.rb +++ /dev/null @@ -1,8 +0,0 @@ -module PageObjects - module AssessorInterface - class FurtherInformationRequest < SitePrism::Page - set_url "/assessor/applications/{reference}/assessments/{assessment_id}" \ - "/further-information-requests/{further_information_request_id}" - end - end -end diff --git a/spec/support/page_helpers.rb b/spec/support/page_helpers.rb index f4c6e201db..99bafe13e6 100644 --- a/spec/support/page_helpers.rb +++ b/spec/support/page_helpers.rb @@ -122,11 +122,6 @@ def assessor_email_consent_letters_requests_assessment_recommendation_verify_pag PageObjects::AssessorInterface::EmailConsentLettersAssessmentRecommendationVerify.new end - def assessor_further_information_request_page - @assessor_further_information_request_page ||= - PageObjects::AssessorInterface::FurtherInformationRequest.new - end - def assessor_further_information_request_preview_page @assessor_further_information_request_preview_page ||= PageObjects::AssessorInterface::FurtherInformationRequestPreview.new diff --git a/spec/system/assessor_interface/requesting_further_information_spec.rb b/spec/system/assessor_interface/requesting_further_information_spec.rb index 1b6a571e11..7dae7afc68 100644 --- a/spec/system/assessor_interface/requesting_further_information_spec.rb +++ b/spec/system/assessor_interface/requesting_further_information_spec.rb @@ -50,12 +50,7 @@ and_i_see_the_email_preview when_i_click_send_to_applicant - then_i_see_the( - :assessor_further_information_request_page, - reference:, - assessment_id:, - further_information_request_id:, - ) + then_i_see_the(:assessor_application_status_page, reference:) and_i_receive_a_further_information_requested_email end @@ -166,8 +161,4 @@ def application_form_for_work_history_contact def assessment_id application_form.assessment.id end - - def further_information_request_id - FurtherInformationRequest.last.id - end end