Skip to content

Commit

Permalink
Merge pull request #1702 from DFE-Digital/stop-using-application-form…
Browse files Browse the repository at this point in the history
…-status

Stop using old application form status fields
  • Loading branch information
thomasleese authored Nov 21, 2023
2 parents d661747 + 597a0a3 commit 09de651
Show file tree
Hide file tree
Showing 40 changed files with 218 additions and 591 deletions.
8 changes: 4 additions & 4 deletions app/controllers/personas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ def load_eligible_personas
%w[online written none]
.product(
%w[online written none],
%w[draft submitted waiting_on awarded declined],
%w[draft not_started verification completed],
)
.map do |status_check, sanction_check, status|
{ status_check:, sanction_check:, status: }
.map do |status_check, sanction_check, stage|
{ status_check:, sanction_check:, stage: }
end

def load_teacher_personas
Expand All @@ -129,7 +129,7 @@ def load_teacher_personas

region.status_check == persona[:status_check] &&
region.sanction_check == persona[:sanction_check] &&
application_form.status == persona[:status]
application_form.stage == persona[:stage]
end

if (application_form = found_application_form)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/teacher_interface/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def document
end

def redirect_unless_application_form_is_draft
if application_form.nil? || !application_form.draft?
if application_form.nil? || application_form.submitted?
redirect_to %i[teacher_interface application_form]
end
end
Expand Down
203 changes: 77 additions & 126 deletions app/lib/application_form_status_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,6 @@ def initialize(application_form:, user:)

def call
ActiveRecord::Base.transaction do
application_form.update!(
overdue_further_information:,
overdue_professional_standing: overdue_lops,
overdue_qualification:,
overdue_reference:,
received_further_information:,
received_professional_standing: received_lops,
received_qualification:,
received_reference:,
waiting_on_further_information:,
waiting_on_professional_standing: waiting_on_lops,
waiting_on_qualification:,
waiting_on_reference:,
)

application_form.status = status if application_form.status != status

if (old_action_required_by = application_form.action_required_by) !=
action_required_by
application_form.action_required_by = action_required_by
Expand Down Expand Up @@ -58,115 +41,6 @@ def call

attr_reader :application_form, :user

def overdue_further_information
overdue?(requestables: further_information_requests)
end

def overdue_lops
return false if teaching_authority_provides_written_statement
overdue?(requestables: professional_standing_requests)
end

def overdue_qualification
overdue?(requestables: qualification_requests)
end

def overdue_reference
return false if references_verified
overdue?(requestables: reference_requests)
end

def received_further_information
received?(requestables: further_information_requests)
end

def received_lops
return false if teaching_authority_provides_written_statement
received?(requestables: professional_standing_requests)
end

def received_qualification
received?(requestables: qualification_requests)
end

def received_reference
return false unless received?(requestables: reference_requests)

received_requests = reference_requests.filter(&:received?)

months_count =
WorkHistoryDuration.for_ids(
received_requests.map(&:work_history_id),
application_form:,
).count_months

most_recent_reference_request =
reference_requests.max_by { |request| request.work_history.start_date }

if months_count < 9
false
elsif months_count >= 20 &&
(region.checks_available? || most_recent_reference_request&.received?)
true
else
reference_requests.all? { |r| r.received? || r.expired? }
end
end

def waiting_on_further_information
waiting_on?(requestables: further_information_requests)
end

def waiting_on_lops
waiting_on?(requestables: professional_standing_requests)
end

def waiting_on_qualification
waiting_on?(requestables: qualification_requests)
end

def waiting_on_reference
return false if references_verified
waiting_on?(requestables: reference_requests)
end

def needs_references_verified?
reference_requests.present? && !waiting_on_reference &&
references_verified != true
end

def status
@status ||=
if dqt_trn_request&.potential_duplicate?
"potential_duplicate_in_dqt"
elsif application_form.withdrawn_at.present?
"withdrawn"
elsif application_form.declined_at.present?
"declined"
elsif application_form.awarded_at.present?
"awarded"
elsif dqt_trn_request.present?
"awarded_pending_checks"
elsif preliminary_check?
"preliminary_check"
elsif overdue_further_information || overdue_lops ||
overdue_qualification || overdue_reference
"overdue"
elsif received_further_information || received_lops ||
received_qualification || received_reference
"received"
elsif waiting_on_further_information || waiting_on_lops ||
waiting_on_qualification || waiting_on_reference
"waiting_on"
elsif assessment&.any_not_preliminary_section_finished?
"assessment_in_progress"
elsif application_form.submitted_at.present?
"submitted"
else
"draft"
end
end

def action_required_by
@action_required_by ||=
if application_form.withdrawn_at.present? ||
Expand Down Expand Up @@ -295,6 +169,83 @@ def requestable_statuses
.filter { |column| send(column) }
end

def overdue_further_information
overdue?(requestables: further_information_requests)
end

def overdue_lops
return false if teaching_authority_provides_written_statement
overdue?(requestables: professional_standing_requests)
end

def overdue_qualification
overdue?(requestables: qualification_requests)
end

def overdue_reference
return false if references_verified
overdue?(requestables: reference_requests)
end

def received_further_information
received?(requestables: further_information_requests)
end

def received_lops
return false if teaching_authority_provides_written_statement
received?(requestables: professional_standing_requests)
end

def received_qualification
received?(requestables: qualification_requests)
end

def received_reference
return false unless received?(requestables: reference_requests)

received_requests = reference_requests.filter(&:received?)

months_count =
WorkHistoryDuration.for_ids(
received_requests.map(&:work_history_id),
application_form:,
).count_months

most_recent_reference_request =
reference_requests.max_by { |request| request.work_history.start_date }

if months_count < 9
false
elsif months_count >= 20 &&
(region.checks_available? || most_recent_reference_request&.received?)
true
else
reference_requests.all? { |r| r.received? || r.expired? }
end
end

def waiting_on_further_information
waiting_on?(requestables: further_information_requests)
end

def waiting_on_lops
waiting_on?(requestables: professional_standing_requests)
end

def waiting_on_qualification
waiting_on?(requestables: qualification_requests)
end

def waiting_on_reference
return false if references_verified
waiting_on?(requestables: reference_requests)
end

def needs_references_verified?
reference_requests.present? && !waiting_on_reference &&
references_verified != true
end

def further_information_requests
@further_information_requests ||=
assessment&.further_information_requests&.to_a || []
Expand Down
46 changes: 0 additions & 46 deletions app/lib/filters/status.rb

This file was deleted.

53 changes: 14 additions & 39 deletions app/models/application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,6 @@ class ApplicationForm < ApplicationRecord
},
_suffix: true

enum status: {
draft: "draft",
submitted: "submitted",
preliminary_check: "preliminary_check",
assessment_in_progress: "assessment_in_progress",
waiting_on: "waiting_on",
received: "received",
overdue: "overdue",
awarded_pending_checks: "awarded_pending_checks",
awarded: "awarded",
declined: "declined",
potential_duplicate_in_dqt: "potential_duplicate_in_dqt",
withdrawn: "withdrawn",
}

delegate :country, to: :region, allow_nil: true

STATUS_COLUMNS = %i[
Expand All @@ -184,48 +169,38 @@ class ApplicationForm < ApplicationRecord

STATUS_COLUMNS.each { |column| enum column, STATUS_VALUES, prefix: column }

scope :assessable,
-> do
where(
status: %i[
preliminary_check
submitted
assessment_in_progress
waiting_on
received
overdue
],
)
end
scope :assessable, -> { where.not(stage: %i[draft completed]) }

scope :active,
-> do
where(hidden_from_assessment: false).merge(
assessable
.or(awarded_pending_checks)
.or(potential_duplicate_in_dqt)
.or(awarded.where("awarded_at >= ?", 90.days.ago))
.or(declined.where("declined_at >= ?", 90.days.ago))
.or(withdrawn.where("withdrawn_at >= ?", 90.days.ago)),
.or(where("awarded_at >= ?", 90.days.ago))
.or(where("declined_at >= ?", 90.days.ago))
.or(where("withdrawn_at >= ?", 90.days.ago)),
)
end

scope :destroyable,
-> do
draft
where(submitted_at: nil)
.where("created_at < ?", 6.months.ago)
.or(awarded.where("awarded_at < ?", 5.years.ago))
.or(declined.where("declined_at < ?", 5.years.ago))
.or(withdrawn.where("withdrawn_at < ?", 5.years.ago))
.or(where("awarded_at < ?", 5.years.ago))
.or(where("declined_at < ?", 5.years.ago))
.or(where("withdrawn_at < ?", 5.years.ago))
end

scope :remindable,
-> do
verification_stage.or(
draft_stage.where("created_at < ?", 5.months.ago),
where(submitted_at: nil).where("created_at < ?", 5.months.ago),
)
end

def submitted?
submitted_at.present?
end

def to_param
reference
end
Expand Down Expand Up @@ -310,7 +285,7 @@ def send_reminder_email(name, number_of_reminders_sent)
end

def expires_after
draft? ? 6.months : nil
submitted? ? nil : 6.months
end

def requested_at
Expand Down
Loading

0 comments on commit 09de651

Please sign in to comment.