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
def related_domain_descriptions
ActiveSupport::Deprecation.warn('Use #domain_names_with_roles')
@desc = {}
registrant_domains.each do |dom|
@ -598,4 +600,24 @@ class Contact < ActiveRecord::Base
def ident_country
Country.new(ident_country_code)
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

View file

@ -8,6 +8,7 @@ class RegistrantPresenter
:reg_no,
:street, :city, :state, :zip, :country,
:ident_country,
:used?,
to: :registrant
def initialize(registrant:, view:)
@ -23,6 +24,17 @@ class RegistrantPresenter
registrant.ident_country.translation(locale)
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
attr_reader :registrant

View file

@ -1,46 +1,49 @@
<%
contact = RegistrantPresenter.new(registrant: @contact, view: self)
registrar = RegistrarPresenter.new(registrar: @contact.registrar, view: self)
%>
Tere <%= @contact.name %>
Tere <%= contact.name %>
<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>
uus aadress: <%= @contact.email %>
uus aadress: <%= contact.email %>
<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>
<% if @contact.related_domain_descriptions.present? %>
<% if contact.used? %>
Muudatusega seotud domeenid:<br>
<% @contact.related_domain_descriptions.each do |domain, desc| %>
<%= domain %> (<%= desc.map { |d| t(d, locale: :et) }.join(', ') %>)<br>
<% end %>
<%= contact.domain_names_with_roles(locale: :et, line_break: '<br>') %>
<% end %>
<br>
<br><br>
Kontaktandmed:<br>
<%= render 'mailers/shared/registrant/registrant.et.html', registrant: contact, with_phone: true %>
<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>
Eesti Interneti Sihtasutus
<br><br>
<hr>
<br><br>
Hi <%= @contact.name %>
Hi <%= contact.name %>
<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>
new address: <%= @contact.email %>
new address: <%= contact.email %>
<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>
<% if @contact.related_domain_descriptions.present? %>
<% if contact.used? %>
Domains affected by this update:<br>
<% @contact.related_domain_descriptions.each do |domain, desc| %>
<%= domain %> (<%= desc.map { |d| t(d, locale: :en) }.join(', ') %>)<br>
<% end %>
<%= contact.domain_names_with_roles(line_break: '<br>') %>
<% end %>
<br>
<br><br>
Contact information:<br>
<%= render 'mailers/shared/registrant/registrant.en.html', registrant: contact, with_phone: true %>
<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>
Estonian Internet Foundation

View file

@ -1,46 +1,49 @@
<%
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 %>
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:
<% @contact.related_domain_descriptions.each do |domain, desc| %>
<%= domain %> (<%= desc.map { |d| t(d, locale: :et) }.join(', ') %>)
<% end %>
<%= contact.domain_names_with_roles(locale: :et) %>
<% end %>
Kontaktandmed:
<%= 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
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 %>
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:
<% @contact.related_domain_descriptions.each do |domain, desc| %>
<%= domain %> (<%= desc.map { |d| t(d, locale: :en) }.join(', ') %>)
<% end %>
<%= contact.domain_names_with_roles %>
<% end %>
Contact information:
<%= 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,
Estonian Internet Foundation

View file

@ -1,5 +1,10 @@
en:
activerecord:
models:
# Used in ContactMailer
registrant: Registrant
admin_domain_contact: Administrative contact
tech_domain_contact: Technical contact
errors:
models:
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'
password: 'Parool'
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'))
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

View file

@ -40,6 +40,21 @@ RSpec.describe RegistrantPresenter do
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(
name
ident
@ -52,6 +67,7 @@ RSpec.describe RegistrantPresenter do
zip
id_code
reg_no
used?
)
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