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..f2083e2c18 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,8 +113,6 @@ 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? else @@ -134,15 +132,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 +213,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 +230,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 +242,49 @@ 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_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 diff --git a/spec/models/assessment_spec.rb b/spec/models/assessment_spec.rb index 4f27d29499..4665ef92aa 100644 --- a/spec/models/assessment_spec.rb +++ b/spec/models/assessment_spec.rb @@ -283,7 +283,7 @@ context "when awarded pending verification" do before { assessment.verify! } - it { is_expected.to be true } + it { is_expected.to be false } end end