-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwithdraw_offer.rb
41 lines (33 loc) · 1.22 KB
/
withdraw_offer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class WithdrawOffer
include ActiveModel::Validations
include ImpersonationAuditHelper
attr_accessor :offer_withdrawal_reason
validates_presence_of :offer_withdrawal_reason
validates_length_of :offer_withdrawal_reason, maximum: 65535
def initialize(actor:, application_choice:, offer_withdrawal_reason: nil)
@auth = ProviderAuthorisation.new(actor:)
@application_choice = application_choice
@offer_withdrawal_reason = offer_withdrawal_reason
end
def save
return false unless valid?
@auth.assert_can_make_decisions!(application_choice: @application_choice, course_option_id: @application_choice.current_course_option.id)
audit(@auth.actor) do
ActiveRecord::Base.transaction do
ApplicationStateChange.new(@application_choice).withdraw_offer!
@application_choice.update!(
offer_withdrawal_reason: @offer_withdrawal_reason,
offer_withdrawn_at: Time.zone.now,
)
end
CandidateMailer.offer_withdrawn(@application_choice).deliver_later
true
end
rescue Workflow::NoTransitionAllowed
errors.add(
:base,
I18n.t('activerecord.errors.models.application_choice.attributes.status.invalid_transition'),
)
false
end
end