diff --git a/app/components/status_tag/component.rb b/app/components/status_tag/component.rb index 38d6365775..086209913f 100644 --- a/app/components/status_tag/component.rb +++ b/app/components/status_tag/component.rb @@ -37,6 +37,7 @@ def tags invalid: "red", not_started: "grey", overdue: "pink", + overdue_consent: "pink", overdue_further_information: "pink", overdue_lops: "pink", overdue_professional_standing: "pink", @@ -46,6 +47,7 @@ def tags pre_assessment: "pink", preliminary_check: "pink", received: "purple", + received_consent: "purple", received_further_information: "purple", received_lops: "purple", received_professional_standing: "purple", @@ -60,6 +62,7 @@ def tags verification_in_progress: "blue", verification_not_started: "grey", waiting_on: "yellow", + waiting_on_consent: "yellow", waiting_on_further_information: "yellow", waiting_on_lops: "yellow", waiting_on_professional_standing: "yellow", diff --git a/app/controllers/personas_controller.rb b/app/controllers/personas_controller.rb index 1eb67958ea..2d5a16b5a6 100644 --- a/app/controllers/personas_controller.rb +++ b/app/controllers/personas_controller.rb @@ -117,7 +117,14 @@ def load_eligible_personas %w[online written none] .product( %w[online written none], - %w[draft not_started verification awarded declined], + %w[ + draft + not_started + waiting_on_consent + waiting_on_further_information + awarded + declined + ], ) .map do |status_check, sanction_check, stage_or_status| { status_check:, sanction_check:, stage_or_status: } @@ -148,13 +155,8 @@ def load_teacher_personas stage_or_status = persona[:stage_or_status] - if stage_or_status == "awarded" - application_form.awarded_at.present? - elsif stage_or_status == "declined" - application_form.declined_at.present? - else - application_form.stage == stage_or_status - end + application_form.stage == stage_or_status || + application_form.statuses.include?(stage_or_status) end if (application_form = found_application_form) diff --git a/app/lib/application_form_status_updater.rb b/app/lib/application_form_status_updater.rb index bfe2a1e3b6..ab966585bd 100644 --- a/app/lib/application_form_status_updater.rb +++ b/app/lib/application_form_status_updater.rb @@ -55,11 +55,12 @@ def action_required_by overdue_further_information || overdue_qualification || received_further_information || received_qualification "assessor" - elsif preliminary_check? || need_to_request_lops? || overdue_lops || - received_lops || overdue_reference || received_reference + elsif preliminary_check? || need_to_request_lops? || overdue_consent || + received_consent || overdue_lops || received_lops || + overdue_reference || received_reference "admin" - elsif waiting_on_further_information || waiting_on_lops || - waiting_on_qualification || waiting_on_reference + elsif waiting_on_consent || waiting_on_further_information || + waiting_on_lops || waiting_on_qualification || waiting_on_reference "external" elsif application_form.submitted_at.present? "assessor" @@ -79,9 +80,10 @@ def stage elsif preliminary_check? || (teaching_authority_provides_written_statement && waiting_on_lops) "pre_assessment" - elsif assessment_in_verify? || need_to_request_lops? || overdue_lops || - overdue_qualification || overdue_reference || received_lops || - received_qualification || received_reference || waiting_on_lops || + elsif assessment_in_verify? || need_to_request_lops? || overdue_consent || + overdue_lops || overdue_qualification || overdue_reference || + received_consent || received_lops || received_qualification || + received_reference || waiting_on_consent || waiting_on_lops || waiting_on_qualification || waiting_on_reference "verification" elsif overdue_further_information || received_further_information || @@ -164,11 +166,15 @@ def need_to_request_lops? def requestable_statuses @requestable_statuses ||= %w[overdue received waiting_on] - .product(%w[further_information lops qualification reference]) + .product(%w[consent further_information lops qualification reference]) .map { |status, requestable| "#{status}_#{requestable}" } .filter { |column| send(column) } end + def overdue_consent + overdue?(requestables: qualification_requests.reject(&:requested?)) + end + def overdue_further_information overdue?(requestables: further_information_requests) end @@ -179,13 +185,22 @@ def overdue_lops end def overdue_qualification - overdue?(requestables: qualification_requests) + overdue?(requestables: qualification_requests.select(&:requested?)) end def overdue_reference overdue?(requestables: reference_requests) end + def received_consent + qualification_requests + .reject(&:verified?) + .reject(&:reviewed?) + .reject(&:expired?) + .reject(&:requested?) + .any?(&:consent_received?) + end + def received_further_information received?(requestables: further_information_requests) end @@ -223,6 +238,15 @@ def received_reference end end + def waiting_on_consent + qualification_requests + .reject(&:verified?) + .reject(&:reviewed?) + .reject(&:expired?) + .reject(&:consent_received?) + .any?(&:consent_requested?) + end + def waiting_on_further_information waiting_on?(requestables: further_information_requests) end diff --git a/config/locales/components.en.yml b/config/locales/components.en.yml index 8d1bf0adbb..2ddb621875 100644 --- a/config/locales/components.en.yml +++ b/config/locales/components.en.yml @@ -16,6 +16,7 @@ en: invalid: Invalid not_started: Not started overdue: Overdue + overdue_consent: Overdue consent overdue_further_information: Overdue further information overdue_lops: Overdue LOPS overdue_professional_standing: Overdue professional standing @@ -25,12 +26,13 @@ en: pre_assessment: Pre-assessment preliminary_check: Preliminary check received: Received + received_and_overdue: Received (overdue) + received_consent: Received consent received_further_information: Received further information received_lops: Received LOPS received_professional_standing: Received professional standing received_qualification: Received qualification received_reference: Received reference - received_and_overdue: Received (overdue) rejected: Rejected requested: Waiting on review: Review @@ -40,6 +42,7 @@ en: verification_in_progress: Verification in progress verification_not_started: Verification not started waiting_on: Waiting on + waiting_on_consent: Waiting on consent waiting_on_further_information: Waiting on further information waiting_on_lops: Waiting on LOPS waiting_on_professional_standing: Waiting on professional standing diff --git a/lib/tasks/example_data.rake b/lib/tasks/example_data.rake index b7defa4890..1d145fb08f 100644 --- a/lib/tasks/example_data.rake +++ b/lib/tasks/example_data.rake @@ -156,12 +156,6 @@ def application_form_traits_for(region) end def create_requestables(application_form, assessment, state) - status_prefix = { - expired: "overdue", - received: "received", - requested: "waiting_on", - }.fetch(state) - unless application_form.teaching_authority_provides_written_statement assessment.sections.update_all(passed: true) end @@ -173,18 +167,6 @@ def create_requestables(application_form, assessment, state) ) FactoryBot.create(:professional_standing_request, state, assessment:) - application_form.update!( - statuses: ["#{status_prefix}_lops"], - stage: - ( - if application_form.teaching_authority_provides_written_statement - "pre_assessment" - else - "verification" - end - ), - ) - unless application_form.teaching_authority_provides_written_statement assessment.verify! end @@ -194,26 +176,18 @@ def create_requestables(application_form, assessment, state) FactoryBot.create(:reference_request, state, assessment:, work_history:) end - application_form.update!( - statuses: ["#{status_prefix}_reference"], - stage: "verification", - ) assessment.verify! elsif (qualifications = application_form.qualifications).present? && rand(2).zero? qualifications.each do |qualification| FactoryBot.create( :qualification_request, - state, + [state, "consent_#{state}"].sample, assessment:, qualification:, ) end - application_form.update!( - statuses: ["#{status_prefix}_qualification"], - stage: "verification", - ) assessment.verify! elsif state != :expired FactoryBot.create( @@ -222,12 +196,13 @@ def create_requestables(application_form, assessment, state) :with_items, assessment:, ) - application_form.update!( - statuses: ["#{status_prefix}_further_information"], - stage: "assessment", - ) assessment.request_further_information! end + + ApplicationFormStatusUpdater.call( + application_form:, + user: "Example data generator", + ) end def create_application_forms diff --git a/spec/factories/qualification_requests.rb b/spec/factories/qualification_requests.rb index 43cbd1ee91..a3c86b3031 100644 --- a/spec/factories/qualification_requests.rb +++ b/spec/factories/qualification_requests.rb @@ -50,6 +50,18 @@ end end + trait :consent_received do + consent_requested + consent_received_at do + Faker::Time.between(from: 1.month.ago, to: Time.zone.now) + end + end + + trait :consent_expired do + consent_requested + expired_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } + end + trait :requested do requested_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } end