Skip to content

Commit

Permalink
Merge pull request #1986 from DFE-Digital/consent-statuses
Browse files Browse the repository at this point in the history
Add consent statuses
  • Loading branch information
thomasleese authored Feb 14, 2024
2 parents bd0e35a + 74343c3 commit 0933cc5
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 49 deletions.
3 changes: 3 additions & 0 deletions app/components/status_tag/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
18 changes: 10 additions & 8 deletions app/controllers/personas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: }
Expand Down Expand Up @@ -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)
Expand Down
42 changes: 33 additions & 9 deletions app/lib/application_form_status_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 ||
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion config/locales/components.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
37 changes: 6 additions & 31 deletions lib/tasks/example_data.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions spec/factories/qualification_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0933cc5

Please sign in to comment.