Skip to content

Commit

Permalink
Stop using statuses
Browse files Browse the repository at this point in the history
This updates various parts of the system to stop using the status (and
related) fields, as they've been replaced by others.
  • Loading branch information
thomasleese committed Sep 28, 2023
1 parent cb42951 commit d90f73e
Show file tree
Hide file tree
Showing 42 changed files with 162 additions and 366 deletions.
8 changes: 4 additions & 4 deletions app/controllers/personas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,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 @@ -134,7 +134,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
46 changes: 0 additions & 46 deletions app/lib/filters/status.rb

This file was deleted.

55 changes: 15 additions & 40 deletions app/models/application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ class ApplicationForm < ApplicationRecord
belongs_to :assessor, class_name: "Staff", optional: true
belongs_to :reviewer, class_name: "Staff", optional: true

validates :submitted_at, presence: true, unless: :draft?
validates :awarded_at, absence: true, if: :declined_at?
validates :awarded_at, absence: true, if: :withdrawn_at?
validates :declined_at, absence: true, if: :awarded_at?
Expand Down Expand Up @@ -146,21 +145,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 @@ -183,40 +167,31 @@ 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
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, -> { draft.where("created_at < ?", 5.months.ago) }
scope :remindable,
-> { where(submitted_at: nil).where("created_at < ?", 5.months.ago) }

def submitted?
submitted_at.present?
end

def teaching_qualification
qualifications.find(&:is_teaching_qualification?)
Expand Down Expand Up @@ -273,7 +248,7 @@ def send_reminder_email(number_of_reminders_sent)
end

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

def requested_at
Expand Down
4 changes: 3 additions & 1 deletion app/models/further_information_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def after_received(*)
end

def after_expired(user:)
DeclineQTS.call(application_form:, user:) unless application_form.withdrawn?
if application_form.withdrawn_at.nil?
DeclineQTS.call(application_form:, user:)
end
end

def after_reviewed(user:)
Expand Down
4 changes: 2 additions & 2 deletions app/models/professional_standing_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def after_received(*)

def after_expired(user:)
if application_form.teaching_authority_provides_written_statement &&
!application_form.withdrawn?
application_form.withdrawn_at.nil?
DeclineQTS.call(application_form:, user:)
end
end
Expand All @@ -55,7 +55,7 @@ def after_expired(user:)
private

def should_send_received_email?
!application_form.declined? &&
application_form.declined_at.nil? &&
application_form.teaching_authority_provides_written_statement
end
end
2 changes: 1 addition & 1 deletion app/models/teacher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Teacher < ApplicationRecord

def application_form
@application_form ||=
application_forms.not_withdrawn.order(created_at: :desc).first
application_forms.where(withdrawn_at: nil).order(created_at: :desc).first
end

def send_magic_link(*)
Expand Down
7 changes: 2 additions & 5 deletions app/services/award_qts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ def initialize(
end

def call
return if application_form.awarded?
return if application_form.awarded_at.present?

unless application_form.awarded_pending_checks? ||
application_form.potential_duplicate_in_dqt?
raise InvalidState
end
raise InvalidState if application_form.dqt_trn_request.nil?

raise MissingTRN if trn.blank?

Expand Down
12 changes: 7 additions & 5 deletions app/services/backfill_preliminary_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ def applications_forms
requires_preliminary_check: false,
)
.merge(
ApplicationForm.submitted.or(
ApplicationForm.waiting_on.where(
teaching_authority_provides_written_statement: true,
waiting_on_professional_standing: true,
ApplicationForm
.where.not(submitted_at: nil)
.or(
ApplicationForm.pre_assessment_stage.where(
"'waiting_on_lops' = ANY (statuses)",
teaching_authority_provides_written_statement: true,
),
),
),
)
end
end
2 changes: 1 addition & 1 deletion app/services/decline_qts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(application_form:, user:)
end

def call
return if application_form.declined?
return if application_form.declined_at.present?

ActiveRecord::Base.transaction do
application_form.update!(declined_at: Time.zone.now)
Expand Down
13 changes: 7 additions & 6 deletions app/services/rollback_assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def validate_state

def has_submitted_another_application_form?
teacher.application_form != application_form &&
!teacher.application_form.draft?
teacher.application_form.submitted?
end

def valid_assessment_state?
assessment.award? || assessment.decline? ||
(assessment.unknown? && application_form.declined?)
(assessment.unknown? && application_form.declined_at.present?)
end

def update_assessment
Expand All @@ -63,9 +63,11 @@ def previously_further_information_requested?
delegate :teacher, to: :application_form

def update_application_form
if application_form.awarded?
if application_form.awarded_at.present?
application_form.update!(awarded_at: nil)
elsif application_form.declined?
end

if application_form.declined_at.present?
application_form.update!(declined_at: nil)
end

Expand All @@ -74,8 +76,7 @@ def update_application_form

def delete_draft_application_forms
ApplicationForm
.draft
.where(teacher:)
.where(submitted_at: nil, teacher:)
.find_each do |application_form|
DestroyApplicationForm.call(application_form:)
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/withdraw_application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(application_form:, user:)
end

def call
return if application_form.withdrawn?
return if application_form.withdrawn_at.present?

ActiveRecord::Base.transaction do
application_form.update!(withdrawn_at: Time.zone.now)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def application_form
@application_form ||=
ApplicationForm
.includes(assessment: :sections)
.not_draft
.where.not(submitted_at: nil)
.find(params[:id])
end

Expand All @@ -28,7 +28,7 @@ def task_list_sections
end

def status
application_form.status.humanize
application_form.statuses.map(&:humanize).to_sentence
end

def email_used_as_reference_in_this_application_form?
Expand All @@ -42,7 +42,7 @@ def other_application_forms_where_email_used_as_reference
.includes(:application_form)
.where(canonical_contact_email: canonical_email)
.where.not(application_form:)
.where.not(application_form: { status: "draft" })
.where.not(application_form: { submitted_at: nil })
.map(&:application_form)
end

Expand Down Expand Up @@ -74,6 +74,10 @@ def management_tasks
].compact
end

def waiting_on_references?
assessment.reference_requests.reject(&:reviewed?).any?(&:requested?)
end

private

attr_reader :params, :current_staff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def work_history_application_forms_contact_email_used_as_teacher

ApplicationForm
.includes(:teacher)
.not_draft
.where.not(submitted_at: nil)
.where(
teacher: {
canonical_email: work_history_canonical_contact_emails,
Expand All @@ -123,7 +123,7 @@ def work_history_application_forms_contact_email_used_as_reference
canonical_contact_email: work_history_canonical_contact_emails,
)
.where.not(application_form:)
.where.not(application_form: { status: "draft" })
.where.not(application_form: { submitted_at: nil })
.group_by(&:canonical_contact_email)
.transform_values do |work_histories|
work_histories.map(&:application_form)
Expand Down
18 changes: 9 additions & 9 deletions app/views/assessor_interface/application_forms/status.html.erb
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<% content_for :page_title, "Application" %>
<% content_for :back_link_url, assessor_interface_application_form_path(@view_object.application_form) %>
<% content_for :back_link_url, [:assessor_interface, @view_object.application_form] %>

<% if @view_object.application_form.waiting_on? %>
<% if @view_object.waiting_on_references? %>
<%= govuk_panel(title_text: "Reference requests sent successfully") %>
<% else %>
<%= govuk_panel(title_text: "QTS application #{@view_object.application_form.reference} has been #{@view_object.status.downcase}") %>
<% end %>

<% unless @view_object.application_form.waiting_on? %>
<p class="govuk-body">The status of this application has been changed to <%= @view_object.status %>.</p>
<% unless @view_object.waiting_on_references? %>
<p class="govuk-body">The status of this application has been changed to <%= @view_object.status %>.</p>
<% end %>

<% if @view_object.application_form.declined? %>
<% if @view_object.application_form.declined_at.present? %>
<p class="govuk-body">The application will be deleted after 90 days unless the applicant chooses to appeal.</p>
<% elsif @view_object.application_form.awarded_pending_checks? %>
<% elsif @view_object.application_form.dqt_trn_request.present? %>
<p class="govuk-body">This status will appear while the award is reconciled with the information in the Database of Qualified Teachers (DQT).</p>
<p class="govuk-body">Once these checks are complete, the status will change to ‘Awarded’ and the applicant will receive the email telling them they’ve been awarded QTS.</p>
<% elsif @view_object.application_form.waiting_on? %>
<% elsif @view_object.waiting_on_references? %>
<p class="govuk-body">You’ve successfully sent requests to each of the references that the applicant provided.</p>
<p class="govuk-body govuk-!-font-weight-bold">The applicant will also receive an email to tell them you’ve contacted their references.</p>
<p class="govuk-body">When the references respond, you’ll see the status of the application change to ‘Received’.</p>
Expand All @@ -25,6 +25,6 @@
<p class="govuk-body">You can now return to the application itself, or go back to your list of applications.</p>

<div class="govuk-button-group">
<%= govuk_button_link_to "Back to application list", assessor_interface_application_forms_path %>
<%= govuk_button_link_to "See application overview", assessor_interface_application_form_path(@view_object.application_form), secondary: true %>
<%= govuk_button_link_to "Back to application list", %i[assessor_interface application_forms] %>
<%= govuk_button_link_to "See application overview", [:assessor_interface, @view_object.application_form], secondary: true %>
</div>
Loading

0 comments on commit d90f73e

Please sign in to comment.