Skip to content

Commit

Permalink
Merge pull request #2041 from DFE-Digital/multiple-fis
Browse files Browse the repository at this point in the history
Prevent duplicate FIs being created
  • Loading branch information
thomasleese authored Feb 27, 2024
2 parents f17b17c + 88c163d commit 40a1b1b
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class AssessmentRecommendationAwardController < BaseController
end

skip_before_action :track_history, only: :show
define_history_origin :edit

def show
redirect_to [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class AssessmentRecommendationDeclineController < BaseController
end

skip_before_action :track_history, only: :show
define_history_origin :edit

def show
redirect_to [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class AssessmentRecommendationReviewController < BaseController
end

skip_before_action :track_history, only: :show
define_history_origin :edit

def show
redirect_to [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,26 @@ 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

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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# frozen_string_literal: true

class AssessorInterface::FurtherInformationRequestPolicy < ApplicationPolicy
def show?
true
end

def create?
user.assess_permission
end
Expand Down
55 changes: 32 additions & 23 deletions app/services/create_further_information_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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) %>
Expand All @@ -20,6 +22,8 @@
<% elsif @view_object.assessment.verify? %>
<p class="govuk-body">You have submitted your verification requests.</p>
<p class="govuk-body">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.</p>
<% elsif @view_object.assessment.request_further_information? %>
<p class="govuk-body">You’ve successfully sent your further information request email to the applicant.</p>
<% elsif @view_object.application_form.declined_at.present? %>
<p class="govuk-body">The application will be deleted after 90 days unless the applicant chooses to appeal.</p>
<% elsif @view_object.application_form.dqt_trn_request.present? %>
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/services/create_further_information_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

This file was deleted.

5 changes: 0 additions & 5 deletions spec/support/page_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 40a1b1b

Please sign in to comment.