diff --git a/app/jobs/domain_update_confirm_job.rb b/app/jobs/domain_update_confirm_job.rb
index 7d4fc488f..b4d2a9f57 100644
--- a/app/jobs/domain_update_confirm_job.rb
+++ b/app/jobs/domain_update_confirm_job.rb
@@ -7,6 +7,7 @@ class DomainUpdateConfirmJob < Que::Job
domain.is_admin = true
case action
when RegistrantVerification::CONFIRMED
+ old_registrant = domain.registrant
domain.poll_message!(:poll_pending_update_confirmed_by_registrant)
raise_errors!(domain)
@@ -15,6 +16,7 @@ class DomainUpdateConfirmJob < Que::Job
domain.clean_pendings!
raise_errors!(domain)
+ RegistrantChange.new(domain: domain, old_registrant: old_registrant).confirm
when RegistrantVerification::REJECTED
RegistrantChangeMailer.rejected(domain: domain,
registrar: domain.registrar,
diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb
index 8c8c2d556..f14f4b4a7 100644
--- a/app/mailers/domain_mailer.rb
+++ b/app/mailers/domain_mailer.rb
@@ -1,37 +1,6 @@
class DomainMailer < ApplicationMailer
include Que::Mailer
- def registrant_updated_notification_for_new_registrant(domain_id, old_registrant_id, new_registrant_id, should_deliver)
- @domain = Domain.find_by(id: domain_id)
- return unless @domain
- return if delivery_off?(@domain, should_deliver)
-
- @old_registrant = Registrant.find(old_registrant_id)
- @new_registrant = Registrant.find(new_registrant_id)
- @address_processing = Contact.address_processing?
-
- return if whitelist_blocked?(@new_registrant.email)
- mail(to: format(@new_registrant.email),
- subject: "#{I18n.t(:registrant_updated_notification_for_new_registrant_subject,
- name: @domain.name)} [#{@domain.name}]")
- end
-
-
- def registrant_updated_notification_for_old_registrant(domain_id, old_registrant_id, new_registrant_id, should_deliver)
- @domain = Domain.find_by(id: domain_id)
- return unless @domain
- return if delivery_off?(@domain, should_deliver)
-
- @old_registrant = Registrant.find(old_registrant_id)
- @new_registrant = Registrant.find(new_registrant_id)
- @address_processing = Contact.address_processing?
-
- return if whitelist_blocked?(@old_registrant.email)
- mail(to: format(@old_registrant.email),
- subject: "#{I18n.t(:registrant_updated_notification_for_old_registrant_subject,
- name: @domain.name)} [#{@domain.name}]")
- end
-
def pending_delete_rejected_notification(domain_id, should_deliver)
@domain = Domain.find_by(id: domain_id)
return unless @domain
diff --git a/app/mailers/registrant_change_mailer.rb b/app/mailers/registrant_change_mailer.rb
index 2a8620ee6..92ee0bd4d 100644
--- a/app/mailers/registrant_change_mailer.rb
+++ b/app/mailers/registrant_change_mailer.rb
@@ -21,6 +21,14 @@ class RegistrantChangeMailer < ApplicationMailer
mail(to: new_registrant.email, subject: subject)
end
+ def confirmed(domain:, old_registrant:)
+ @domain = domain
+ recipients = [domain.registrant_email, old_registrant.email]
+ subject = default_i18n_subject(domain_name: domain.name)
+
+ mail(to: recipients, subject: subject)
+ end
+
def rejected(domain:, registrar:, registrant:)
@domain = DomainPresenter.new(domain: domain, view: view_context)
@registrar = RegistrarPresenter.new(registrar: registrar, view: view_context)
diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb
index f16ad7fc3..997c77fc5 100644
--- a/app/models/epp/domain.rb
+++ b/app/models/epp/domain.rb
@@ -521,9 +521,7 @@ class Epp::Domain < Domain
preclean_pendings
user = ApiUser.find(pending_json['current_user_id'])
frame = Nokogiri::XML(pending_json['frame'])
- old_registrant_id = registrant_id
- self.deliver_emails = true # turn on email delivery
self.statuses.delete(DomainStatus::PENDING_UPDATE)
self.upid = user.registrar.id if user.registrar
self.up_date = Time.zone.now
@@ -531,11 +529,9 @@ class Epp::Domain < Domain
return unless update(frame, user, false)
clean_pendings!
- save! # for notification if everything fails
+ save!
WhoisRecord.find_by(domain_id: id).save # need to reload model
- DomainMailer.registrant_updated_notification_for_old_registrant(id, old_registrant_id, registrant_id, true).deliver
- DomainMailer.registrant_updated_notification_for_new_registrant(id, old_registrant_id, registrant_id, true).deliver
true
end
diff --git a/app/services/registrant_change.rb b/app/services/registrant_change.rb
new file mode 100644
index 000000000..a820dbe8d
--- /dev/null
+++ b/app/services/registrant_change.rb
@@ -0,0 +1,19 @@
+class RegistrantChange
+ def initialize(domain:, old_registrant:)
+ @domain = domain
+ @old_registrant = old_registrant
+ end
+
+ def confirm
+ notify_registrant
+ end
+
+ private
+
+ def notify_registrant
+ RegistrantChangeMailer.confirmed(domain: domain, old_registrant: old_registrant).deliver_now
+ end
+
+ attr_reader :domain
+ attr_reader :old_registrant
+end
diff --git a/app/views/mailers/domain_mailer/registrant_updated_notification_for_new_registrant.html.erb b/app/views/mailers/domain_mailer/registrant_updated_notification_for_new_registrant.html.erb
deleted file mode 100644
index 9797b18b3..000000000
--- a/app/views/mailers/domain_mailer/registrant_updated_notification_for_new_registrant.html.erb
+++ /dev/null
@@ -1,43 +0,0 @@
-Tere
-
-Domeeni <%= @domain.name %> registreerija vahetuse taotlus on kinnitatud ning andmed registris uuendatud.
-
-Uue registreerija andmed:
-Nimi: <%= @new_registrant.name %>
-<% if @new_registrant.priv? %>
- Isikukood: <%= @new_registrant.ident %>
-<% else %>
- Äriregistrikood: <%= @new_registrant.ident %>
-<% end %>
-Epost: <%= @new_registrant.email %>
-<% if @address_processing -%>
-Tänav: <%= @new_registrant.street %>
-Linn: <%= @new_registrant.city %>
-Riik: <%= @new_registrant.country.name %>
-<% end -%>
-
-Lugupidamisega
-Eesti Interneti Sihtasutus
-
-
-
-Hi,
-
-Process for changing registrant of the domain <%= @domain.name %> has been approved and the data in the registry is updated.
-
-New registrant:
-Name: <%= @new_registrant.name %>
-<% if @new_registrant.priv? %>
- Personal code: <%= @new_registrant.ident %>
-<% else %>
- Business Registry code: <%= @new_registrant.ident %>
-<% end %>
-E-mail: <%= @new_registrant.email %>
-<% if @address_processing -%>
-Street: <%= @new_registrant.street %>
-City: <%= @new_registrant.city %>
-Country: <%= @new_registrant.country.name %>
-<% end -%>
-
-Best Regards,
-Estonian Internet Foundation
diff --git a/app/views/mailers/domain_mailer/registrant_updated_notification_for_new_registrant.text.erb b/app/views/mailers/domain_mailer/registrant_updated_notification_for_new_registrant.text.erb
deleted file mode 100644
index fec027aaa..000000000
--- a/app/views/mailers/domain_mailer/registrant_updated_notification_for_new_registrant.text.erb
+++ /dev/null
@@ -1,45 +0,0 @@
-Tere
-
-Domeeni <%= @domain.name %> registreerija vahetuse taotlus on kinnitatud ning andmed registris uuendatud.
-
-Uue registreerija andmed:
-Nimi: <%= @new_registrant.name %>
-
-<% if @new_registrant.priv? %>
- Isikukood: <%= @new_registrant.ident %>
-<% else %>
- Äriregistrikood: <%= @new_registrant.ident %>
-<% end %>
-Epost: <%= @new_registrant.email %>
-<% if @address_processing -%>
-Tänav: <%= @new_registrant.street %>
-Linn: <%= @new_registrant.city %>
-Riik: <%= @new_registrant.country.name %>
-<% end -%>
-
-Lugupidamisega
-Eesti Interneti Sihtasutus
-
---------------------------------------
-
-Hi,
-
-Process for changing registrant of the domain <%= @domain.name %> has been approved and the data in the registry is updated.
-
-New registrant:
-Name: <%= @new_registrant.name %>
-
-<% if @new_registrant.priv? %>
- Personal code: <%= @new_registrant.ident %>
-<% else %>
- Business Registry code: <%= @new_registrant.ident %>
-<% end %>
-E-mail: <%= @new_registrant.email %>
-<% if @address_processing -%>
-Street: <%= @new_registrant.street %>
-City: <%= @new_registrant.city %>
-Country: <%= @new_registrant.country.name %>
-<% end -%>
-
-Best Regards,
-Estonian Internet Foundation
diff --git a/app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.html.erb b/app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.html.erb
deleted file mode 100644
index b1cf2ff7b..000000000
--- a/app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.html.erb
+++ /dev/null
@@ -1,43 +0,0 @@
-Tere
-
-Domeeni <%= @domain.name %> registreerija vahetuse taotlus on kinnitatud ning andmed registris uuendatud.
-
-Uue registreerija andmed:
-Nimi: <%= @new_registrant.name %>
-<% if @new_registrant.priv? %>
-Isikukood: <%= @new_registrant.ident %>
-<% else %>
-Äriregistrikood: <%= @new_registrant.ident %>
-<% end %>
-Epost: <%= @new_registrant.email %>
-<% if @address_processing -%>
-Tänav: <%= @new_registrant.street %>
-Linn: <%= @new_registrant.city %>
-Riik: <%= @new_registrant.country.name %>
-<% end -%>
-
-Lugupidamisega
-Eesti Interneti Sihtasutus
-
-
-
-Hi,
-
-Process for changing registrant of the domain <%= @domain.name %> has been approved and the data in the registry is updated.
-
-New registrant:
-Name: <%= @new_registrant.name %>
-<% if @new_registrant.priv? %>
-Personal code: <%= @new_registrant.ident %>
-<% else %>
-Business Registry code: <%= @new_registrant.ident %>
-<% end %>
-E-mail: <%= @new_registrant.email %>
-<% if @address_processing -%>
-Street: <%= @new_registrant.street %>
-City: <%= @new_registrant.city %>
-Country: <%= @new_registrant.country.name %>
-<% end -%>
-
-Best Regards,
-Estonian Internet Foundation
diff --git a/app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.text.erb b/app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.text.erb
deleted file mode 100644
index 5a333e662..000000000
--- a/app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.text.erb
+++ /dev/null
@@ -1,45 +0,0 @@
-Tere
-
-Domeeni <%= @domain.name %> registreerija vahetuse taotlus on kinnitatud ning andmed registris uuendatud.
-
-Uue registreerija andmed:
-Nimi: <%= @new_registrant.name %>
-
-<% if @new_registrant.priv? %>
-Isikukood: <%= @new_registrant.ident %>
-<% else %>
-Äriregistrikood: <%= @new_registrant.ident %>
-<% end %>
-Epost: <%= @new_registrant.email %>
-<% if @address_processing -%>
-Tänav: <%= @new_registrant.street %>
-Linn: <%= @new_registrant.city %>
-Riik: <%= @new_registrant.country.name %>
-<% end -%>
-
-Lugupidamisega
-Eesti Interneti Sihtasutus
-
---------------------------------------
-
-Hi,
-
-Process for changing registrant of the domain <%= @domain.name %> has been approved and the data in the registry is updated.
-
-New registrant:
-Name: <%= @new_registrant.name %>
-
-<% if @new_registrant.priv? %>
-Personal code: <%= @new_registrant.ident %>
-<% else %>
-Business Registry code: <%= @new_registrant.ident %>
-<% end %>
-E-mail: <%= @new_registrant.email %>
-<% if @address_processing -%>
-Street: <%= @new_registrant.street %>
-City: <%= @new_registrant.city %>
-Country: <%= @new_registrant.country.name %>
-<% end -%>
-
-Best Regards,
-Estonian Internet Foundation
diff --git a/app/views/mailers/registrant_change_mailer/confirmed.html.erb b/app/views/mailers/registrant_change_mailer/confirmed.html.erb
new file mode 100644
index 000000000..b56aae53c
--- /dev/null
+++ b/app/views/mailers/registrant_change_mailer/confirmed.html.erb
@@ -0,0 +1,25 @@
+<%
+ domain = DomainPresenter.new(domain: @domain, view: self)
+ new_registrant = RegistrantPresenter.new(registrant: @domain.registrant, view: self)
+%>
+Tere
+
+Domeeni <%= domain.name %> registreerija vahetuse taotlus on kinnitatud ning andmed registris uuendatud.
+
+Uue registreerija andmed:
+<%= render 'mailers/shared/registrant/registrant.et.html', registrant: new_registrant %>
+
+Lugupidamisega
+Eesti Interneti Sihtasutus
+
+
+
+Hi,
+
+Process for changing registrant of the domain <%= domain.name %> has been approved and the data in the registry is updated.
+
+New registrant:
+<%= render 'mailers/shared/registrant/registrant.en.html', registrant: new_registrant %>
+
+Best Regards,
+Estonian Internet Foundation
diff --git a/app/views/mailers/registrant_change_mailer/confirmed.text.erb b/app/views/mailers/registrant_change_mailer/confirmed.text.erb
new file mode 100644
index 000000000..2bab1f4c2
--- /dev/null
+++ b/app/views/mailers/registrant_change_mailer/confirmed.text.erb
@@ -0,0 +1,25 @@
+<%
+ domain = DomainPresenter.new(domain: @domain, view: self)
+ new_registrant = RegistrantPresenter.new(registrant: @domain.registrant, view: self)
+%>
+Tere
+
+Domeeni <%= domain.name %> registreerija vahetuse taotlus on kinnitatud ning andmed registris uuendatud.
+
+Uue registreerija andmed:
+<%= render 'mailers/shared/registrant/registrant.et.text', registrant: new_registrant %>
+
+Lugupidamisega
+Eesti Interneti Sihtasutus
+
+--------------------------------------
+
+Hi,
+
+Process for changing registrant of the domain <%= domain.name %> has been approved and the data in the registry is updated.
+
+New registrant:
+<%= render 'mailers/shared/registrant/registrant.en.text', registrant: new_registrant %>
+
+Best Regards,
+Estonian Internet Foundation
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 29a9ee5f4..b9dffce2e 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -760,8 +760,6 @@ en:
unimplemented_object_service: 'Unimplemented object service'
contact_email_update_subject: 'Teie domeenide kontakt epostiaadress on muutunud / Contact e-mail addresses of your domains have changed'
object_status_prohibits_operation: 'Object status prohibits operation'
- registrant_updated_notification_for_new_registrant_subject: 'Domeeni %{name} registreerija vahetus teostatud / Registrant change of %{name} has been finished.'
- registrant_updated_notification_for_old_registrant_subject: 'Domeeni %{name} registreerija vahetus teostatud / Registrant change of %{name} has been finished.'
pending_delete_rejected_notification_subject: "Domeeni %{name} kustutamise taotlus tagasi lükatud / %{name} deletion declined"
pending_delete_expired_notification_subject: "Domeeni %{name} kustutamise taotlus on tühistatud / %{name} deletion cancelled"
delete_confirmation_subject: "Domeeni %{name} kustutatud / %{name} deleted"
diff --git a/config/locales/mailers/registrant_change.en.yml b/config/locales/mailers/registrant_change.en.yml
index 9cd95f648..87a7cc492 100644
--- a/config/locales/mailers/registrant_change.en.yml
+++ b/config/locales/mailers/registrant_change.en.yml
@@ -6,5 +6,9 @@ en:
subject: Domeeni %{domain_name} registreerija vahetus protseduur on algatatud / %{domain_name} registrant change
rejected:
subject: Domeeni %{domain_name} registreerija vahetuse taotlus tagasi lükatud / %{domain_name} registrant change declined
+ confirmed:
+ subject: >-
+ Domeeni %{domain_name} registreerija vahetus teostatud
+ / Registrant change of %{domain_name} has been finished
expired:
subject: Domeeni %{domain_name} registreerija vahetuse taotlus on tühistatud / %{domain_name} registrant change cancelled
diff --git a/spec/jobs/domain_update_confirm_job_spec.rb b/spec/jobs/domain_update_confirm_job_spec.rb
new file mode 100644
index 000000000..4748ca021
--- /dev/null
+++ b/spec/jobs/domain_update_confirm_job_spec.rb
@@ -0,0 +1,18 @@
+require 'rails_helper'
+
+RSpec.describe DomainUpdateConfirmJob do
+ let(:domain) { instance_spy(Epp::Domain, registrant: registrant, errors: []) }
+ let(:registrant) { instance_double(Registrant) }
+ let(:registrant_change) { instance_spy(RegistrantChange) }
+
+ it 'confirms registrant change' do
+ expect(Epp::Domain).to receive(:find).and_return(domain)
+ expect(RegistrantChange).to receive(:new)
+ .with(domain: domain, old_registrant: registrant)
+ .and_return(registrant_change)
+
+ described_class.enqueue(domain_id = nil, action = RegistrantVerification::CONFIRMED)
+
+ expect(registrant_change).to have_received(:confirm)
+ end
+end
diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb
deleted file mode 100644
index e05c5ad38..000000000
--- a/spec/mailers/domain_mailer_spec.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-require 'rails_helper'
-
-RSpec.describe DomainMailer do
- describe '#registrant_updated_notification_for_new_registrant', db: true do
- subject(:message) { described_class.registrant_updated_notification_for_new_registrant(55, 55, 55, true) }
-
- context 'when contact address processing is enabled' do
- before :example do
- allow(Contact).to receive(:address_processing?).and_return(true)
- create(:domain, id: 55)
- create(:registrant_with_address, id: 55)
- end
-
- it 'sends message' do
- expect { message.deliver }.to change { ActionMailer::Base.deliveries.count }.by(1)
- end
- end
-
- context 'when contact address processing is disabled' do
- before :example do
- allow(Contact).to receive(:address_processing?).and_return(false)
- create(:domain, id: 55)
- create(:registrant_without_address, id: 55)
- end
-
- it 'sends message' do
- expect { message.deliver }.to change { ActionMailer::Base.deliveries.count }.by(1)
- end
- end
- end
-
- describe '#registrant_updated_notification_for_old_registrant', db: true do
- subject(:message) { described_class.registrant_updated_notification_for_old_registrant(55, 55, 55, true) }
-
- context 'when contact address processing is enabled' do
- before :example do
- allow(Contact).to receive(:address_processing?).and_return(true)
- create(:domain, id: 55)
- create(:registrant_with_address, id: 55)
- end
-
- it 'sends message' do
- expect { message.deliver }.to change { ActionMailer::Base.deliveries.count }.by(1)
- end
- end
-
- context 'when contact address processing is disabled' do
- before :example do
- allow(Contact).to receive(:address_processing?).and_return(false)
- create(:domain, id: 55)
- create(:registrant_without_address, id: 55)
- end
-
- it 'sends message' do
- expect { message.deliver }.to change { ActionMailer::Base.deliveries.count }.by(1)
- end
- end
- end
-end
diff --git a/spec/mailers/registrant_change_mailer_spec.rb b/spec/mailers/registrant_change_mailer_spec.rb
index be1e7d105..e38cde83d 100644
--- a/spec/mailers/registrant_change_mailer_spec.rb
+++ b/spec/mailers/registrant_change_mailer_spec.rb
@@ -94,6 +94,40 @@ RSpec.describe RegistrantChangeMailer do
end
end
+ describe '#confirmed' do
+ let(:domain) { instance_spy(Domain, registrant_email: 'new.registrant@test.com') }
+ let(:old_registrant) { instance_spy(Registrant, email: 'old.registrant@test.com') }
+ let(:registrant_presenter) { instance_spy(RegistrantPresenter) }
+ let(:domain_presenter) { instance_spy(DomainPresenter) }
+ subject(:message) { described_class.confirmed(domain: domain, old_registrant: old_registrant) }
+
+ before :example do
+ allow(RegistrantPresenter).to receive(:new).and_return(registrant_presenter)
+ allow(DomainPresenter).to receive(:new).and_return(domain_presenter)
+ end
+
+ it 'has sender' do
+ expect(message.from).to eq(['noreply@internet.ee'])
+ end
+
+ it 'has new registrant email as a recipient' do
+ expect(message.to).to include('new.registrant@test.com')
+ end
+
+ it 'has old registrant email as a recipient' do
+ expect(message.to).to include('old.registrant@test.com')
+ end
+
+ it 'has subject' do
+ allow(domain).to receive(:name).and_return('test.com')
+ expect(message.subject).to eq(t('registrant_change_mailer.confirmed.subject', domain_name: 'test.com'))
+ end
+
+ it 'sends message' do
+ expect { message.deliver_now }.to change { ActionMailer::Base.deliveries.count }.by(1)
+ end
+ end
+
describe '#rejected' do
let(:domain) { instance_spy(Domain, name: 'test.com', new_registrant_email: 'new.registrant@test.com') }
let(:registrar) { instance_spy(Registrar) }
diff --git a/spec/services/registrant_change_spec.rb b/spec/services/registrant_change_spec.rb
new file mode 100644
index 000000000..fb1762557
--- /dev/null
+++ b/spec/services/registrant_change_spec.rb
@@ -0,0 +1,20 @@
+require 'rails_helper'
+
+RSpec.describe RegistrantChange do
+ describe '#confirm' do
+ let(:domain) { instance_double(Domain) }
+ let(:old_registrant) { instance_double(Registrant) }
+ let(:message) { instance_spy(ActionMailer::MessageDelivery) }
+
+ before :example do
+ allow(RegistrantChangeMailer).to receive(:confirmed)
+ .with(domain: domain, old_registrant: old_registrant)
+ .and_return(message)
+ described_class.new(domain: domain, old_registrant: old_registrant).confirm
+ end
+
+ it 'notifies registrant' do
+ expect(message).to have_received(:deliver_now)
+ end
+ end
+end