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

Reset requested date when changing reference request email addresses #2243

Merged
merged 3 commits into from
Jun 6, 2024
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 @@ -111,13 +111,7 @@ def update_verify_failed

def resend_email
if reference_request.requested? && !reference_request.received?
DeliverEmail.call(
application_form:,
mailer: RefereeMailer,
action: :reference_requested,
reference_request:,
)

reference_request.send_requested_email
flash[:info] = "The reference requested email has been resent."
end

Expand Down
13 changes: 13 additions & 0 deletions app/models/reference_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,23 @@ def send_reminder_email(_name, number_of_reminders_sent)
)
end

def send_requested_email
DeliverEmail.call(
application_form:,
mailer: RefereeMailer,
action: :reference_requested,
reference_request: self,
)
end

def expires_after
6.weeks
end

def after_requested(*)
send_requested_email
end

def after_verified(*)
UpdateAssessmentInductionRequired.call(assessment:)
end
Expand Down
9 changes: 6 additions & 3 deletions app/services/request_requestable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
class RequestRequestable
include ServicePattern

def initialize(requestable:, user:)
def initialize(requestable:, user:, allow_already_requested: false)
@requestable = requestable
@user = user
@allow_already_requested = allow_already_requested
end

def call
raise AlreadyRequested if requestable.requested?
raise AlreadyRequested if !allow_already_requested && requestable.requested?

ActiveRecord::Base.transaction do
requestable.requested!

requestable.update!(expired_at: nil) if requestable.expired?

CreateTimelineEvent.call(
"requestable_requested",
application_form:,
Expand All @@ -30,7 +33,7 @@ class AlreadyRequested < StandardError

private

attr_reader :requestable, :user
attr_reader :requestable, :user, :allow_already_requested

delegate :application_form, to: :requestable
end
39 changes: 22 additions & 17 deletions app/services/update_work_history_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,32 @@ def initialize(work_history:, user:, name: nil, job: nil, email: nil)
end

def call
ActiveRecord::Base.transaction do
change_value("contact_name", name) if name.present?
change_value("contact_name", name) if name.present?

change_value("contact_job", job) if job.present?
change_value("contact_job", job) if job.present?

if email.present?
change_value("contact_email", email)
if email.present?
email_address = EmailAddress.new(email)

email_address = EmailAddress.new(email)
work_history.update!(
change_value(
"contact_email",
email,
additional_updates: {
canonical_contact_email: email_address.canonical,
contact_email_domain: email_address.host_name,
)
end
},
)
end

if email.present? && (reference_request = work_history.reference_request)
DeliverEmail.call(
application_form:,
mailer: RefereeMailer,
action: :reference_requested,
reference_request:,
RequestRequestable.call(
requestable: reference_request,
user:,
allow_already_requested: true,
)

ApplicationFormStatusUpdater.call(application_form:, user:)

DeliverEmail.call(
application_form:,
mailer: TeacherMailer,
Expand All @@ -51,10 +53,13 @@ def call

delegate :application_form, to: :work_history

def change_value(column_name, new_value)
def change_value(column_name, new_value, additional_updates: {})
old_value = work_history.send(column_name)
work_history.update!(column_name => new_value)
create_timeline_event(column_name, old_value, new_value)

ActiveRecord::Base.transaction do
work_history.update!(column_name => new_value, **additional_updates)
create_timeline_event(column_name, old_value, new_value)
end
end

def create_timeline_event(column_name, old_value, new_value)
Expand Down
13 changes: 2 additions & 11 deletions app/services/verify_assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def call
end

if reference_requests.present?
send_reference_request_emails(reference_requests)
send_references_requested_email(reference_requests)
end

reference_requests
Expand Down Expand Up @@ -80,16 +80,7 @@ def create_reference_requests
end
end

def send_reference_request_emails(reference_requests)
reference_requests.each do |reference_request|
DeliverEmail.call(
application_form:,
mailer: RefereeMailer,
action: :reference_requested,
reference_request:,
)
end

def send_references_requested_email(reference_requests)
DeliverEmail.call(
application_form:,
mailer: TeacherMailer,
Expand Down
2 changes: 2 additions & 0 deletions spec/support/shared_examples/requestable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@
describe "#after_requested" do
let(:after_requested) { subject.after_requested(user: "User") }

before { subject.requested! }

it "doesn't raise an error" do
expect { after_requested }.to_not raise_error
end
Expand Down
Loading