Added multiple domain emails #2786

This commit is contained in:
Priit Tark 2015-07-28 17:32:14 +03:00
parent 00d42ef3c4
commit 8a92591df7
18 changed files with 243 additions and 47 deletions

View file

@ -8,7 +8,7 @@ class DomainUpdateConfirmJob < Que::Job
domain.apply_pending_update!
domain.clean_pendings!
when RegistrantVerification::REJECTED
DomainMailer.pending_update_rejected_new_registrant_notification(domain).deliver_now
DomainMailer.pending_update_rejected_notification_for_new_registrant(domain).deliver_now
domain.clean_pendings!
end
destroy # it's best to destroy the job in the same transaction

View file

@ -1,5 +1,5 @@
class DomainMailer < ApplicationMailer
def pending_update_old_registrant_request(domain)
def pending_update_request_for_old_registrant(domain)
@domain = domain
return if delivery_off?(@domain)
@ -20,11 +20,11 @@ class DomainMailer < ApplicationMailer
return if whitelist_blocked?(@old_registrant.email)
mail(to: @old_registrant.email,
subject: "#{I18n.t(:pending_update_old_registrant_request_subject,
subject: "#{I18n.t(:pending_update_request_for_old_registrant_subject,
name: @domain.name)} [#{@domain.name}]")
end
def pending_update_new_registrant_notification(domain)
def pending_update_notification_for_new_registrant(domain)
@domain = domain
return if delivery_off?(@domain)
@ -43,21 +43,33 @@ class DomainMailer < ApplicationMailer
return if whitelist_blocked?(@new_registrant.email)
mail(to: @new_registrant.email,
subject: "#{I18n.t(:pending_update_new_registrant_notification_subject,
subject: "#{I18n.t(:pending_update_notification_for_new_registrant_subject,
name: @domain.name)} [#{@domain.name}]")
end
def registrant_updated(domain)
def registrant_updated_notification_for_new_registrant(domain)
@domain = domain
return if delivery_off?(@domain)
return if whitelist_blocked?(@domain.registrant_email)
mail(to: @domain.registrant_email,
subject: "#{I18n.t(:domain_registrant_updated,
subject: "#{I18n.t(:registrant_updated_notification_for_new_registrant_subject,
name: @domain.name)} [#{@domain.name}]")
end
def pending_update_rejected_new_registrant_notification(domain)
def registrant_updated_notification_for_old_registrant(domain)
@domain = domain
return if delivery_off?(@domain)
@old_registrant_email = domain.registrant_email # Nb! before applying pending updates
return if whitelist_blocked?(@old_registrant_email)
mail(to: @old_registrant_email,
subject: "#{I18n.t(:registrant_updated_notification_for_old_registrant_subject,
name: @domain.name)} [#{@domain.name}]")
end
def pending_update_rejected_notification_for_new_registrant(domain)
@domain = domain
# no delivery off control, driggered by que, no epp request
@ -66,7 +78,24 @@ class DomainMailer < ApplicationMailer
return if whitelist_blocked?(@new_registrant_email)
mail(to: @new_registrant_email,
subject: "#{I18n.t(:pending_update_rejected_new_registrant_notification_subject,
subject: "#{I18n.t(:pending_update_rejected_notification_for_new_registrant_subject,
name: @domain.name)} [#{@domain.name}]")
end
def pending_update_expired_notification_for_new_registrant(domain)
@domain = domain
# no delivery off control, driggered by cron, no epp request
@new_registrant_email = @domain.pending_json[:new_registrant_email]
@new_registrant_name = @domain.pending_json[:new_registrant_name]
return if whitelist_blocked?(@new_registrant_email)
if @new_registrant_email.blank?
logger.info "EMAIL NOT DELIVERED: no registrant email [pending_update_expired_notification_for_new_registrant]"
return
end
mail(to: @new_registrant_email,
subject: "#{I18n.t(:pending_update_expired_notification_for_new_registrant_subject,
name: @domain.name)} [#{@domain.name}]")
end

View file

@ -198,6 +198,7 @@ class Domain < ActiveRecord::Base
next
end
count += 1
DomainMailer.pending_update_expired_notification_for_new_registrant(domain).deliver_now
domain.clean_pendings!
STDOUT << "#{Time.zone.now.utc} Domain.clean_expired_pendings: ##{domain.id}\n" unless Rails.env.test?
end
@ -363,8 +364,8 @@ class Domain < ActiveRecord::Base
new_registrant_email = registrant.email
new_registrant_name = registrant.name
DomainMailer.pending_update_old_registrant_request(self).deliver_now
DomainMailer.pending_update_new_registrant_notification(self).deliver_now
DomainMailer.pending_update_request_for_old_registrant(self).deliver_now
DomainMailer.pending_update_notification_for_new_registrant(self).deliver_now
reload # revert back to original

View file

@ -420,6 +420,7 @@ class Epp::Domain < Domain
# rubocop: enable Metrics/AbcSize
def apply_pending_update!
old_registrant_email = DomainMailer.registrant_updated_notification_for_old_registrant(self)
preclean_pendings
user = ApiUser.find(pending_json['current_user_id'])
frame = Nokogiri::XML(pending_json['frame'])
@ -428,7 +429,8 @@ class Epp::Domain < Domain
return unless update(frame, user, false)
clean_pendings!
self.deliver_emails = true # turn on email delivery for epp
DomainMailer.registrant_updated(self).deliver_now
DomainMailer.registrant_updated_notification_for_new_registrant(self).deliver_now
old_registrant_email.deliver_now
end
def apply_pending_delete!

View file

@ -0,0 +1,19 @@
Tere,
<br><br>
Domeeni <%= @domain.name %> registreerija <%= @domain.registrant_name %> ei kinnitanud tähtaegselt registreerija vahetuse taotlust. Domeeni <%= @domain.name %> registreerija vahetus on sellest tulenevalt tühistatud.
<br><br>
Küsimuste korral palun võtke ühendust registripidajaga <%= @domain.registrar_name %>, kelle kontaktid leiate http://internet.ee/registripidajad/akrediteeritud-registripidajad
<br><br>
Lugupidamisega<br>
Eesti Interneti SA
<br><br>
<hr>
<br><br>
Hi,
<br><br>
Domain registrant change has been expired for the domain <%= @domain.name %>.
<br><br>
Please contact to your registrar <%= @domain.registrar_name %> if you have any questions.
<br><br>
Best Regards,<br>
Estonian Internet Foundation

View file

@ -0,0 +1,19 @@
Tere,
Domeeni <%= @domain.name %> registreerija <%= @domain.registrant_name %> ei kinnitanud tähtaegselt registreerija vahetuse taotlust. Domeeni <%= @domain.name %> registreerija vahetus on sellest tulenevalt tühistatud.
Küsimuste korral palun võtke ühendust registripidajaga <%= @domain.registrar_name %>, kelle kontaktid leiate http://internet.ee/registripidajad/akrediteeritud-registripidajad
Lugupidamisega
Eesti Interneti SA
--------------------------------------
Hi,
Domain registrant change has been expired for the domain <%= @domain.name %>.
Please contact to your registrar <%= @domain.registrar_name %> if you have any questions.
Best Regards,
Estonian Internet Foundation

View file

@ -0,0 +1,21 @@
Tere,
<br><br>
Domeeni <%= @domain.name %> registreerija vahetuse taotlus on kinnitatud ning andmed registris uuendatud.
<br><br>
Uued registreerija:<br>
Nimi: <%= @domain.registrant_name %>
<br><br>
Lugupidamisega<br>
Eesti Interneti SA
<br><br>
<hr>
<br><br>
Hi,
<br><br>
Process for changing registrant of the domain <%= @domain.name %> has been approved and the data in the registry is updated.
<br><br>
New registrant:<br>
Name: <%= @domain.registrant_name %>
<br><br>
Best Regards,<br>
Estonian Internet Foundation

View file

@ -0,0 +1,21 @@
Tere,
Domeeni <%= @domain.name %> registreerija vahetuse taotlus on kinnitatud ning andmed registris uuendatud.
Uued registreerija:
Nimi: <%= @domain.registrant_name %>
Lugupidamisega
Eesti Interneti SA
--------------------------------------
Hi,
Process for changing registrant of the domain <%= @domain.name %> has been approved and the data in the registry is updated.
New registrant:
Name: <%= @domain.registrant_name %>
Best Regards,
Estonian Internet Foundation

View file

@ -777,9 +777,12 @@ 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'
pending_update_old_registrant_request_subject: "Kinnitustaotlus domeeni %{name} registreerija vahetuseks / Application for approval for registrant chache of %{name}"
pending_update_new_registrant_notification_subject: "Domeeni %{name} registreerija vahetus protseduur on algatatud / %{name} registrant change"
pending_update_rejected_new_registrant_notification_subject: "Domeeni %{name} registreerija vahetuse taotlus tagasi lükatud / %{name} registrant change declined"
pending_update_request_for_old_registrant_subject: "Kinnitustaotlus domeeni %{name} registreerija vahetuseks / Application for approval for registrant chache of %{name}"
pending_update_notification_for_new_registrant_subject: "Domeeni %{name} registreerija vahetus protseduur on algatatud / %{name} registrant change"
pending_update_rejected_notification_for_new_registrant_subject: "Domeeni %{name} registreerija vahetuse taotlus tagasi lükatud / %{name} registrant change declined"
pending_update_expired_notification_for_new_registrant_subject: "Domeeni %{name} registreerija vahetuse taotlus on tühistatud / %{name} registrant change cancelled"
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.'
domain_pending_deleted_subject: "Kinnitustaotlus domeeni %{name} kustutamiseks .ee registrist / Application for approval for deletion of %{name}"
whois: WHOIS
login_failed_check_id_card: 'Log in failed, check ID card'
@ -874,7 +877,6 @@ en:
no_transfers_found: 'No transfers found'
parameter_value_range_error: 'Parameter value range error: %{key}'
payment_received: 'Payment received'
domain_registrant_updated: 'Domeeni %{name} registreerija vahetus teostatud / Registrant change of %{name} has been finished.'
api_user_not_found: 'API user not found'
domain_already_belongs_to_the_querying_registrar: 'Domain already belongs to the querying registrar'
notes: Notes

View file

@ -1,11 +1,11 @@
require 'rails_helper'
describe DomainMailer do
describe 'registrant change request for old registrant when delivery turned off' do
describe 'pending update request for an old registrant when delivery turned off' do
before :all do
@registrant = Fabricate(:registrant, email: 'test@example.com')
@domain = Fabricate(:domain, registrant: @registrant)
@mail = DomainMailer.pending_update_old_registrant_request(@domain)
@mail = DomainMailer.pending_update_request_for_old_registrant(@domain)
end
it 'should not render email subject' do
@ -25,7 +25,7 @@ describe DomainMailer do
end
end
describe 'registrant change request for old registrant' do
describe 'pending update request for an old registrant' do
before :all do
@registrant = Fabricate(:registrant, email: 'test@example.com')
@new_registrant = Fabricate(:registrant, email: 'test@example.org')
@ -34,7 +34,7 @@ describe DomainMailer do
@domain.registrant_verification_token = '123'
@domain.registrant_verification_asked_at = Time.zone.now
@domain.registrant = @new_registrant
@mail = DomainMailer.pending_update_old_registrant_request(@domain)
@mail = DomainMailer.pending_update_request_for_old_registrant(@domain)
end
it 'should render email subject' do
@ -58,7 +58,7 @@ describe DomainMailer do
end
end
describe 'registrant change notification for new registrant' do
describe 'pending upadte notification for a new registrant' do
before :all do
@registrant = Fabricate(:registrant, email: 'old@example.com')
@new_registrant = Fabricate(:registrant, email: 'new@example.org')
@ -67,7 +67,7 @@ describe DomainMailer do
@domain.registrant_verification_token = '123'
@domain.registrant_verification_asked_at = Time.zone.now
@domain.registrant = @new_registrant
@mail = DomainMailer.pending_update_new_registrant_notification(@domain)
@mail = DomainMailer.pending_update_notification_for_new_registrant(@domain)
end
it 'should render email subject' do
@ -87,6 +87,113 @@ describe DomainMailer do
end
end
describe 'pending update notification for a new registrant' do
before :all do
@registrant = Fabricate(:registrant, email: 'old@example.com')
@new_registrant = Fabricate(:registrant, email: 'new@example.org')
@domain = Fabricate(:domain, registrant: @registrant)
@domain.deliver_emails = true
@domain.registrant_verification_token = '123'
@domain.registrant_verification_asked_at = Time.zone.now
@domain.registrant = @new_registrant
@mail = DomainMailer.pending_update_notification_for_new_registrant(@domain)
end
it 'should render email subject' do
@mail.subject.should =~ /protseduur on algatatud/
end
it 'should have sender email' do
@mail.from.should == ["noreply@internet.ee"]
end
it 'should send confirm email to new registrant email' do
@mail.to.should == ["new@example.org"]
end
it 'should render body' do
@mail.body.encoded.should =~ /vahendusel on algatatud/
end
end
describe 'pending update rejected notification for a new registrant' do
before :all do
@registrant = Fabricate(:registrant, email: 'old@example.com')
@new_registrant = Fabricate(:registrant, email: 'new@example.org')
@domain = Fabricate(:domain, registrant: @registrant)
@domain.deliver_emails = true
@domain.pending_json[:new_registrant_email] = 'new@example.org'
@domain.pending_json[:new_registrant_name] = 'test name'
@mail = DomainMailer.pending_update_rejected_notification_for_new_registrant(@domain)
end
it 'should render email subject' do
@mail.subject.should =~ /vahetuse taotlus tagasi lükatud/
end
it 'should have sender email' do
@mail.from.should == ["noreply@internet.ee"]
end
it 'should send confirm email to new registrant email' do
@mail.to.should == ["new@example.org"]
end
it 'should render body' do
@mail.body.encoded.should =~ /Registrant change was declined/
end
end
describe 'registrant updated notification for a new registrant' do
before :all do
@registrant = Fabricate(:registrant, email: 'test@example.com')
@domain = Fabricate(:domain, registrant: @registrant)
@domain.deliver_emails = true
@mail = DomainMailer.registrant_updated_notification_for_new_registrant(@domain)
end
it 'should render email subject' do
@mail.subject.should =~ /registreerija vahetus teostatud/
end
it 'should have sender email' do
@mail.from.should == ["noreply@internet.ee"]
end
it 'should send to registrant email' do
@mail.to.should == ["test@example.com"]
end
it 'should render body' do
@mail.body.encoded.should =~ /registreerija vahetuse taotlus on kinnitatud/
end
end
describe 'registrant updated notification for a old registrant' do
before :all do
@registrant = Fabricate(:registrant, email: 'test@example.com')
@domain = Fabricate(:domain, registrant: @registrant)
@domain.deliver_emails = true
@mail = DomainMailer.registrant_updated_notification_for_old_registrant(@domain)
end
it 'should render email subject' do
@mail.subject.should =~ /registreerija vahetus teostatud/
end
it 'should have sender email' do
@mail.from.should == ["noreply@internet.ee"]
end
it 'should send to registrant email' do
@mail.to.should == ["test@example.com"]
end
it 'should render body' do
@mail.body.encoded.should =~ /registreerija vahetuse taotlus on kinnitatud/
end
end
describe 'domain pending delete notification when delivery turned off' do
before :all do
@registrant = Fabricate(:registrant, email: 'test@example.com')
@ -141,29 +248,4 @@ describe DomainMailer do
@mail.body.encoded.should =~ %r{registrant\/domain_delete_con} # somehowe delete_confirms not matching
end
end
describe 'registrant successfully changed confirmation' do
before :all do
@registrant = Fabricate(:registrant, email: 'test@example.com')
@domain = Fabricate(:domain, registrant: @registrant)
@domain.deliver_emails = true
@mail = DomainMailer.registrant_updated(@domain)
end
it 'should render email subject' do
@mail.subject.should =~ /registreerija vahetus teostatud/
end
it 'should have sender email' do
@mail.from.should == ["noreply@internet.ee"]
end
it 'should send to registrant email' do
@mail.to.should == ["test@example.com"]
end
it 'should render body' do
@mail.body.encoded.should =~ /registreerija vahetuse taotlus on kinnitatud/
end
end
end