Merge pull request #63 from internetee/story/111503520-update-pending-apply

Story/111503520 update pending apply
This commit is contained in:
Timo Võhmar 2016-01-13 11:12:38 +02:00
commit e7aef75b25
3 changed files with 29 additions and 15 deletions

View file

@ -3,20 +3,16 @@ class DomainUpdateConfirmJob < Que::Job
# it's recommended to keep transaction against job table as short as possible. # it's recommended to keep transaction against job table as short as possible.
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
domain = Epp::Domain.find(domain_id) domain = Epp::Domain.find(domain_id)
domain.is_admin = true
case action case action
when RegistrantVerification::CONFIRMED when RegistrantVerification::CONFIRMED
domain.poll_message!(:poll_pending_update_confirmed_by_registrant) domain.poll_message!(:poll_pending_update_confirmed_by_registrant)
domain.apply_pending_update! do |e| domain.apply_pending_update!
e.instance_variable_set("@changed_attributes", e.changed_attributes.merge("statuses"=>[]))
end
domain.clean_pendings! domain.clean_pendings!
WhoisRecord.find_by(domain_id: domain.id).save
when RegistrantVerification::REJECTED when RegistrantVerification::REJECTED
domain.send_mail :pending_update_rejected_notification_for_new_registrant domain.send_mail :pending_update_rejected_notification_for_new_registrant
domain.poll_message!(:poll_pending_update_rejected_by_registrant) domain.poll_message!(:poll_pending_update_rejected_by_registrant)
domain.clean_pendings! domain.clean_pendings_lowlevel
domain.instance_variable_set("@changed_attributes", domain.changed_attributes.merge("statuses"=>[]))
domain.save
end end
destroy # it's best to destroy the job in the same transaction destroy # it's best to destroy the job in the same transaction
end end

View file

@ -244,7 +244,7 @@ class Domain < ActiveRecord::Base
if domain.pending_delete? || domain.pending_delete_confirmation? if domain.pending_delete? || domain.pending_delete_confirmation?
DomainMailer.pending_delete_expired_notification(domain.id, true).deliver DomainMailer.pending_delete_expired_notification(domain.id, true).deliver
end end
domain.clean_pendings! domain.clean_pendings_lowlevel
unless Rails.env.test? unless Rails.env.test?
STDOUT << "#{Time.zone.now.utc} Domain.clean_expired_pendings: ##{domain.id} (#{domain.name})\n" STDOUT << "#{Time.zone.now.utc} Domain.clean_expired_pendings: ##{domain.id} (#{domain.name})\n"
end end
@ -439,6 +439,25 @@ class Domain < ActiveRecord::Base
save save
end end
# state change shouln't be
def clean_pendings_lowlevel
statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION)
statuses.delete(DomainStatus::PENDING_UPDATE)
statuses.delete(DomainStatus::PENDING_DELETE)
status_notes[DomainStatus::PENDING_UPDATE] = ''
status_notes[DomainStatus::PENDING_DELETE] = ''
update_columns(
registrant_verification_token: nil,
registrant_verification_asked_at: nil,
pending_json: {},
status_notes: status_notes,
statuses: statuses.presence || [DomainStatus::OK]
)
end
def pending_update! def pending_update!
return true if pending_update? return true if pending_update?
self.epp_pending_update = true # for epp self.epp_pending_update = true # for epp

View file

@ -507,18 +507,17 @@ class Epp::Domain < Domain
frame = Nokogiri::XML(pending_json['frame']) frame = Nokogiri::XML(pending_json['frame'])
self.deliver_emails = true # turn on email delivery self.deliver_emails = true # turn on email delivery
send_mail :registrant_updated_notification_for_old_registrant self.statuses.delete(DomainStatus::PENDING_UPDATE)
statuses.delete(DomainStatus::PENDING_UPDATE)
yield(self) if block_given? # need to skip statuses check here
self.save
::PaperTrail.whodunnit = user.id_role_username # updator str should be the request originator not the approval user ::PaperTrail.whodunnit = user.id_role_username # updator str should be the request originator not the approval user
send_mail :registrant_updated_notification_for_old_registrant
return unless update(frame, user, false) return unless update(frame, user, false)
clean_pendings! clean_pendings!
send_mail :registrant_updated_notification_for_new_registrant send_mail :registrant_updated_notification_for_new_registrant
update_whois_record WhoisRecord.find_by(domain_id: id).save # need to reload model
save! # for notification if everything fails
true true
end end