Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make requestables verifiable #1733

Merged
merged 4 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions app/components/timeline_entry/component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@
<% elsif timeline_event.requestable_reviewed? && timeline_event.requestable.is_a?(FurtherInformationRequest) %>
<p class="govuk-body">Further information request has been assessed.</p>

<% if (failure_assessor_note = description_vars[:failure_assessor_note]).present? %>
<%= govuk_inset_text do %>
<%= simple_format failure_assessor_note %>
<% end %>
<% if (note = description_vars[:note]).present? %>
<%= govuk_inset_text { simple_format note } %>
<% end %>
<% elsif timeline_event.information_changed? %>
<p class="govuk-body">
Expand Down
9 changes: 6 additions & 3 deletions app/components/timeline_entry/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,16 @@ def requestable_received_vars

def requestable_reviewed_vars
{
passed: timeline_event.requestable.passed,
failure_assessor_note: timeline_event.requestable.failure_assessor_note,
passed: timeline_event.requestable.review_passed,
note: timeline_event.requestable.review_note,
}
end

def requestable_verified_vars
{}
{
passed: timeline_event.requestable.verify_passed,
note: timeline_event.requestable.verify_note,
}
end

def information_changed_vars
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ def edit
RequestableReviewForm.new(
requestable: view_object.further_information_request,
user: current_staff,
passed: view_object.further_information_request.passed,
failure_assessor_note:
view_object.further_information_request.failure_assessor_note,
passed: view_object.further_information_request.review_passed,
note: view_object.further_information_request.review_note,
)
end

Expand Down Expand Up @@ -116,7 +115,7 @@ def view_object
def requestable_review_form_params
params.require(:assessor_interface_requestable_review_form).permit(
:passed,
:failure_assessor_note,
:note,
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def edit_review
RequestableReviewForm.new(
requestable:,
user: current_staff,
passed: requestable.passed,
failure_assessor_note: requestable.failure_assessor_note,
passed: requestable.review_passed,
note: requestable.review_note,
)
end

Expand Down Expand Up @@ -77,7 +77,7 @@ def review_form_params
params.require(:assessor_interface_requestable_review_form).permit(
:reviewed,
:passed,
:failure_assessor_note,
:note,
)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def edit
user: current_staff,
received:,
passed:,
failure_assessor_note: requestable.failure_assessor_note,
note: requestable.review_note,
failed:,
)
end
Expand Down Expand Up @@ -74,7 +74,7 @@ def form_params
params.require(:assessor_interface_qualification_request_form).permit(
:received,
:passed,
:failure_assessor_note,
:note,
:failed,
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def set_individual_variables
def requestable_review_form_params
params.require(:assessor_interface_requestable_review_form).permit(
:passed,
:failure_assessor_note,
:note,
)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def save
end

if requestable.requested? && requestable.reviewed?
requestable.update!(passed: nil, reviewed_at: nil)
requestable.update!(review_passed: nil, reviewed_at: nil)
ApplicationFormStatusUpdater.call(application_form:, user:)
end

Expand Down
10 changes: 4 additions & 6 deletions app/forms/assessor_interface/qualification_request_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ class AssessorInterface::QualificationRequestForm
attribute :passed, :boolean
validates :passed, inclusion: [true, false], if: :received

attribute :failure_assessor_note, :string
validates :failure_assessor_note,
presence: true,
if: -> { received && passed == false }
attribute :note, :string
validates :note, presence: true, if: -> { received && passed == false }

attribute :failed, :boolean
validates :failed, inclusion: [true, false], unless: :received
Expand All @@ -32,14 +30,14 @@ def save
end

if review_passed.nil?
requestable.update!(passed: nil, reviewed_at: nil)
requestable.update!(review_passed: nil, reviewed_at: nil)
ApplicationFormStatusUpdater.call(application_form:, user:)
else
ReviewRequestable.call(
requestable:,
user:,
passed: review_passed,
failure_assessor_note:,
note:,
)
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/forms/assessor_interface/requestable_review_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class AssessorInterface::RequestableReviewForm
attribute :passed, :boolean
validates :passed, inclusion: [true, false]

attribute :failure_assessor_note, :string
validates :failure_assessor_note, presence: true, if: -> { passed == false }
attribute :note, :string
validates :note, presence: true, if: -> { passed == false }

def save
return false if invalid?

ReviewRequestable.call(requestable:, user:, passed:, failure_assessor_note:)
ReviewRequestable.call(requestable:, user:, passed:, note:)

true
end
Expand Down
23 changes: 23 additions & 0 deletions app/forms/assessor_interface/requestable_verify_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

class AssessorInterface::RequestableVerifyForm
include ActiveModel::Model
include ActiveModel::Attributes

attr_accessor :requestable, :user
validates :requestable, :user, presence: true

attribute :passed, :boolean
validates :passed, inclusion: [true, false]

attribute :note, :string
validates :note, presence: true, if: -> { passed == false }

def save
return false if invalid?

VerifyRequestable.call(requestable:, user:, passed:, note:)

true
end
end
25 changes: 14 additions & 11 deletions app/models/assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def can_award?
if skip_verification?
all_sections_or_further_information_requests_passed?
else
verify? && enough_reference_requests_passed? &&
all_qualification_requests_passed? &&
professional_standing_request_passed?
verify? && enough_reference_requests_review_passed? &&
all_qualification_requests_review_passed? &&
professional_standing_request_review_passed?
end
else
all_sections_or_further_information_requests_passed?
Expand Down Expand Up @@ -186,40 +186,43 @@ def no_section_declines?

def all_further_information_requests_passed?
further_information_requests.present? &&
further_information_requests.all?(&:passed)
further_information_requests.all?(&:review_passed?)
end

def any_further_information_request_failed?
further_information_requests.present? &&
further_information_requests.any?(&:failed)
further_information_requests.any?(&:review_failed?)
end

def enough_reference_requests_passed?
def enough_reference_requests_review_passed?
return false unless references_verified

months_count =
WorkHistoryDuration.new(
work_history_relation:
application_form.work_histories.where(
id: reference_requests.where(passed: true).map(&:work_history_id),
id:
reference_requests.where(review_passed: true).map(
&:work_history_id
),
),
).count_months

months_count >= 9
end

def all_qualification_requests_passed?
def all_qualification_requests_review_passed?
if qualification_requests.present?
qualification_requests.all?(&:passed)
qualification_requests.all?(&:review_passed?)
else
true
end
end

def professional_standing_request_passed?
def professional_standing_request_review_passed?
if !application_form.teaching_authority_provides_written_statement &&
professional_standing_request.present?
professional_standing_request.passed?
professional_standing_request.review_passed?
else
true
end
Expand Down
47 changes: 32 additions & 15 deletions app/models/concerns/requestable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ module Requestable
included do
belongs_to :assessment

validates :reviewed_at, presence: true, unless: -> { passed.nil? }

scope :requested, -> { where.not(requested_at: nil) }
scope :received, -> { where.not(received_at: nil) }
scope :respondable,
Expand All @@ -36,29 +34,44 @@ def received?
received_at != nil
end

def reviewed!(passed)
update!(passed:, reviewed_at: Time.zone.now)
def reviewed?
review_passed != nil
end

def reviewed?
passed != nil
def review_passed?
review_passed == true
end

def failed
return nil if passed.nil?
passed == false
def review_failed?
review_passed == false
end

def verified?
try(:verify_passed) != nil
end

def verify_passed?
try(:verify_passed) == true
end

def verify_failed?
try(:verify_passed) == false
end

def status
if reviewed_at.present?
passed ? "accepted" : "rejected"
elsif received_at.present? && expired_at.present?
if verify_passed? || review_passed?
"accepted"
elsif review_failed?
"rejected"
elsif verify_failed?
"review"
elsif received? && expired?
"received_and_overdue"
elsif expired_at.present?
elsif expired?
"overdue"
elsif received_at.present?
elsif received?
"received"
elsif requested_at.present?
elsif requested?
"waiting_on"
else
"not_started"
Expand All @@ -76,4 +89,8 @@ def after_received(user:)
def after_reviewed(user:)
# implement logic after this requestable has been reviewed
end

def after_verified(user:)
# implement logic after this requestable has been verified
end
end
26 changes: 13 additions & 13 deletions app/models/further_information_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#
# id :bigint not null, primary key
# expired_at :datetime
# failure_assessor_note :string default(""), not null
# passed :boolean
# received_at :datetime
# requested_at :datetime
# review_note :string default(""), not null
# review_passed :boolean
# reviewed_at :datetime
# working_days_assessment_started_to_creation :integer
# working_days_received_to_recommendation :integer
Expand Down Expand Up @@ -71,18 +71,18 @@ def after_expired(user:)
end

def after_reviewed(user:)
items
.select(&:work_history_contact?)
.each do |item|
UpdateWorkHistoryContact.call(
user:,
work_history: item.work_history,
name: item.contact_name,
job: item.contact_job,
email: item.contact_email,
)
end
update_work_history_contact_items(user:) if review_passed?
end

def after_verified(user:)
update_work_history_contact_items(user:) if verify_passed?
end

delegate :teacher, to: :application_form

private

def update_work_history_contact_items(user:)
items.each { |item| item.update_work_history_contact(user:) }
end
end
12 changes: 12 additions & 0 deletions app/models/further_information_request_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,16 @@ def is_teaching_qualification?
failure_reason_key,
)
end

def update_work_history_contact(user:)
return unless work_history_contact?

UpdateWorkHistoryContact.call(
user:,
work_history:,
name: contact_name,
job: contact_job,
email: contact_email,
)
end
end
Loading
Loading