From ee553c2e87f5df0a490b4816c9e2120d74984f67 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Thu, 5 Oct 2023 14:51:29 +0100 Subject: [PATCH] Allow sending an assessment to review This makes it possible to send an assessment to review if the LoPS is unable to be verified by an admin user. --- ...ssment_recommendation_review_controller.rb | 5 +- app/lib/application_form_status_updater.rb | 7 +- app/models/assessment.rb | 73 +++++++++++++++---- .../application_forms_show_view_object.rb | 9 +-- 4 files changed, 66 insertions(+), 28 deletions(-) diff --git a/app/controllers/assessor_interface/assessment_recommendation_review_controller.rb b/app/controllers/assessor_interface/assessment_recommendation_review_controller.rb index de2be07bdf..3d333e7532 100644 --- a/app/controllers/assessor_interface/assessment_recommendation_review_controller.rb +++ b/app/controllers/assessor_interface/assessment_recommendation_review_controller.rb @@ -2,16 +2,19 @@ module AssessorInterface class AssessmentRecommendationReviewController < BaseController - before_action :authorize_assessor before_action :ensure_can_review before_action :load_assessment_and_application_form def edit + authorize %i[assessor_interface assessment_recommendation] + @professional_standing_request = assessment.professional_standing_request if assessment.professional_standing_request.verify_failed? end def update + authorize %i[assessor_interface assessment_recommendation] + ActiveRecord::Base.transaction do assessment.review! ApplicationFormStatusUpdater.call( diff --git a/app/lib/application_form_status_updater.rb b/app/lib/application_form_status_updater.rb index 84092500c8..c485bb2c58 100644 --- a/app/lib/application_form_status_updater.rb +++ b/app/lib/application_form_status_updater.rb @@ -87,12 +87,7 @@ def received_further_information def received_lops return false if teaching_authority_provides_written_statement - - professional_standing_requests - .reject(&:verified?) - .any? do |requestable| - requestable.received? || requestable.ready_for_review - end + received?(requestables: professional_standing_requests) end def received_qualification diff --git a/app/models/assessment.rb b/app/models/assessment.rb index 4402d66bee..ed1dfa3180 100644 --- a/app/models/assessment.rb +++ b/app/models/assessment.rb @@ -96,7 +96,7 @@ def can_award? elsif verify? enough_reference_requests_review_passed? && all_qualification_requests_review_passed? && - professional_standing_request_review_passed? + professional_standing_request_verify_passed? elsif review? professional_standing_request_review_passed? else @@ -113,10 +113,12 @@ def can_decline? (all_sections_finished? && any_section_failed? && any_section_declines?) elsif request_further_information? any_further_information_request_failed? - elsif verify? - true # TODO: check the state of verification requests elsif review? professional_standing_request_review_failed? + elsif verify? + enough_reference_requests_reviewed? && + all_qualification_requests_reviewed? && + professional_standing_request_verified? && !can_review? && !can_award? else false end @@ -134,15 +136,16 @@ def can_request_further_information? def can_review? return false unless application_form.created_under_new_regulations? - + return false unless verify? return false if skip_verification? - false + enough_reference_requests_reviewed? && + all_qualification_requests_reviewed? && + professional_standing_request_verify_failed? end def can_verify? return false unless application_form.created_under_new_regulations? - return false if skip_verification? all_sections_or_further_information_requests_passed? @@ -214,6 +217,7 @@ def any_further_information_request_failed? end def enough_reference_requests_review_passed? + return true if reference_requests.empty? return false unless references_verified months_count = @@ -230,6 +234,10 @@ def enough_reference_requests_review_passed? months_count >= 9 end + def enough_reference_requests_reviewed? + references_verified || reference_requests.empty? + end + def all_qualification_requests_review_passed? if qualification_requests.present? qualification_requests.all?(&:review_passed?) @@ -238,22 +246,57 @@ def all_qualification_requests_review_passed? end end + def all_qualification_requests_reviewed? + if qualification_requests.present? + qualification_requests.all?(&:reviewed?) + else + true + end + end + + def professional_standing_request_review_passed? + if professional_standing_request_part_of_verification? + professional_standing_request.review_passed? + else + true + end + end + + def professional_standing_request_verified? + if professional_standing_request_part_of_verification? + professional_standing_request.verified? + else + true + end + end + def professional_standing_request_review_failed? - if application_form.teaching_authority_provides_written_statement - return true + if professional_standing_request_part_of_verification? + professional_standing_request.review_failed? + else + false end - return true if professional_standing_request.nil? + end - professional_standing_request.review_failed? + def professional_standing_request_verify_passed? + if professional_standing_request_part_of_verification? + professional_standing_request.verify_passed? + else + true + end end - def professional_standing_request_review_passed? - if application_form.teaching_authority_provides_written_statement - return true + def professional_standing_request_verify_failed? + if professional_standing_request_part_of_verification? + professional_standing_request.verify_failed? + else + false end - return true if professional_standing_request.nil? + end - professional_standing_request.review_passed? + def professional_standing_request_part_of_verification? + !application_form.teaching_authority_provides_written_statement && + professional_standing_request.present? end def skip_verification? diff --git a/app/view_objects/assessor_interface/application_forms_show_view_object.rb b/app/view_objects/assessor_interface/application_forms_show_view_object.rb index a2e457fe9a..209b477f84 100644 --- a/app/view_objects/assessor_interface/application_forms_show_view_object.rb +++ b/app/view_objects/assessor_interface/application_forms_show_view_object.rb @@ -399,13 +399,10 @@ def review_verifications_task_list_item :review_verifications, ], status: - if assessment.recommendable? + if assessment.completed? || assessment.recommendable? :completed - elsif ( - !teaching_authority_provides_written_statement && - professional_standing_request&.reviewed? - ) || qualification_requests.any?(&:reviewed?) || - reference_requests.any?(&:reviewed?) + elsif !teaching_authority_provides_written_statement && + professional_standing_request&.reviewed? :in_progress else :not_started