Improve ContactMailer

- Add detailed registrar info
- Refactor contact domain list
- Fix english translation

#480
This commit is contained in:
Artur Beljajev 2017-06-08 02:06:00 +03:00
parent 37004c24ba
commit 49552fc67e
11 changed files with 220 additions and 37 deletions

View file

@ -429,6 +429,8 @@ class Contact < ActiveRecord::Base
end end
def related_domain_descriptions def related_domain_descriptions
ActiveSupport::Deprecation.warn('Use #domain_names_with_roles')
@desc = {} @desc = {}
registrant_domains.each do |dom| registrant_domains.each do |dom|
@ -598,4 +600,24 @@ class Contact < ActiveRecord::Base
def ident_country def ident_country
Country.new(ident_country_code) Country.new(ident_country_code)
end end
def used?
registrant_domains.any? || domain_contacts.any?
end
def domain_names_with_roles
domain_names = {}
registrant_domains.pluck(:name).each do |domain_name|
domain_names[domain_name] ||= Set.new
domain_names[domain_name] << Registrant.name.underscore.to_sym
end
domain_contacts.each do |domain_contact|
domain_names[domain_contact.domain.name] ||= Set.new
domain_names[domain_contact.domain.name] << domain_contact.type.underscore.to_sym
end
domain_names
end
end end

View file

@ -8,6 +8,7 @@ class RegistrantPresenter
:reg_no, :reg_no,
:street, :city, :state, :zip, :country, :street, :city, :state, :zip, :country,
:ident_country, :ident_country,
:used?,
to: :registrant to: :registrant
def initialize(registrant:, view:) def initialize(registrant:, view:)
@ -23,6 +24,17 @@ class RegistrantPresenter
registrant.ident_country.translation(locale) registrant.ident_country.translation(locale)
end end
def domain_names_with_roles(locale: I18n.locale, line_break: "\n")
lines = []
registrant.domain_names_with_roles.each do |domain_name, roles|
lines << "#{domain_name} (#{roles.map { |role| role.to_s.classify.constantize.model_name.human(locale: locale) }
.join(', ')})"
end
lines.join(line_break)
end
private private
attr_reader :registrant attr_reader :registrant

View file

@ -1,46 +1,49 @@
<% <%
contact = RegistrantPresenter.new(registrant: @contact, view: self) contact = RegistrantPresenter.new(registrant: @contact, view: self)
registrar = RegistrarPresenter.new(registrar: @contact.registrar, view: self)
%> %>
Tere <%= @contact.name %> Tere <%= contact.name %>
<br><br> <br><br>
Kontakti <%= @contact.name %> e-posti aadress on muudetud<br> Kontakti <%= contact.name %> e-posti aadress on muudetud<br>
endine aadress: <%= @old_email %><br> endine aadress: <%= @old_email %><br>
uus aadress: <%= @contact.email %> uus aadress: <%= contact.email %>
<br><br> <br><br>
E-posti aadressile saadetakse domeeni toimingutega seotud infot, sealhulgas kinnitustaotlused omanikuvahetuse ja domeeni kustutamise korral. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja <%= @contact.registrar.name %> poole. E-posti aadressile saadetakse domeeni toimingutega seotud infot, sealhulgas kinnitustaotlused omanikuvahetuse ja domeeni kustutamise korral.
<br><br> <br><br>
<% if @contact.related_domain_descriptions.present? %> <% if contact.used? %>
Muudatusega seotud domeenid:<br> Muudatusega seotud domeenid:<br>
<% @contact.related_domain_descriptions.each do |domain, desc| %> <%= contact.domain_names_with_roles(locale: :et, line_break: '<br>') %>
<%= domain %> (<%= desc.map { |d| t(d, locale: :et) }.join(', ') %>)<br>
<% end %>
<% end %> <% end %>
<br> <br><br>
Kontaktandmed:<br> Kontaktandmed:<br>
<%= render 'mailers/shared/registrant/registrant.et.html', registrant: contact, with_phone: true %> <%= render 'mailers/shared/registrant/registrant.et.html', registrant: contact, with_phone: true %>
<br><br> <br><br>
Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole:
<%= render 'mailers/shared/registrar/registrar.et.html', registrar: registrar %>
<br><br>
Lugupidamisega<br> Lugupidamisega<br>
Eesti Interneti Sihtasutus Eesti Interneti Sihtasutus
<br><br> <br><br>
<hr> <hr>
<br><br> <br><br>
Hi <%= @contact.name %> Hi <%= contact.name %>
<br><br> <br><br>
E-mail address of <%= @contact.name %> has been changed<br> E-mail address of <%= contact.name %> has been changed<br>
previous address: <%= @old_email %><br> previous address: <%= @old_email %><br>
new address: <%= @contact.email %> new address: <%= contact.email %>
<br><br> <br><br>
E-mail addresses are used to send important information regarding your registered domains including applications for approval of registrant change and domain deletion. Please make sure that the update and contact information are correct. Incase of problems please turn to your registrar. Your registrar is <%= @contact.registrar.name %> E-mail addresses are used to send important information regarding your registered domains including applications for approval of registrant change and domain deletion. Please make sure that the update and contact information are correct.
<br><br> <br><br>
<% if @contact.related_domain_descriptions.present? %> <% if contact.used? %>
Domains affected by this update:<br> Domains affected by this update:<br>
<% @contact.related_domain_descriptions.each do |domain, desc| %> <%= contact.domain_names_with_roles(line_break: '<br>') %>
<%= domain %> (<%= desc.map { |d| t(d, locale: :en) }.join(', ') %>)<br>
<% end %>
<% end %> <% end %>
<br> <br><br>
Contact information:<br> Contact information:<br>
<%= render 'mailers/shared/registrant/registrant.en.html', registrant: contact, with_phone: true %> <%= render 'mailers/shared/registrant/registrant.en.html', registrant: contact, with_phone: true %>
<br><br> <br><br>
In case of problems please turn to your registrar:
<%= render 'mailers/shared/registrar/registrar.en.html', registrar: registrar %>
<br><br>
Best Regards,<br> Best Regards,<br>
Estonian Internet Foundation Estonian Internet Foundation

View file

@ -1,46 +1,49 @@
<% <%
contact = RegistrantPresenter.new(registrant: @contact, view: self) contact = RegistrantPresenter.new(registrant: @contact, view: self)
registrar = RegistrarPresenter.new(registrar: @contact.registrar, view: self)
%> %>
Tere <%= @contact.name %> Tere <%= contact.name %>
Kontakti <%= @contact.name %> e-posti aadress on muudetud Kontakti <%= contact.name %> e-posti aadress on muudetud
endine aadress: <%= @old_email %> endine aadress: <%= @old_email %>
uus aadress: <%= @contact.email %> uus aadress: <%= contact.email %>
E-posti aadressile saadetakse domeeni toimingutega seotud infot, sealhulgas kinnitustaotlused omanikuvahetuse ja domeeni kustutamise korral. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja <%= @contact.registrar.name %> poole. E-posti aadressile saadetakse domeeni toimingutega seotud infot, sealhulgas kinnitustaotlused omanikuvahetuse ja domeeni kustutamise korral.
<% if @contact.related_domain_descriptions.present? %> <% if contact.used? %>
Muudatusega seotud domeenid: Muudatusega seotud domeenid:
<% @contact.related_domain_descriptions.each do |domain, desc| %> <%= contact.domain_names_with_roles(locale: :et) %>
<%= domain %> (<%= desc.map { |d| t(d, locale: :et) }.join(', ') %>)
<% end %>
<% end %> <% end %>
Kontaktandmed: Kontaktandmed:
<%= render 'mailers/shared/registrant/registrant.et.text', registrant: contact, with_phone: true %> <%= render 'mailers/shared/registrant/registrant.et.text', registrant: contact, with_phone: true %>
Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole:
<%= render 'mailers/shared/registrar/registrar.et.text', registrar: registrar %>
Lugupidamisega Lugupidamisega
Eesti Interneti Sihtasutus Eesti Interneti Sihtasutus
---------------------------------------------------------------------------------- ----------------------------------------------------------------------------------
Hi <%= @contact.name %> Hi <%= contact.name %>
E-mail address of <%= @contact.name %> has been changed E-mail address of <%= contact.name %> has been changed
previous address: <%= @old_email %> previous address: <%= @old_email %>
new address: <%= @contact.email %> new address: <%= contact.email %>
E-mail addresses are used to send important information regarding your registered domains including applications for approval of registrant change and domain deletion. Please make sure that the update and contact information are correct. Incase of problems please turn to your registrar. Your registrar is <%= @contact.registrar.name %> E-mail addresses are used to send important information regarding your registered domains including applications for approval of registrant change and domain deletion. Please make sure that the update and contact information are correct.
<% if @contact.related_domain_descriptions.present? %> <% if contact.used? %>
Domains affected by this update: Domains affected by this update:
<% @contact.related_domain_descriptions.each do |domain, desc| %> <%= contact.domain_names_with_roles %>
<%= domain %> (<%= desc.map { |d| t(d, locale: :en) }.join(', ') %>)
<% end %>
<% end %> <% end %>
Contact information: Contact information:
<%= render 'mailers/shared/registrant/registrant.en.text', registrant: contact, with_phone: true %> <%= render 'mailers/shared/registrant/registrant.en.text', registrant: contact, with_phone: true %>
In case of problems please turn to your registrar:
<%= render 'mailers/shared/registrar/registrar.en.text', registrar: registrar %>
Best Regards, Best Regards,
Estonian Internet Foundation Estonian Internet Foundation

View file

@ -1,5 +1,10 @@
en: en:
activerecord: activerecord:
models:
# Used in ContactMailer
registrant: Registrant
admin_domain_contact: Administrative contact
tech_domain_contact: Technical contact
errors: errors:
models: models:
contact: contact:

View file

@ -0,0 +1,7 @@
et:
activerecord:
models:
# Used in ContactMailer
registrant: Registreerija
admin_domain_contact: Halduskontakt
tech_domain_contact: Tehniline kontakt

View file

@ -2,6 +2,3 @@ et:
username: 'Kasutajanimi' username: 'Kasutajanimi'
password: 'Parool' password: 'Parool'
log_in: 'Logi sisse' log_in: 'Logi sisse'
registrant: registreerija
tech: tehniline kontakt
admin: halduskontakt

View file

@ -541,4 +541,58 @@ RSpec.describe Contact do
expect(contact.ident_country).to eq(Country.new('US')) expect(contact.ident_country).to eq(Country.new('US'))
end end
end end
describe '#used?' do
context 'when used as registrant' do
let(:registrant) { create(:registrant) }
before :example do
create(:domain, registrant: registrant)
registrant.reload
end
specify { expect(registrant).to be_used }
end
context 'when used as contact' do
let(:contact) { create(:contact) }
before :example do
domain = create(:domain)
domain.admin_domain_contacts << create(:admin_domain_contact, contact: contact)
contact.reload
end
specify { expect(contact).to be_used }
end
context 'when not used' do
let(:contact) { create(:contact) }
specify { expect(contact).to_not be_used }
end
end
describe '#domain_names_with_roles' do
let(:contact) { create(:registrant) }
subject(:domain_names) { contact.domain_names_with_roles }
it 'returns associated domains with roles' do
domain = create(:domain, registrant: contact, name: 'test.com')
domain.admin_domain_contacts << create(:admin_domain_contact, contact: contact)
domain.tech_domain_contacts << create(:tech_domain_contact, contact: contact)
contact.reload
expect(domain_names).to eq({ 'test.com' => %i[registrant admin_domain_contact tech_domain_contact].to_set })
end
it 'returns unique roles' do
domain = create(:domain, name: 'test.com')
2.times { domain.admin_domain_contacts << create(:admin_domain_contact, contact: contact) }
contact.reload
expect(domain_names).to eq({ 'test.com' => %i[admin_domain_contact].to_set })
end
end
end end

View file

@ -40,6 +40,21 @@ RSpec.describe RegistrantPresenter do
end end
end end
describe '#domain_names_with_roles' do
before :example do
roles = %i[registrant admin_domain_contact tech_domain_contact]
allow(registrant).to receive(:domain_names_with_roles)
.and_return({ 'test.com' => roles,
'test.org' => %i[registrant] })
end
it 'returns domain names with unique roles in current locale by default' do
text = "test.com (Registrant, Administrative contact, Technical contact)" \
"\ntest.org (Registrant)"
expect(presenter.domain_names_with_roles).to eq(text)
end
end
registrant_delegatable_attributes = %i( registrant_delegatable_attributes = %i(
name name
ident ident
@ -52,6 +67,7 @@ RSpec.describe RegistrantPresenter do
zip zip
id_code id_code
reg_no reg_no
used?
) )
registrant_delegatable_attributes.each do |attr_name| registrant_delegatable_attributes.each do |attr_name|

View file

@ -0,0 +1,32 @@
require 'rails_helper'
RSpec.describe 'mailers/contact_mailer/email_updated.html.erb' do
let(:contact) { instance_spy(Contact) }
let(:contact_presenter) { instance_spy(RegistrantPresenter) }
let(:registrar_presenter) { instance_spy(RegistrarPresenter) }
before :example do
allow(RegistrantPresenter).to receive(:new).and_return(contact_presenter)
allow(RegistrarPresenter).to receive(:new).and_return(registrar_presenter)
assign(:contact, contact)
assign(:old_email, 'test@test.com')
stub_template 'mailers/shared/registrant/_registrant.et.html' => ''
stub_template 'mailers/shared/registrant/_registrant.en.html' => ''
stub_template 'mailers/shared/registrar/_registrar.et.html' => ''
stub_template 'mailers/shared/registrar/_registrar.en.html' => ''
end
it 'has affected domain list in estonian' do
expect(contact_presenter).to receive(:domain_names_with_roles).with(locale: :et, line_break: '<br>').and_return('test domain list et')
render
expect(rendered).to have_text('test domain list et')
end
it 'has affected domain list in english' do
expect(contact_presenter).to receive(:domain_names_with_roles).with(line_break: '<br>').and_return('test domain list en')
render
expect(rendered).to have_text('test domain list en')
end
end

View file

@ -0,0 +1,32 @@
require 'rails_helper'
RSpec.describe 'mailers/contact_mailer/email_updated.text.erb' do
let(:contact) { instance_spy(Contact) }
let(:contact_presenter) { instance_spy(RegistrantPresenter) }
let(:registrar_presenter) { instance_spy(RegistrarPresenter) }
before :example do
allow(RegistrantPresenter).to receive(:new).and_return(contact_presenter)
allow(RegistrarPresenter).to receive(:new).and_return(registrar_presenter)
assign(:contact, contact)
assign(:old_email, 'test@test.com')
stub_template 'mailers/shared/registrant/_registrant.et.text' => ''
stub_template 'mailers/shared/registrant/_registrant.en.text' => ''
stub_template 'mailers/shared/registrar/_registrar.et.text' => ''
stub_template 'mailers/shared/registrar/_registrar.en.text' => ''
end
it 'has affected domain list in estonian' do
expect(contact_presenter).to receive(:domain_names_with_roles).with(locale: :et).and_return('test domain list et')
render
expect(rendered).to have_text('test domain list et')
end
it 'has affected domain list in english' do
expect(contact_presenter).to receive(:domain_names_with_roles).and_return('test domain list en')
render
expect(rendered).to have_text('test domain list en')
end
end