diff --git a/app/controllers/registrant/domain_update_confirms_controller.rb b/app/controllers/registrant/domain_update_confirms_controller.rb
index 9830b5331..debe7294b 100644
--- a/app/controllers/registrant/domain_update_confirms_controller.rb
+++ b/app/controllers/registrant/domain_update_confirms_controller.rb
@@ -20,7 +20,6 @@ class Registrant::DomainUpdateConfirmsController < RegistrantController
@registrant_verification = RegistrantVerification.new(domain_id: @domain.id,
domain_name: @domain.name,
verification_token: params[:token])
-
if params[:rejected]
if @registrant_verification.domain_registrant_change_reject!
flash[:notice] = t(:registrant_domain_verification_rejected)
diff --git a/app/jobs/domain_confirm_job.rb b/app/jobs/domain_confirm_job.rb
new file mode 100644
index 000000000..e1f1c0e55
--- /dev/null
+++ b/app/jobs/domain_confirm_job.rb
@@ -0,0 +1,16 @@
+class DomainConfirmJob < Que::Job
+ def run(domain_id, action)
+ # it's recommended to keep transaction against job table as short as possible.
+ ActiveRecord::Base.transaction do
+ domain = Epp::Domain.find(domain_id)
+ case action
+ when RegistrantVerification::CONFIRMED
+ domain.apply_pending_update!
+ domain.clean_pendings!
+ when RegistrantVerification::REJECTED
+ domain.clean_pendings!
+ end
+ destroy # it's best to destroy the job in the same transaction
+ end
+ end
+end
diff --git a/app/models/domain.rb b/app/models/domain.rb
index 61ad23d43..03689c81a 100644
--- a/app/models/domain.rb
+++ b/app/models/domain.rb
@@ -54,6 +54,11 @@ class Domain < ActiveRecord::Base
delegate :name, to: :registrar, prefix: true
delegate :street, to: :registrar, prefix: true
+ after_initialize :init_default_values
+ def init_default_values
+ self.pending_json = {} if pending_json.blank?
+ end
+
before_create :generate_auth_info
before_create :set_validity_dates
before_update :manage_statuses
@@ -269,6 +274,19 @@ class Domain < ActiveRecord::Base
true
end
+ def preclean_pendings
+ self.registrant_verification_token = nil
+ self.registrant_verification_asked_at = nil
+ end
+
+ def clean_pendings!
+ preclean_pendings
+ self.pending_json = {}
+ domain_statuses.where(value: DomainStatus::PENDING_UPDATE).destroy_all
+ domain_statuses.where(value: DomainStatus::PENDING_DELETE).destroy_all
+ save
+ end
+
def pending_update?
(domain_statuses.pluck(:value) & %W(
#{DomainStatus::PENDING_UPDATE}
@@ -280,9 +298,10 @@ class Domain < ActiveRecord::Base
self.epp_pending_update = true # for epp
return true unless registrant_verification_asked?
- pending_json_cache = all_changes
+ pending_json_cache = pending_json
token = registrant_verification_token
asked_at = registrant_verification_asked_at
+ changes_cache = changes
DomainMailer.registrant_pending_updated(self).deliver_now
@@ -291,10 +310,12 @@ class Domain < ActiveRecord::Base
self.pending_json = pending_json_cache
self.registrant_verification_token = token
self.registrant_verification_asked_at = asked_at
+ self.pending_json[:domain] = changes_cache
domain_statuses.create(value: DomainStatus::PENDING_UPDATE)
end
def registrant_update_confirmable?(token)
+ return true if Rails.env.development?
return false unless pending_update?
return false if registrant_verification_token.blank?
return false if registrant_verification_asked_at.blank?
@@ -304,6 +325,7 @@ class Domain < ActiveRecord::Base
end
def registrant_delete_confirmable?(token)
+ return true if Rails.env.development?
return false unless pending_delete?
return false if registrant_verification_token.blank?
return false if registrant_verification_asked_at.blank?
@@ -320,7 +342,9 @@ class Domain < ActiveRecord::Base
registrant_verification_asked_at.present? && registrant_verification_token.present?
end
- def registrant_verification_asked!
+ def registrant_verification_asked!(frame_str, current_user_id)
+ self.pending_json['frame'] = frame_str
+ self.pending_json['current_user_id'] = current_user_id
self.registrant_verification_asked_at = Time.zone.now
self.registrant_verification_token = SecureRandom.hex(42)
end
@@ -393,12 +417,10 @@ class Domain < ActiveRecord::Base
name
end
- def pending_registrant_name
+ def pending_registrant
return '' if pending_json.blank?
- return '' if pending_json['domain'].blank?
return '' if pending_json['domain']['registrant_id'].blank?
- registrant = Registrant.find_by(id: pending_json['domain']['registrant_id'].last)
- registrant.try(:name)
+ Registrant.find_by(id: pending_json['domain']['registrant_id'].last)
end
# rubocop:disable Lint/Loop
@@ -465,17 +487,6 @@ class Domain < ActiveRecord::Base
log
end
- def all_changes
- all_changes = HashWithIndifferentAccess.new
- all_changes[:domain] = changes
- all_changes[:admin_contacts] = admin_contacts.map(&:changes)
- all_changes[:tech_contacts] = tech_contacts.map(&:changes)
- all_changes[:nameservers] = nameservers.map(&:changes)
- all_changes[:registrant] = registrant.try(:changes)
- all_changes[:domain_statuses] = domain_statuses.map(&:changes)
- all_changes
- end
-
def update_whois_record
whois_record.blank? ? create_whois_record : whois_record.save
end
diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb
index 4e7dc7f62..f6870f7c4 100644
--- a/app/models/epp/domain.rb
+++ b/app/models/epp/domain.rb
@@ -394,14 +394,25 @@ class Epp::Domain < Domain
at[:dnskeys_attributes] += at_add[:dnskeys_attributes]
at[:domain_statuses_attributes] += at_add[:domain_statuses_attributes]
- if frame.css('registrant').present? && frame.css('registrant').attr('verified').to_s.downcase != 'yes'
- registrant_verification_asked!
+ if frame.css('registrant').present? && frame.css('registrant').attr('verified').to_s.downcase != 'yes' && !pending_update?
+ registrant_verification_asked!(frame.to_s, current_user.id)
end
self.deliver_emails = true # turn on email delivery for epp
errors.empty? && super(at)
end
+ def apply_pending_update!
+ preclean_pendings
+ user = ApiUser.find(pending_json['current_user_id'])
+ frame = Nokogiri::XML(pending_json['frame'])
+ domain_statuses.where(value: DomainStatus::PENDING_UPDATE).destroy_all
+ domain_statuses.reload
+ if update(frame, user)
+ clean_pendings!
+ end
+ end
+
def attach_legal_document(legal_document_data)
return unless legal_document_data
diff --git a/app/models/registrant_verification.rb b/app/models/registrant_verification.rb
index d56170bdd..99a3e3e60 100644
--- a/app/models/registrant_verification.rb
+++ b/app/models/registrant_verification.rb
@@ -17,12 +17,16 @@ class RegistrantVerification < ActiveRecord::Base
def domain_registrant_change_confirm!
self.action_type = DOMAIN_REGISTRANT_CHANGE
self.action = CONFIRMED
- save
+ if save
+ DomainConfirmJob.enqueue domain.id, CONFIRMED
+ end
end
def domain_registrant_change_reject!
self.action_type = DOMAIN_REGISTRANT_CHANGE
self.action = REJECTED
- save
+ if save
+ DomainConfirmJob.enqueue domain.id, REJECTED
+ end
end
end
diff --git a/app/views/domain_mailer/registrant_pending_updated.html.erb b/app/views/domain_mailer/registrant_pending_updated.html.erb
index b081bf2b4..9f071df10 100644
--- a/app/views/domain_mailer/registrant_pending_updated.html.erb
+++ b/app/views/domain_mailer/registrant_pending_updated.html.erb
@@ -9,8 +9,6 @@ Isikukood: <%= @domain.registrant_ident %>
<% else %>
Äriregistrikood: <%= @domain.registrant_ident %>
<% end %>
-Epost: <%= @domain.registrant_email %>
-Tel: <%= @domain.registrant_phone %>
Tänav: <%= @domain.registrant_street %>
Linn: <%= @domain.registrant_city %>
Riik: <%= @domain.registrant_country %>
@@ -34,8 +32,6 @@ Personal code: <%= @domain.registrant_ident %>
<% else %>
Business Registry code: <%= @domain.registrant_ident %>
<% end %>
-E-mail: <%= @domain.registrant_email %>
-Tel: <%= @domain.registrant_phone %>
Street: <%= @domain.registrant_street %>
City: <%= @domain.registrant_city %>
Country: <%= @domain.registrant_country %>
diff --git a/app/views/domain_mailer/registrant_pending_updated.text.erb b/app/views/domain_mailer/registrant_pending_updated.text.erb
index ca6609eac..228c7f0a4 100644
--- a/app/views/domain_mailer/registrant_pending_updated.text.erb
+++ b/app/views/domain_mailer/registrant_pending_updated.text.erb
@@ -9,8 +9,6 @@ Isikukood: <%= @domain.registrant_ident %>
<% else %>
Äriregistrikood: <%= @domain.registrant_ident %>
<% end %>
-Epost: <%= @domain.registrant_email %>
-Tel: <%= @domain.registrant_phone %>
Tänav: <%= @domain.registrant_street %>
Linn: <%= @domain.registrant_city %>
Riik: <%= @domain.registrant_country %>
@@ -34,8 +32,6 @@ Personal code: <%= @domain.registrant_ident %>
<% else %>
Business Registry code: <%= @domain.registrant_ident %>
<% end %>
-E-mail: <%= @domain.registrant_email %>
-Tel: <%= @domain.registrant_phone %>
Street: <%= @domain.registrant_street %>
City: <%= @domain.registrant_city %>
Country: <%= @domain.registrant_country %>
diff --git a/app/views/registrant/domain_update_confirms/show.haml b/app/views/registrant/domain_update_confirms/show.haml
index d777f3bf6..796638109 100644
--- a/app/views/registrant/domain_update_confirms/show.haml
+++ b/app/views/registrant/domain_update_confirms/show.haml
@@ -25,13 +25,13 @@
.row
.col-md-12.text-center.confirmation
.column-keys
- %p= t(:domain_name) + ':'
+ %p= t(:domain_name) + ':'
%p= t(:current_registrant) + ':'
%p= t(:new_pending_registrant) + ':'
.column-values
%p= @domain.name
- %p= @domain.registrant_name
- %p= @domain.pending_registrant_name
+ %p= "#{@domain.registrant_name} (#{@domain.registrant.ident})"
+ %p= "#{@domain.pending_registrant.try(:name)} (#{@domain.pending_registrant.try(:ident)})"
.row
.col-md-12.text-center
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 4522f1215..2337959d5 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -788,8 +788,8 @@ en:
reject_domain_registrant_update: 'Reject domain ownership change'
domain_registrant_change_title: 'Please confirm or reject domain ownership change'
domain_registrant_change_body: 'There is a request to change domain ownership. Before doing it we need your confirmation.'
- new_pending_registrant: 'New owner'
- current_registrant: 'Current owner'
+ new_pending_registrant: 'New registrant'
+ current_registrant: 'Current registrant'
registrant_domain_verification_failed: 'Domain verification not available'
domain_registrant_change_confirmed_title: 'Domain owner change has been confirmed'
domain_registrant_change_confirmed_body: 'You have successfully confirmed domain owner change.'