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

[409] end of cycle implement a single deadline for all candidates #9503

Merged
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 @@ -7,7 +7,7 @@ def initialize(application_form:)
end

def render?
@application_form.unsuccessful_and_apply_2_deadline_has_passed?
@application_form.unsuccessful_and_apply_deadline_has_passed?
end

def application_form_academic_cycle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def render?

def deadline
{
date: CycleTimetable.date(:apply_2_deadline).to_fs(:govuk_date),
time: CycleTimetable.date(:apply_2_deadline).to_fs(:govuk_time),
date: CycleTimetable.date(:apply_deadline).to_fs(:govuk_date),
time: CycleTimetable.date(:apply_deadline).to_fs(:govuk_time),
}
end

Expand Down
21 changes: 4 additions & 17 deletions app/components/candidate_interface/reopen_banner_component.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
class CandidateInterface::ReopenBannerComponent < ViewComponent::Base
attr_accessor :phase, :flash_empty

def initialize(phase:, flash_empty:)
def initialize(flash_empty:)
@phase = phase
@flash_empty = flash_empty
end

def render?
flash_empty &&
(show_apply_1_reopen_banner? || show_apply_2_reopen_banner?)
flash_empty && show_apply_reopen_banner?
end

private

def show_apply_1_reopen_banner?
apply_1? && CycleTimetable.between_cycles_apply_1?
end

def show_apply_2_reopen_banner?
apply_2? && CycleTimetable.between_cycles_apply_2?
end

def apply_1?
phase == 'apply_1'
end

def apply_2?
phase == 'apply_2'
def show_apply_reopen_banner?
CycleTimetable.between_cycles?
end

def reopen_date
Expand Down
10 changes: 3 additions & 7 deletions app/components/shared/end_of_cycle_banners_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ def end_of_cycle_banners
[
{
name: 'Summer recruitment banner',
date: "#{banner_date(:show_summer_recruitment_banner)} to #{banner_date(:apply_1_deadline)}",
date: "#{banner_date(:show_summer_recruitment_banner)} to #{banner_date(:apply_deadline)}",
},
{
name: 'Apply 1 deadline banner',
date: "#{banner_date(:show_deadline_banner)} to #{banner_date(:apply_1_deadline)}",
},
{
name: 'Apply 2 deadline banner',
date: "#{banner_date(:show_summer_recruitment_banner)} to #{banner_date(:apply_2_deadline)}",
name: 'Apply deadline banner',
date: "#{banner_date(:show_deadline_banner)} to #{banner_date(:apply_deadline)}",
},
].map do |cycle_data|
EndOfCycleBanner.new(cycle_data)
Expand Down
20 changes: 5 additions & 15 deletions app/components/shared/end_of_cycle_emails_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@ class EndOfCycleEmailsComponent < ViewComponent::Base
def end_of_cycle_emails
[
{
link: preview_email_link('Apply 1 deadline reminder', path: 'candidate_mailer/eoc_deadline_reminder'),

date: "#{email_date(:apply_1_deadline_first_reminder)} and #{email_date(:apply_1_deadline_second_reminder)}",
candidates_size: apply_1_candidates,
},
{
link: preview_email_link('Apply 2 deadline reminder', path: 'candidate_mailer/eoc_deadline_reminder'),
date: "#{email_date(:apply_2_deadline_first_reminder)} and #{email_date(:apply_2_deadline_second_reminder)}",
candidates_size: apply_2_candidates,
link: preview_email_link('Apply deadline reminder', path: 'candidate_mailer/eoc_deadline_reminder'),
date: "#{email_date(:apply_deadline_first_reminder)} and #{email_date(:apply_deadline_second_reminder)}",
candidates_size: apply_candidates,
},
{
link: preview_email_link('Find has opened', path: 'candidate_mailer/find_has_opened'),
Expand All @@ -36,12 +30,8 @@ def end_of_cycle_emails
end
end

def apply_1_candidates
GetApplicationsToSendDeadlineRemindersTo.deadline_reminder_candidates_apply_1.count
end

def apply_2_candidates
GetApplicationsToSendDeadlineRemindersTo.deadline_reminder_candidates_apply_2.count
def apply_candidates
GetApplicationsToSendDeadlineRemindersTo.deadline_reminder_query.count
end

def candidates_to_notify_about_find_and_apply
Expand Down
2 changes: 1 addition & 1 deletion app/components/shared/end_of_cycle_timeline_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class EndOfCycleTimelineComponent < ViewComponent::Base
}.freeze

def initialize
@cycle_timetable = CycleTimetable::CYCLE_DATES[CycleTimetable.current_year].merge(
@cycle_timetable = CYCLE_DATES[CycleTimetable.current_year].merge(
{
find_reopens: CycleTimetable.find_reopens,
apply_reopens: CycleTimetable.apply_reopens,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def complete
end

def start_carry_over
render CycleTimetable.between_cycles_apply_2? ? :start_carry_over_between_cycles : :start_carry_over
render CycleTimetable.between_cycles? ? :start_carry_over_between_cycles : :start_carry_over
end

def carry_over
Expand Down
16 changes: 4 additions & 12 deletions app/helpers/cycle_timetable_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,12 @@ def mid_cycle(year = CycleTimetable.current_year)
CycleTimetable.apply_opens(year) + 1.day
end

def after_apply_1_deadline(year = CycleTimetable.current_year)
CycleTimetable.apply_1_deadline(year) + 1.day
def after_apply_deadline(year = CycleTimetable.current_year)
CycleTimetable.apply_deadline(year) + 1.day
end

def before_apply_1_deadline(year = CycleTimetable.current_year)
CycleTimetable.apply_1_deadline(year) - 1.day
end

def after_apply_2_deadline(year = CycleTimetable.current_year)
CycleTimetable.apply_2_deadline(year) + 1.day
end

def before_apply_2_deadline(year = CycleTimetable.current_year)
CycleTimetable.apply_2_deadline(year) - 1.day
def before_apply_deadline(year = CycleTimetable.current_year)
CycleTimetable.apply_deadline(year) - 1.day
end

def after_apply_reopens(year = CycleTimetable.next_year)
Expand Down
24 changes: 2 additions & 22 deletions app/lib/test_applications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def create_application(
recruitment_cycle_year:,
states:,
courses_to_apply_to:,
apply_again: false,
carry_over: false,
course_full: false,
candidate: nil,
Expand All @@ -43,7 +42,6 @@ def create_application(
recruitment_cycle_year:,
states:,
courses:,
apply_again:,
carry_over:,
candidate:,
incomplete_references:,
Expand Down Expand Up @@ -84,31 +82,14 @@ def create_application_to_courses(
recruitment_cycle_year:,
states:,
courses:,
apply_again: false,
carry_over: false,
candidate: nil,
application_in_past: false,
incomplete_references: false
)
raise CourseAndStateNumbersDoNotMatchError unless courses.count == states.count

if apply_again
raise OnlyOneCourseWhenApplyingAgainError unless states.one?

create_application_to_courses(
application_in_past: true,
recruitment_cycle_year:,
courses:,
states: [:rejected],
candidate:,
)

initialize_time(recruitment_cycle_year, application_in_past:)
candidate = candidate.presence || Candidate.last
first_name = candidate.current_application.first_name
last_name = candidate.current_application.last_name
previous_application_form = candidate.current_application
elsif carry_over
if carry_over
courses_from_last_year = Course.with_course_options.distinct.in_cycle(recruitment_cycle_year - 1).sample(rand(1..3))
create_application_to_courses(
recruitment_cycle_year: recruitment_cycle_year - 1,
Expand Down Expand Up @@ -161,7 +142,6 @@ def create_application_to_courses(
created_at: time,
updated_at: time,
recruitment_cycle_year:,
phase: apply_again ? 'apply_2' : 'apply_1',
previous_application_form:,
references_count: 0,
)
Expand Down Expand Up @@ -563,7 +543,7 @@ def initialize_time(recruitment_cycle_year, application_in_past: false)
end
else
earliest_date = CycleTimetable.apply_opens(recruitment_cycle_year)
latest_date = CycleTimetable.apply_1_deadline(recruitment_cycle_year)
latest_date = CycleTimetable.apply_deadline(recruitment_cycle_year)
end

@time = rand(earliest_date..latest_date)
Expand Down
8 changes: 4 additions & 4 deletions app/models/application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,15 @@ def candidate_has_previously_applied?
end

def carry_over?
previous_recruitment_cycle? && (not_submitted_and_deadline_has_passed? || unsuccessful_and_apply_2_deadline_has_passed?)
previous_recruitment_cycle? && (not_submitted_and_deadline_has_passed? || unsuccessful_and_apply_deadline_has_passed?)
end

def not_submitted_and_deadline_has_passed?
!submitted? && ((apply_1? && CycleTimetable.apply_1_deadline_has_passed?(self)) || (apply_2? && CycleTimetable.apply_2_deadline_has_passed?(self)))
!submitted? && CycleTimetable.apply_deadline_has_passed?(self)
end

def unsuccessful_and_apply_2_deadline_has_passed?
ended_without_success? && CycleTimetable.apply_2_deadline_has_passed?(self)
def unsuccessful_and_apply_deadline_has_passed?
ended_without_success? && CycleTimetable.apply_deadline_has_passed?(self)
end

##########################################
Expand Down
2 changes: 1 addition & 1 deletion app/models/candidate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def self.for_email(email)

def current_application
application_form = application_forms.order(:created_at, :id).last
application_form || if Time.zone.now > CycleTimetable.apply_1_deadline
application_form || if Time.zone.now > CycleTimetable.apply_deadline
application_forms.create!(recruitment_cycle_year: CycleTimetable.next_year)
else
application_forms.create!
Expand Down
4 changes: 2 additions & 2 deletions app/models/performance_statistics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ def application_choices
end

def date_range_query_for_recruitment_cycle_year(cycle_year)
start_date = CycleTimetable.apply_2_deadline(cycle_year - 1).end_of_day
start_date = CycleTimetable.apply_deadline(cycle_year - 1).end_of_day

query = "created_at >= '#{start_date}'"

end_date = CycleTimetable.apply_2_deadline(cycle_year)
end_date = CycleTimetable.apply_deadline(cycle_year)

if end_date
query + " AND created_at <= '#{end_date}'"
Expand Down
4 changes: 2 additions & 2 deletions app/models/recruitment_cycle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def self.years_visible_to_providers

def self.years_visible_in_support
from_year = HostingEnvironment.production? ? current_year : next_year
from_year.downto(CycleTimetable::CYCLE_DATES.keys.min)
from_year.downto(CYCLE_DATES.keys.min)
end

def self.years_available_to_register
current_year.downto(CycleTimetable::CYCLE_DATES.keys.min)
current_year.downto(CYCLE_DATES.keys.min)
end

def self.cycle_name(year = current_year)
Expand Down
18 changes: 3 additions & 15 deletions app/queries/get_applications_to_send_deadline_reminders_to.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
class GetApplicationsToSendDeadlineRemindersTo
def self.call
if CycleTimetable.need_to_send_deadline_reminder? == :apply_1
deadline_reminder_candidates_apply_1
elsif CycleTimetable.need_to_send_deadline_reminder? == :apply_2
deadline_reminder_candidates_apply_2
end
deadline_reminder_query if CycleTimetable.need_to_send_deadline_reminder?
end

def self.deadline_reminder_candidates_apply_1
deadline_reminder_query(phase: 'apply_1')
end

def self.deadline_reminder_candidates_apply_2
deadline_reminder_query(phase: 'apply_2')
end

def self.deadline_reminder_query(phase:)
def self.deadline_reminder_query
ApplicationForm
.joins(:candidate)
.where(submitted_at: nil, phase:, recruitment_cycle_year: RecruitmentCycle.current_year)
.where(submitted_at: nil, recruitment_cycle_year: RecruitmentCycle.current_year)
.where.not(candidate: { unsubscribed_from_emails: true })
end
end
2 changes: 1 addition & 1 deletion app/services/candidate_api/serializers/v1_1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def query
Candidate
.left_outer_joins(:application_forms)
.where(application_forms: { recruitment_cycle_year: RecruitmentCycle.current_year })
.or(Candidate.where('candidates.created_at > ? ', CycleTimetable.apply_1_deadline(RecruitmentCycle.previous_year)))
.or(Candidate.where('candidates.created_at > ? ', CycleTimetable.apply_deadline(RecruitmentCycle.previous_year)))
.distinct
.includes(application_forms: :application_choices)
.where('candidate_api_updated_at > ?', updated_since)
Expand Down
2 changes: 1 addition & 1 deletion app/services/candidate_api/serializers/v1_2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def query
.left_outer_joins(application_forms: { application_choices: %i[provider course interviews], application_references: [], application_qualifications: [] })
.includes(application_forms: { application_choices: %i[provider course course_option interviews], application_qualifications: [], application_references: [] })
.where('candidates.updated_at > :updated_since OR application_forms.updated_at > :updated_since OR application_choices.updated_at > :updated_since OR "references".updated_at > :updated_since OR application_qualifications.updated_at > :updated_since', updated_since:)
.where('application_forms.recruitment_cycle_year = ? OR candidates.created_at > ?', RecruitmentCycle.current_year, CycleTimetable.apply_1_deadline(RecruitmentCycle.previous_year))
.where('application_forms.recruitment_cycle_year = ? OR candidates.created_at > ?', RecruitmentCycle.current_year, CycleTimetable.apply_deadline(RecruitmentCycle.previous_year))
.order(id: :asc)
.distinct
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/candidate_api/serializers/v1_3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def query
.left_outer_joins(application_forms: { application_choices: %i[provider course interviews], application_references: [], application_qualifications: [] })
.includes(application_forms: { application_choices: %i[provider course course_option interviews], application_qualifications: [], application_references: [] })
.where('candidates.updated_at > :updated_since OR application_forms.updated_at > :updated_since OR application_choices.updated_at > :updated_since OR "references".updated_at > :updated_since OR application_qualifications.updated_at > :updated_since', updated_since:)
.where('application_forms.recruitment_cycle_year = ? OR candidates.created_at > ?', RecruitmentCycle.current_year, CycleTimetable.apply_1_deadline(RecruitmentCycle.previous_year))
.where('application_forms.recruitment_cycle_year = ? OR candidates.created_at > ?', RecruitmentCycle.current_year, CycleTimetable.apply_deadline(RecruitmentCycle.previous_year))
.order(id: :asc)
.distinct
end
Expand Down
3 changes: 1 addition & 2 deletions app/services/carry_over_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ def call

DuplicateApplication.new(
@application_form,
target_phase: 'apply_1',
recruitment_cycle_year:,
).duplicate
end
Expand All @@ -26,7 +25,7 @@ def application_from_current_cycle?
end

def recruitment_cycle_year
if Time.zone.now > CycleTimetable.apply_1_deadline
if Time.zone.now > CycleTimetable.apply_deadline
RecruitmentCycle.next_year
else
RecruitmentCycle.current_year
Expand Down
Loading
Loading