diff --git a/app/controllers/assessor_interface/assessment_sections_controller.rb b/app/controllers/assessor_interface/assessment_sections_controller.rb index 2559fe7048..fb0ae89c3f 100644 --- a/app/controllers/assessor_interface/assessment_sections_controller.rb +++ b/app/controllers/assessor_interface/assessment_sections_controller.rb @@ -96,10 +96,7 @@ def notify_teacher return end - TeacherMailer - .with(teacher: application_form.teacher) - .initial_checks_passed - .deliver_later + TeacherMailer.with(application_form:).initial_checks_passed.deliver_later end def unassign_assessor diff --git a/app/mailers/teacher_mailer.rb b/app/mailers/teacher_mailer.rb index 08adcb1309..9186978628 100644 --- a/app/mailers/teacher_mailer.rb +++ b/app/mailers/teacher_mailer.rb @@ -4,9 +4,6 @@ class TeacherMailer < ApplicationMailer include RegionHelper before_action :set_application_form - before_action :set_further_information_request, - only: :further_information_reminder - before_action :set_further_information_requested, only: :application_declined helper :application_form, :region @@ -76,6 +73,8 @@ def further_information_requested end def further_information_reminder + @further_information_request = params[:further_information_request] + view_mail( GOVUK_NOTIFY_TEMPLATE_ID, to: teacher.email, @@ -129,23 +128,13 @@ def references_requested private - def teacher - params[:teacher] + def application_form + params[:application_form] end - delegate :application_form, to: :teacher - delegate :assessment, :region, to: :application_form + delegate :assessment, :region, :teacher, to: :application_form def set_application_form @application_form = application_form end - - def set_further_information_request - @further_information_request = params[:further_information_request] - end - - def set_further_information_requested - @further_information_requested = - assessment.further_information_requests.any? - end end diff --git a/app/models/application_form.rb b/app/models/application_form.rb index 68a0ca956d..e89b7941c2 100644 --- a/app/models/application_form.rb +++ b/app/models/application_form.rb @@ -267,13 +267,13 @@ def send_reminder_email(name, number_of_reminders_sent) case name when "expiration" TeacherMailer - .with(teacher:, number_of_reminders_sent:) + .with(application_form: self, number_of_reminders_sent:) .application_not_submitted .deliver_later when "references" TeacherMailer .with( - teacher:, + application_form: self, number_of_reminders_sent:, reference_requests: reference_requests_not_yet_received_or_rejected.to_a, diff --git a/app/models/further_information_request.rb b/app/models/further_information_request.rb index 146980a5e9..3dda340c02 100644 --- a/app/models/further_information_request.rb +++ b/app/models/further_information_request.rb @@ -48,7 +48,7 @@ def should_send_reminder_email?(_name, number_of_reminders_sent) def send_reminder_email(_name, _number_of_reminders_sent) TeacherMailer - .with(teacher:, further_information_request: self) + .with(application_form:, further_information_request: self) .further_information_reminder .deliver_later end @@ -63,7 +63,10 @@ def expires_after end def after_received(*) - TeacherMailer.with(teacher:).further_information_received.deliver_later + TeacherMailer + .with(application_form:) + .further_information_received + .deliver_later end def after_expired(user:) diff --git a/app/models/professional_standing_request.rb b/app/models/professional_standing_request.rb index 641263ee04..3886a1e9d1 100644 --- a/app/models/professional_standing_request.rb +++ b/app/models/professional_standing_request.rb @@ -40,7 +40,10 @@ def expires_after def after_received(*) if should_send_received_email? - TeacherMailer.with(teacher:).professional_standing_received.deliver_later + TeacherMailer + .with(application_form:) + .professional_standing_received + .deliver_later end end diff --git a/app/services/award_qts.rb b/app/services/award_qts.rb index 95d784a765..84228fe071 100644 --- a/app/services/award_qts.rb +++ b/app/services/award_qts.rb @@ -24,12 +24,15 @@ def call raise MissingTRN if trn.blank? ActiveRecord::Base.transaction do - teacher.update!(trn:, access_your_teaching_qualifications_url:) + application_form.teacher.update!( + trn:, + access_your_teaching_qualifications_url:, + ) application_form.update!(awarded_at: Time.zone.now) ApplicationFormStatusUpdater.call(application_form:, user:) end - TeacherMailer.with(teacher:).application_awarded.deliver_later + TeacherMailer.with(application_form:).application_awarded.deliver_later end class InvalidState < StandardError @@ -44,6 +47,4 @@ class MissingTRN < StandardError :user, :trn, :access_your_teaching_qualifications_url - - delegate :teacher, to: :application_form end diff --git a/app/services/create_further_information_request.rb b/app/services/create_further_information_request.rb index 5c66f7ae2f..c0b9f6adca 100644 --- a/app/services/create_further_information_request.rb +++ b/app/services/create_further_information_request.rb @@ -29,7 +29,10 @@ def call requestable end - TeacherMailer.with(teacher:).further_information_requested.deliver_later + TeacherMailer + .with(application_form:) + .further_information_requested + .deliver_later further_information_request end @@ -38,11 +41,5 @@ def call attr_reader :assessment, :user - def application_form - @application_form ||= assessment.application_form - end - - def teacher - @teacher ||= application_form.teacher - end + delegate :application_form, to: :assessment end diff --git a/app/services/decline_qts.rb b/app/services/decline_qts.rb index c204029427..42be6517dd 100644 --- a/app/services/decline_qts.rb +++ b/app/services/decline_qts.rb @@ -16,11 +16,10 @@ def call ApplicationFormStatusUpdater.call(application_form:, user:) end - TeacherMailer.with(teacher:).application_declined.deliver_later + TeacherMailer.with(application_form:).application_declined.deliver_later end private attr_reader :application_form, :user - delegate :teacher, to: :application_form end diff --git a/app/services/submit_application_form.rb b/app/services/submit_application_form.rb index 077d966bb1..bfa0ff90a5 100644 --- a/app/services/submit_application_form.rb +++ b/app/services/submit_application_form.rb @@ -32,17 +32,11 @@ def call ApplicationFormStatusUpdater.call(application_form:, user:) end - TeacherMailer - .with(teacher: application_form.teacher) - .application_received - .deliver_later + TeacherMailer.with(application_form:).application_received.deliver_later if !application_form.requires_preliminary_check && application_form.teaching_authority_provides_written_statement - TeacherMailer - .with(teacher: application_form.teacher) - .initial_checks_passed - .deliver_later + TeacherMailer.with(application_form:).initial_checks_passed.deliver_later end if region.teaching_authority_requires_submission_email diff --git a/app/services/update_work_history_contact.rb b/app/services/update_work_history_contact.rb index f61a9c8c17..9a4a721f58 100644 --- a/app/services/update_work_history_contact.rb +++ b/app/services/update_work_history_contact.rb @@ -28,7 +28,7 @@ def call if email.present? && (reference_request = work_history.reference_request) RefereeMailer.with(reference_request:).reference_requested.deliver_later TeacherMailer - .with(teacher:, reference_requests: [reference_request]) + .with(application_form:, reference_requests: [reference_request]) .references_requested .deliver_later end @@ -39,7 +39,6 @@ def call attr_reader :work_history, :user, :name, :job, :email delegate :application_form, to: :work_history - delegate :teacher, to: :application_form def change_value(column_name, new_value) old_value = work_history.send(column_name) diff --git a/app/services/verify_assessment.rb b/app/services/verify_assessment.rb index a704961c04..c743540578 100644 --- a/app/services/verify_assessment.rb +++ b/app/services/verify_assessment.rb @@ -52,9 +52,7 @@ class AlreadyVerified < StandardError :work_histories delegate :application_form, to: :assessment - delegate :teacher, - :teaching_authority_provides_written_statement, - to: :application_form + delegate :teaching_authority_provides_written_statement, to: :application_form def create_professional_standing_request if professional_standing && !teaching_authority_provides_written_statement @@ -84,7 +82,7 @@ def send_reference_request_emails(reference_requests) end TeacherMailer - .with(teacher:, reference_requests:) + .with(application_form:, reference_requests:) .references_requested .deliver_later end diff --git a/app/views/assessor_interface/assessment_recommendation_award/preview.html.erb b/app/views/assessor_interface/assessment_recommendation_award/preview.html.erb index bea969f699..c54674f18b 100644 --- a/app/views/assessor_interface/assessment_recommendation_award/preview.html.erb +++ b/app/views/assessor_interface/assessment_recommendation_award/preview.html.erb @@ -8,7 +8,7 @@ <%= render(PreviewMailer::Component.new( mailer_class: TeacherMailer, name: :application_awarded, - teacher: @application_form.teacher, + application_form: @application_form, )) %>