Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2322-send-referee-reminders-to-applicants #1778

Merged
merged 7 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ def update_reference_requests

def preview_referee
authorize %i[assessor_interface assessment_recommendation], :edit?
@reference_requests = assessment.reference_requests
end

def preview_teacher
Expand Down
4 changes: 3 additions & 1 deletion app/mailers/referee_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ class RefereeMailer < ApplicationMailer
helper :application_form

def reference_reminder
@number_of_reminders_sent = params[:number_of_reminders_sent]

view_mail(
GOVUK_NOTIFY_TEMPLATE_ID,
to: work_history.contact_email,
subject:
I18n.t(
"mailer.referee.reference_reminder.subject",
"mailer.referee.reference_reminder.subject.#{@number_of_reminders_sent}",
name: application_form_full_name(application_form),
),
)
Expand Down
16 changes: 16 additions & 0 deletions app/mailers/teacher_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,23 @@ def professional_standing_received
)
end

def references_reminder
@number_of_reminders_sent = params[:number_of_reminders_sent]
@reference_requests = params[:reference_requests]

view_mail(
GOVUK_NOTIFY_TEMPLATE_ID,
to: teacher.email,
subject:
I18n.t(
"mailer.teacher.references_reminder.subject.#{@number_of_reminders_sent}",
),
)
end

def references_requested
@reference_requests = params[:reference_requests]

view_mail(
GOVUK_NOTIFY_TEMPLATE_ID,
to: teacher.email,
Expand Down
59 changes: 50 additions & 9 deletions app/models/application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
# fk_rails_... (teacher_id => teachers.id)
#
class ApplicationForm < ApplicationRecord
include Expirable
include Remindable

belongs_to :teacher
Expand Down Expand Up @@ -219,7 +220,12 @@ class ApplicationForm < ApplicationRecord
.or(withdrawn.where("withdrawn_at < ?", 5.years.ago))
end

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

def to_param
reference
Expand Down Expand Up @@ -261,18 +267,46 @@ def created_under_new_regulations?
created_at >= Date.parse(ENV.fetch("NEW_REGS_DATE", "2023-02-01"))
end

def should_send_reminder_email?(days_until_expired, number_of_reminders_sent)
def reminder_email_names
%w[expiration references]
end

def should_send_reminder_email?(name, number_of_reminders_sent)
return false if teacher.application_form != self

(days_until_expired <= 14 && number_of_reminders_sent.zero?) ||
(days_until_expired <= 7 && number_of_reminders_sent == 1)
case name
when "expiration"
return false if days_until_expired.nil?

(days_until_expired <= 14 && number_of_reminders_sent.zero?) ||
(days_until_expired <= 7 && number_of_reminders_sent == 1)
when "references"
unreviewed_reference_requests.any? do |reference_request|
reference_request.should_send_reminder_email?(
"expiration",
number_of_reminders_sent,
)
end
end
end

def send_reminder_email(number_of_reminders_sent)
TeacherMailer
.with(teacher:, number_of_reminders_sent:)
.application_not_submitted
.deliver_later
def send_reminder_email(name, number_of_reminders_sent)
case name
when "expiration"
TeacherMailer
.with(teacher:, number_of_reminders_sent:)
.application_not_submitted
.deliver_later
when "references"
TeacherMailer
.with(
teacher:,
number_of_reminders_sent:,
reference_requests: unreviewed_reference_requests.to_a,
)
.references_reminder
.deliver_later
end
end

def expires_after
Expand All @@ -292,4 +326,11 @@ def build_documents
documents.build(document_type: :english_language_proficiency)
documents.build(document_type: :written_statement)
end

def unreviewed_reference_requests
ReferenceRequest
.joins(:work_history)
.where(work_histories: { application_form_id: id })
.where(received_at: nil, expired_at: nil)
end
end
5 changes: 5 additions & 0 deletions app/models/concerns/expirable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ def expires_at
requested_at + expires_after
end

def days_until_expired
return nil if expires_at.nil?
(expires_at.to_date - Time.zone.today).to_i
end

def expired!
update!(expired_at: Time.zone.now)
end
Expand Down
10 changes: 6 additions & 4 deletions app/models/concerns/remindable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
module Remindable
extend ActiveSupport::Concern

include Expirable

included { has_many :reminder_emails, as: :remindable }

def should_send_reminder_email?(days_until_expired, number_of_reminders_sent)
def reminder_email_names
%w[expiration]
end

def should_send_reminder_email?(type, number_of_reminders_sent)
# whether to send a reminder email at this point
end

def send_reminder_email(number_of_reminders_sent)
def send_reminder_email(type, number_of_reminders_sent)
# send a suitable reminder email for this object
end
end
4 changes: 2 additions & 2 deletions app/models/further_information_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ class FurtherInformationRequest < ApplicationRecord

FOUR_WEEK_COUNTRY_CODES = %w[AU CA GI NZ US].freeze

def should_send_reminder_email?(days_until_expired, number_of_reminders_sent)
def should_send_reminder_email?(_name, number_of_reminders_sent)
(days_until_expired <= 14 && number_of_reminders_sent.zero?) ||
(days_until_expired <= 7 && number_of_reminders_sent == 1) ||
(days_until_expired <= 2 && number_of_reminders_sent == 2)
end

def send_reminder_email(_number_of_reminders_sent)
def send_reminder_email(_name, _number_of_reminders_sent)
TeacherMailer
.with(teacher:, further_information_request: self)
.further_information_reminder
Expand Down
9 changes: 6 additions & 3 deletions app/models/reference_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,16 @@ def responses_given?
].none?(&:nil?)
end

def should_send_reminder_email?(days_until_expired, number_of_reminders_sent)
def should_send_reminder_email?(_name, number_of_reminders_sent)
(days_until_expired <= 28 && number_of_reminders_sent.zero?) ||
(days_until_expired <= 14 && number_of_reminders_sent == 1)
end

def send_reminder_email(_number_of_reminders_sent)
RefereeMailer.with(reference_request: self).reference_reminder.deliver_later
def send_reminder_email(_name, number_of_reminders_sent)
RefereeMailer
.with(reference_request: self, number_of_reminders_sent:)
.reference_reminder
.deliver_later
end

def expires_after
Expand Down
1 change: 1 addition & 0 deletions app/models/reminder_email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Table name: reminder_emails
#
# id :bigint not null, primary key
# name :string default("expiration"), not null
# remindable_type :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
Expand Down
34 changes: 13 additions & 21 deletions app/services/send_reminder_email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,31 @@ def initialize(remindable:)
end

def call
if send_reminder?
send_email
record_reminder
remindable.reminder_email_names.each do |name|
if send_reminder?(name)
send_email(name)
record_reminder(name)
end
end
end

private

attr_reader :remindable

def send_reminder?
return false unless remindable.expires_at

remindable.should_send_reminder_email?(
days_until_expired,
number_of_reminders_sent,
)
end

def number_of_reminders_sent
remindable.reminder_emails.count
def send_reminder?(name)
remindable.should_send_reminder_email?(name, number_of_reminders_sent(name))
end

def days_until_expired
today = Time.zone.today
(remindable.expires_at.to_date - today).to_i
def number_of_reminders_sent(name)
remindable.reminder_emails.where(name:).count
end

def send_email
remindable.send_reminder_email(number_of_reminders_sent)
def send_email(name)
remindable.send_reminder_email(name, number_of_reminders_sent(name))
end

def record_reminder
remindable.reminder_emails.create!
def record_reminder(name)
remindable.reminder_emails.create!(name:)
end
end
5 changes: 4 additions & 1 deletion app/services/update_work_history_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ def call

if email.present? && (reference_request = work_history.reference_request)
RefereeMailer.with(reference_request:).reference_requested.deliver_later
TeacherMailer.with(teacher:).references_requested.deliver_later
TeacherMailer
.with(teacher:, reference_requests: [reference_request])
.references_requested
.deliver_later
end
end

Expand Down
5 changes: 4 additions & 1 deletion app/services/verify_assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def send_reference_request_emails(reference_requests)
RefereeMailer.with(reference_request:).reference_requested.deliver_later
end

TeacherMailer.with(teacher:).references_requested.deliver_later
TeacherMailer
.with(teacher:, reference_requests:)
.references_requested
.deliver_later
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
mailer_class: TeacherMailer,
name: :references_requested,
teacher: @application_form.teacher,
reference_requests: [OpenStruct.new(
expires_at: Time.zone.now + 6.weeks,
)],
)) %>

<div class="govuk-button-group">
Expand Down
31 changes: 26 additions & 5 deletions app/views/referee_mailer/reference_reminder.text.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
Dear <%= @work_history.contact_name %>

We still need you to confirm some information about <%= application_form_full_name(@application_form) %> as part of their application for qualified teacher status (QTS) in England.
<% if @number_of_reminders_sent == 1 %>
You have just 2 weeks to complete the reference request for <%= application_form_full_name(@application_form) %>.
<% end %>

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.
<%= application_form_full_name(@application_form) %> has applied for qualified teacher status (QTS) in England.

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.
<% if @number_of_reminders_sent == 0 %>
We recently asked you to confirm the information they’ve provided about their work history and experience. We have not yet received a response from you. The applicant may not be awarded QTS if we cannot confirm the information they have provided.
<% elsif @number_of_reminders_sent == 1 %>
They have given us your name and email address to confirm the information they’ve provided about their work history and experience.

The applicant may not be awarded QTS if we cannot confirm the information they have provided.
<% end %>

# What you need to do

You need to answer a few questions about <%= application_form_full_name(@application_form) %> by <%= @reference_request.expires_at.to_date.to_fs(:long_ordinal_uk) %>. This should take no longer than 5 minutes.

Follow the link below to start.

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

It should take no longer than 5 minutes.
# About QTS

QTS is a legal requirement to teach in many English schools, and most schools prefer their teachers to have it.

<%= application_form_full_name(@application_form) %> has not applied for a job. Having QTS does not guarantee a job or give someone the right to work in England.

The QTS application allows us to assess a person’s teacher training and experience to understand if they have the skills and qualifications needed to gain QTS in England.

Kind regards,
The Teacher Qualifications Team (part of the Teaching Regulation Agency)
Teaching Regulation Authority (TRA)
(an executive agency sponsored by the Department for Education, England)
22 changes: 13 additions & 9 deletions app/views/referee_mailer/reference_requested.text.erb
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
Dear <%= @work_history.contact_name %>

We need you to confirm some information about <%= application_form_full_name(@application_form) %> as part of their application for qualified teacher status (QTS) in England.
<%= application_form_full_name(@application_form) %> has applied for qualified teacher status (QTS) in England.

As part of the QTS application process, our assessors need to understand each applicant’s work history and experience.
They have given us your name and email address to confirm the information they’ve provided about their work history and experience.

<%= application_form_full_name(@application_form) %> has given us your name and email address to help us confirm that the information they’ve provided about their work history and experience is accurate.
# What you need to do

# About QTS
You need to answer a few questions about <%= application_form_full_name(@application_form) %> by <%= @reference_request.expires_at.to_date.to_fs(:long_ordinal_uk) %>. This should take no longer than 5 minutes.

<%= application_form_full_name(@application_form) %> is NOT applying for a job – their QTS application just allows us to assess their qualifications and teaching experience to understand whether they can teach in England.
Follow the link below to start.

# What we need you to do
<%= teacher_interface_reference_request_url(@reference_request.slug) %>

Please follow the link below and answer the questions by <%= @reference_request.expires_at.to_date.to_fs(:long_ordinal_uk) %>.
Please complete the reference by the due date. The applicant may not be awarded QTS if we cannot confirm the information they have provided.

<%= teacher_interface_reference_request_url(@reference_request.slug) %>
# About QTS

QTS is a legal requirement to teach in many English schools, and most schools prefer their teachers to have it.

<%= application_form_full_name(@application_form) %> has not applied for a job. Having QTS does not guarantee a job or give someone the right to work in England.

It should take no longer than 5 minutes.
The QTS application allows us to assess a person’s teacher training and experience to understand if they have the skills and qualifications needed to gain QTS in England.

Kind regards,
Teaching Regulation Authority (TRA)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
If you have any questions, contact: <%= t("service.email.enquiries") %>
If you have any questions, contact: [<%= t("service.email.enquiries") %>](mailto:<%= t("service.email.enquiries") %>)
2 changes: 1 addition & 1 deletion app/views/teacher_mailer/application_declined.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ If you would like to request a decision review, you’ll need to provide:
- formal evidence and reasoning as to how you meet the required assessment criteria
- additional information not included in your original application that would support your decision review

Your request for review must be received within 28 days of receipt of the decision to decline QTS. Email your request for review, including the information required as above, to <%= t("service.email.enquiries") %>.
Your request for review must be received within 28 days of receipt of the decision to decline QTS. Email your request for review, including the information required as above, to [<%= t("service.email.enquiries") %>](mailto:<%= t("service.email.enquiries") %>).

If you are not satisfied with the outcome of the decision review, you can request a final formal appeal to a senior Teacher Qualification Manager.

Expand Down
2 changes: 1 addition & 1 deletion app/views/teacher_mailer/initial_checks_passed.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Dear <%= application_form_full_name(@application_form) %>

<%= render "shared/teacher_mailer/reference_number" %>

You should now request your <%= region_certificate_name(@application_form.region) %> from <%= region_teaching_authority_name(@application_form.region) %>. Contact them directly and instruct them to send the document to <%= t("service.email.verification") %>.
You should now request your <%= region_certificate_name(@application_form.region) %> from <%= region_teaching_authority_name(@application_form.region) %>. Contact them directly and instruct them to send the document to [<%= t("service.email.verification") %>](mailto:<%= t("service.email.verification") %>).

Once we receive the document, we’ll begin the full assessment of your application.

Expand Down
Loading
Loading