Skip to content

Commit

Permalink
Merge pull request #1717 from DFE-Digital/requestable-requested-at-ex…
Browse files Browse the repository at this point in the history
…pired-at

Track verification dates
  • Loading branch information
thomasleese authored Sep 28, 2023
2 parents a07a0fb + 9741d16 commit 24ac887
Show file tree
Hide file tree
Showing 34 changed files with 281 additions and 90 deletions.
4 changes: 2 additions & 2 deletions app/jobs/expire_requestable_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

class ExpireRequestableJob < ApplicationJob
def perform(requestable)
if requestable.requested? && requestable.expired_at.present? &&
Time.zone.now > requestable.expired_at
if requestable.requested? && requestable.expires_at.present? &&
Time.zone.now > requestable.expires_at
ExpireRequestable.call(requestable:, user: "Expirer")
end
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ def expires_after
draft? ? 6.months : nil
end

def requested_at
created_at
end

private

def build_documents
Expand Down
6 changes: 4 additions & 2 deletions app/models/concerns/expirable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
module Expirable
extend ActiveSupport::Concern

def expired_at
expires_after ? created_at + expires_after : nil
def expires_at
return nil if requested_at.nil? || expires_after.nil?

requested_at + expires_after
end

def after_expired(user:)
Expand Down
14 changes: 12 additions & 2 deletions app/models/concerns/requestable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,25 @@ module Requestable

validates :state, presence: true, inclusion: { in: states.values }

validates :requested_at, presence: true, if: :requested?
validates :received_at, presence: true, if: :received?
validates :expired_at, presence: true, if: :expired?
validates :reviewed_at, presence: true, unless: -> { passed.nil? }

scope :respondable, -> { not_received.merge(ApplicationForm.assessable) }

define_method :requested! do
update!(state: "requested", received_at: nil)
update!(state: "requested", requested_at: Time.zone.now)
end

define_method :received! do
update!(state: "received", received_at: Time.zone.now)
end

define_method :expired! do
update!(state: "expired", expired_at: Time.zone.now)
end

has_one :application_form, through: :assessment
end

Expand All @@ -39,7 +45,7 @@ def reviewed?
end

def overdue?
expired? || (received? && expired_at.present? && received_at > expired_at)
expired? || (received? && expires_at.present? && received_at > expires_at)
end

def failed
Expand All @@ -53,6 +59,10 @@ def status
passed ? "accepted" : "rejected"
end

def after_requested(user:)
# implement logic after this requestable has been requested
end

def after_received(user:)
# implement logic after this requestable has been received
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/further_information_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
# Table name: further_information_requests
#
# id :bigint not null, primary key
# expired_at :datetime
# failure_assessor_note :string default(""), not null
# passed :boolean
# received_at :datetime
# requested_at :datetime
# reviewed_at :datetime
# state :string not null
# working_days_assessment_started_to_creation :integer
Expand Down
2 changes: 2 additions & 0 deletions app/models/professional_standing_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
# Table name: professional_standing_requests
#
# id :bigint not null, primary key
# expired_at :datetime
# failure_assessor_note :string default(""), not null
# location_note :text default(""), not null
# passed :boolean
# ready_for_review :boolean default(FALSE), not null
# received_at :datetime
# requested_at :datetime
# reviewed_at :datetime
# state :string not null
# created_at :datetime not null
Expand Down
2 changes: 2 additions & 0 deletions app/models/qualification_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
# Table name: qualification_requests
#
# id :bigint not null, primary key
# expired_at :datetime
# failure_assessor_note :string default(""), not null
# location_note :text default(""), not null
# passed :boolean
# received_at :datetime
# requested_at :datetime
# reviewed_at :datetime
# state :string not null
# created_at :datetime not null
Expand Down
2 changes: 2 additions & 0 deletions app/models/reference_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# contact_response :boolean
# dates_comment :text default(""), not null
# dates_response :boolean
# expired_at :datetime
# failure_assessor_note :string default(""), not null
# hours_comment :text default(""), not null
# hours_response :boolean
Expand All @@ -25,6 +26,7 @@
# received_at :datetime
# reports_comment :text default(""), not null
# reports_response :boolean
# requested_at :datetime
# reviewed_at :datetime
# satisfied_comment :text default(""), not null
# satisfied_response :boolean
Expand Down
2 changes: 2 additions & 0 deletions app/services/create_further_information_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ def call
FurtherInformationRequestItemsFactory.call(
assessment_sections: assessment.sections,
),
requested_at: Time.zone.now,
)

ApplicationFormStatusUpdater.call(application_form:, user:)

create_timeline_event(request)
request.after_requested(user:)

request
end
Expand Down
5 changes: 3 additions & 2 deletions app/services/send_reminder_email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def call
attr_reader :remindable

def send_reminder?
return false unless remindable.expired_at
return false if remindable.try(:expired_at).present?
return false unless remindable.expires_at

remindable.should_send_reminder_email?(
days_until_expired,
Expand All @@ -33,7 +34,7 @@ def number_of_reminders_sent

def days_until_expired
today = Time.zone.today
(remindable.expired_at.to_date - today).to_i
(remindable.expires_at.to_date - today).to_i
end

def send_email
Expand Down
8 changes: 7 additions & 1 deletion app/services/submit_application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,19 @@ def call
def create_professional_standing_request(assessment)
return unless application_form.teaching_authority_provides_written_statement

requestable = ProfessionalStandingRequest.create!(assessment:)
requestable =
ProfessionalStandingRequest.create!(
assessment:,
requested_at: Time.zone.now,
)

TimelineEvent.create!(
event_type: "requestable_requested",
application_form:,
creator: user,
requestable:,
)

requestable.after_requested(user:)
end
end
8 changes: 5 additions & 3 deletions app/services/verify_assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,22 @@ def create_professional_standing_request
return if application_form.teaching_authority_provides_written_statement

ProfessionalStandingRequest
.create!(assessment:)
.create!(assessment:, requested_at: Time.zone.now)
.tap { |requestable| create_timeline_event(requestable) }
end

def create_qualification_requests
qualifications.map do |qualification|
QualificationRequest
.create!(assessment:, qualification:)
.create!(assessment:, qualification:, requested_at: Time.zone.now)
.tap { |requestable| create_timeline_event(requestable) }
end
end

def create_reference_requests
work_histories.map do |work_history|
ReferenceRequest
.create!(assessment:, work_history:)
.create!(assessment:, work_history:, requested_at: Time.zone.now)
.tap { |requestable| create_timeline_event(requestable) }
end
end
Expand All @@ -84,6 +84,8 @@ def create_timeline_event(requestable)
event_type: "requestable_requested",
requestable:,
)

requestable.after_requested(user:)
end

def send_reference_request_emails(reference_requests)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
reference_request: OpenStruct.new(
slug: "reference-request",
work_history: @application_form.work_histories.first,
expired_at: Time.zone.now + 6.weeks,
expires_at: Time.zone.now + 6.weeks,
assessment: @assessment,
application_form: @application_form
),
Expand Down
2 changes: 1 addition & 1 deletion app/views/referee_mailer/reference_reminder.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ We still need you to confirm some information about <%= application_form_full_na

We recently contacted you to ask you to help us confirm that the information <%= application_form_full_name(@application_form) %> has provided about their work history and experience is accurate.

Please follow the link below and answer the questions by <%= @reference_request.expired_at.to_date.to_fs(:long_ordinal_uk) %>. If we do not receive your response by this date, it could affect the outcome for the applicant.
Please follow the link below and answer the questions by <%= @reference_request.expires_at.to_date.to_fs(:long_ordinal_uk) %>. If we do not receive your response by this date, it could affect the outcome for the applicant.

<%= teacher_interface_reference_request_url(@reference_request.slug) %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/referee_mailer/reference_requested.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ As part of the QTS application process, our assessors need to understand each ap

# What we need you to do

Please follow the link below and answer the questions by <%= @reference_request.expired_at.to_date.to_fs(:long_ordinal_uk) %>.
Please follow the link below and answer the questions by <%= @reference_request.expires_at.to_date.to_fs(:long_ordinal_uk) %>.

<%= teacher_interface_reference_request_url(@reference_request.slug) %>

Expand Down
6 changes: 3 additions & 3 deletions app/views/teacher_mailer/application_not_submitted.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ Dear <%= application_form_full_name(@application_form) %>
<% when 0 %>
We’ve noticed that you have a draft application for qualified teacher status (QTS) that has not been submitted.

We need to let you know that if you do not complete and submit your application by <%= @application_form.expired_at.to_date.to_fs(:long_ordinal_uk) %> we’ll delete the application.
We need to let you know that if you do not complete and submit your application by <%= @application_form.expires_at.to_date.to_fs(:long_ordinal_uk) %> we’ll delete the application.
<% when 1 %>
We contacted you a week ago about your draft application for qualified teacher status (QTS).

If you do not complete and submit your application by <%= @application_form.expired_at.to_date.to_fs(:long_ordinal_uk) %> we’ll delete the application.
If you do not complete and submit your application by <%= @application_form.expires_at.to_date.to_fs(:long_ordinal_uk) %> we’ll delete the application.
<% end %>

# What happens if your application is deleted?
Expand All @@ -19,7 +19,7 @@ Applications are deleted permanently, so if you still wanted to apply for QTS af

# Your next steps

If you still want to apply for QTS you must do so before <%= @application_form.expired_at.to_date.to_fs(:long_ordinal_uk) %>. You can sign in to complete and submit your application using the link below:
If you still want to apply for QTS you must do so before <%= @application_form.expires_at.to_date.to_fs(:long_ordinal_uk) %>. You can sign in to complete and submit your application using the link below:

<%= new_teacher_session_url %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Dear <%= application_form_full_name(@application_form) %>

# What happens next

You must respond to this request by <%= @further_information_request.expired_at.to_date.to_fs(:long_ordinal_uk) %> otherwise your QTS application will be declined.
You must respond to this request by <%= @further_information_request.expires_at.to_date.to_fs(:long_ordinal_uk) %> otherwise your QTS application will be declined.

Once you respond with all of the information we’ve requested, the assessor will be able to continue reviewing your application.

Expand Down
Loading

0 comments on commit 24ac887

Please sign in to comment.