Story#117124725 - generate emails of apply_pending_update! only when everything is ok

This commit is contained in:
Vladimir Krylov 2016-04-08 14:58:56 +03:00
parent 1d5a79f406
commit a091c62264
8 changed files with 108 additions and 103 deletions

View file

@ -9,12 +9,34 @@ class DomainMailer < ApplicationMailer
compose_from(params)
end
def registrant_updated_notification_for_new_registrant(params)
compose_from(params)
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)
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(params)
compose_from(params)
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)
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_update_rejected_notification_for_new_registrant(params)

View file

@ -20,28 +20,7 @@ class DomainMailModel
domain_info
compose
end
def registrant_updated_notification_for_new_registrant
registrant
subject(:registrant_updated_notification_for_new_registrant_subject)
domain_info
compose
end
def registrant_updated_notification_for_old_registrant
registrant_pending
registrant_old
subject(:registrant_updated_notification_for_old_registrant_subject)
new_registrant = Registrant.find @domain.pending_json['new_registrant_id']
@params[:registrant_name] = new_registrant.name
@params[:registrant_ident] = new_registrant.ident
@params[:registrant_priv] = new_registrant.priv?
@params[:registrant_email] = new_registrant.email
@params[:registrant_street] = new_registrant.street
@params[:registrant_city] = new_registrant.city
@params[:registrant_country] = new_registrant.country.name
compose
end
def pending_update_rejected_notification_for_new_registrant
registrant_pending

View file

@ -525,19 +525,21 @@ 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)
::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)
clean_pendings!
send_mail :registrant_updated_notification_for_new_registrant
WhoisRecord.find_by(domain_id: id).save # need to reload model
save! # for notification if everything fails
WhoisRecord.find_by(domain_id: id).save # need to reload model
DomainMailer.registrant_updated_notification_for_old_registrant(id, old_registrant_id, registrant_id, should_deliver)
DomainMailer.registrant_updated_notification_for_new_registrant(id, old_registrant_id, registrant_id, should_deliver)
true
end

View file

@ -1,18 +1,18 @@
Tere,
<br><br>
Domeeni <%= @params[:name] %> registreerija vahetuse taotlus on kinnitatud ning andmed registris uuendatud.
Domeeni <%= @domain.name %> registreerija vahetuse taotlus on kinnitatud ning andmed registris uuendatud.
<br><br>
Uue registreerija andmed:<br>
Nimi: <%= @params[:registrant_name] %><br>
<% if @params[:registrant_priv] %>
Isikukood: <%= @params[:registrant_ident] %><br>
Nimi: <%= @new_registrant.name %><br>
<% if @new_registrant.priv? %>
Isikukood: <%= @new_registrant.ident %><br>
<% else %>
Äriregistrikood: <%= @params[:registrant_ident] %><br>
Äriregistrikood: <%= @new_registrant.ident %><br>
<% end %>
Epost: <%= @params[:registrant_email] %><br>
Tänav: <%= @params[:registrant_street] %><br>
Linn: <%= @params[:registrant_city] %><br>
Riik: <%= @params[:registrant_country] %>
Epost: <%= @new_registrant.email %><br>
Tänav: <%= @new_registrant.street %><br>
Linn: <%= @new_registrant.city %><br>
Riik: <%= @new_registrant.country.name %>
<br><br>
Lugupidamisega<br>
Eesti Interneti SA
@ -21,19 +21,19 @@ Eesti Interneti SA
<br><br>
Hi,
<br><br>
Process for changing registrant of the domain <%= @params[:name] %> has been approved and the data in the registry is updated.
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: <%= @params[:registrant_name] %><br>
<% if @params[:registrant_priv] %>
Personal code: <%= @params[:registrant_ident] %><br>
Name: <%= @new_registrant.name %><br>
<% if @new_registrant.priv? %>
Personal code: <%= @new_registrant.ident %><br>
<% else %>
Business Registry code: <%= @params[:registrant_ident] %><br>
Business Registry code: <%= @new_registrant.ident %><br>
<% end %>
E-mail: <%= @params[:registrant_email] %><br>
Street: <%= @params[:registrant_street] %><br>
City: <%= @params[:registrant_city] %><br>
Country: <%= @params[:registrant_country] %>
E-mail: <%= @new_registrant.email %><br>
Street: <%= @new_registrant.street %><br>
City: <%= @new_registrant.city %><br>
Country: <%= @new_registrant.country.name %>
<br><br>
Best Regards,<br>
Estonian Internet Foundation

View file

@ -1,18 +1,19 @@
Tere,
Domeeni <%= @params[:name] %> registreerija vahetuse taotlus on kinnitatud ning andmed registris uuendatud.
Domeeni <%= @domain.name %> registreerija vahetuse taotlus on kinnitatud ning andmed registris uuendatud.
Uue registreerija andmed:
Nimi: <%= @params[:registrant_name] %>
<% if @params[:registrant_priv] %>
Isikukood: <%= @params[:registrant_ident] %>
Nimi: <%= @new_registrant.name %>
<% if @new_registrant.priv? %>
Isikukood: <%= @new_registrant.ident %>
<% else %>
Äriregistrikood: <%= @params[:registrant_ident] %>
Äriregistrikood: <%= @new_registrant.ident %>
<% end %>
Epost: <%= @params[:registrant_email] %>
Tänav: <%= @params[:registrant_street] %>
Linn: <%= @params[:registrant_city] %>
Riik: <%= @params[:registrant_country] %>
Epost: <%= @new_registrant.email %>
Tänav: <%= @new_registrant.street %>
Linn: <%= @new_registrant.city %>
Riik: <%= @new_registrant.country.name %>
Lugupidamisega
Eesti Interneti SA
@ -21,19 +22,20 @@ Eesti Interneti SA
Hi,
Process for changing registrant of the domain <%= @params[:name] %> has been approved and the data in the registry is updated.
Process for changing registrant of the domain <%= @domain.name %> has been approved and the data in the registry is updated.
New registrant:
Name: <%= @params[:registrant_name] %>
<% if @params[:registrant_priv] %>
Personal code: <%= @params[:registrant_ident] %>
Name: <%= @new_registrant.name %>
<% if @new_registrant.priv? %>
Personal code: <%= @new_registrant.ident %>
<% else %>
Business Registry code: <%= @params[:registrant_ident] %>
Business Registry code: <%= @new_registrant.ident %>
<% end %>
E-mail: <%= @params[:registrant_email] %>
Street: <%= @params[:registrant_street] %>
City: <%= @params[:registrant_city] %>
Country: <%= @params[:registrant_country] %>
E-mail: <%= @new_registrant.email %>
Street: <%= @new_registrant.street %>
City: <%= @new_registrant.city %>
Country: <%= @new_registrant.country.name %>
Best Regards,
Estonian Internet Foundation

View file

@ -1,18 +1,18 @@
Tere,
<br><br>
Domeeni <%= @params[:name] %> registreerija vahetuse taotlus on kinnitatud ning andmed registris uuendatud.
Domeeni <%= @domain.name %> registreerija vahetuse taotlus on kinnitatud ning andmed registris uuendatud.
<br><br>
Uue registreerija andmed:<br>
Nimi: <%= @params[:new_registrant_name] %><br>
<% if @params[:registrant_priv] %>
Isikukood: <%= @params[:registrant_ident] %><br>
Nimi: <%= @new_registrant.name %><br>
<% if @new_registrant.priv? %>
Isikukood: <%= @new_registrant.ident %><br>
<% else %>
Äriregistrikood: <%= @params[:registrant_ident] %><br>
Äriregistrikood: <%= @new_registrant.ident %><br>
<% end %>
Epost: <%= @params[:registrant_email] %><br>
Tänav: <%= @params[:registrant_street] %><br>
Linn: <%= @params[:registrant_city] %><br>
Riik: <%= @params[:registrant_country] %>
Epost: <%= @new_registrant.email %><br>
Tänav: <%= @new_registrant.street %><br>
Linn: <%= @new_registrant.city %><br>
Riik: <%= @new_registrant.country.name %>
<br><br>
Lugupidamisega<br>
Eesti Interneti SA
@ -21,19 +21,19 @@ Eesti Interneti SA
<br><br>
Hi,
<br><br>
Process for changing registrant of the domain <%= @params[:name] %> has been approved and the data in the registry is updated.
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: <%= @params[:new_registrant_name] %><br>
<% if @params[:registrant_priv] %>
Personal code: <%= @params[:registrant_ident] %><br>
Name: <%= @new_registrant.name %><br>
<% if @new_registrant.priv? %>
Personal code: <%= @new_registrant.ident %><br>
<% else %>
Business Registry code: <%= @params[:registrant_ident] %><br>
Business Registry code: <%= @new_registrant.ident %><br>
<% end %>
E-mail: <%= @params[:registrant_email] %><br>
Street: <%= @params[:registrant_street] %><br>
City: <%= @params[:registrant_city] %><br>
Country: <%= @params[:registrant_country] %>
E-mail: <%= @new_registrant.email %><br>
Street: <%= @new_registrant.street %><br>
City: <%= @new_registrant.city %><br>
Country: <%= @new_registrant.country.name %>
<br><br>
Best Regards,<br>
Estonian Internet Foundation

View file

@ -1,19 +1,19 @@
Tere,
Domeeni <%= @params[:name] %> registreerija vahetuse taotlus on kinnitatud ning andmed registris uuendatud.
Domeeni <%= @domain.name %> registreerija vahetuse taotlus on kinnitatud ning andmed registris uuendatud.
Uue registreerija andmed:
Nimi: <%= @params[:new_registrant_name] %>
Nimi: <%= @new_registrant.name %>
<% if @params[:registrant_priv] %>
Isikukood: <%= @params[:registrant_ident] %>
<% if @new_registrant.priv? %>
Isikukood: <%= @new_registrant.ident %>
<% else %>
Äriregistrikood: <%= @params[:registrant_ident] %>
Äriregistrikood: <%= @new_registrant.ident %>
<% end %>
Epost: <%= @params[:registrant_email] %>
Tänav: <%= @params[:registrant_street] %>
Linn: <%= @params[:registrant_city] %>
Riik: <%= @params[:registrant_country] %>
Epost: <%= @new_registrant.email %>
Tänav: <%= @new_registrant.street %>
Linn: <%= @new_registrant.city %>
Riik: <%= @new_registrant.country.name %>
Lugupidamisega
Eesti Interneti SA
@ -22,20 +22,20 @@ Eesti Interneti SA
Hi,
Process for changing registrant of the domain <%= @params[:name] %> has been approved and the data in the registry is updated.
Process for changing registrant of the domain <%= @domain.name %> has been approved and the data in the registry is updated.
New registrant:
Name: <%= @params[:new_registrant_name] %>
Name: <%= @new_registrant.name %>
<% if @params[:registrant_priv] %>
Personal code: <%= @params[:registrant_ident] %>
<% if @new_registrant.priv? %>
Personal code: <%= @new_registrant.ident %>
<% else %>
Business Registry code: <%= @params[:registrant_ident] %>
Business Registry code: <%= @new_registrant.ident %>
<% end %>
E-mail: <%= @params[:registrant_email] %>
Street: <%= @params[:registrant_street] %>
City: <%= @params[:registrant_city] %>
Country: <%= @params[:registrant_country] %>
E-mail: <%= @new_registrant.email %>
Street: <%= @new_registrant.street %>
City: <%= @new_registrant.city %>
Country: <%= @new_registrant.country.name %>
Best Regards,
Estonian Internet Foundation

View file

@ -153,7 +153,7 @@ describe DomainMailer 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.id, deliver_emails)
@mail = DomainMailer.registrant_updated_notification_for_new_registrant(@domain.id, @registrant.id, @registrant.id, deliver_emails)
end
it 'should render email subject' do
@ -178,7 +178,7 @@ describe DomainMailer 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.id, deliver_emails)
@mail = DomainMailer.registrant_updated_notification_for_old_registrant(@domain.id, @registrant.id, @registrant.id, deliver_emails)
end
it 'should render email subject' do