Add extended registrar's info to "pending_deleted" mailer

#180
This commit is contained in:
Artur Beljajev 2016-11-03 20:16:01 +02:00
parent e52c747946
commit bebd49e5f4
11 changed files with 190 additions and 36 deletions

View file

@ -47,29 +47,13 @@ class DomainMailer < ApplicationMailer
compose_from(params)
end
def pending_deleted(domain_id, old_registrant_id, should_deliver)
@domain = Domain.find_by(id: domain_id)
@old_registrant = Registrant.find(old_registrant_id)
return unless @domain
return if delivery_off?(@domain, should_deliver)
def pending_deleted(domain:, registrant:)
@domain = DomainPresenter.new(domain: domain, view: view_context)
@registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context)
@verification_url = registrant_domain_delete_confirm_url(domain, token: domain.registrant_verification_token)
if @domain.registrant_verification_token.blank?
logger.warn "EMAIL NOT DELIVERED: registrant_verification_token is missing for #{@domain.name}"
return
end
if @domain.registrant_verification_asked_at.blank?
logger.warn "EMAIL NOT DELIVERED: registrant_verification_asked_at is missing for #{@domain.name}"
return
end
confirm_path = "#{ENV['registrant_url']}/registrant/domain_delete_confirms"
@verification_url = "#{confirm_path}/#{@domain.id}?token=#{@domain.registrant_verification_token}"
return if whitelist_blocked?(@old_registrant.email)
mail(to: format(@old_registrant.email),
subject: "#{I18n.t(:domain_pending_deleted_subject,
name: @domain.name)} [#{@domain.name}]")
subject = default_i18n_subject(domain_name: domain.name)
mail(to: registrant.email, subject: subject)
end
def pending_delete_rejected_notification(domain_id, should_deliver)

View file

@ -439,7 +439,8 @@ class Domain < ActiveRecord::Base
pending_delete_confirmation!
save(validate: false) # should check if this did succeed
DomainMailer.pending_deleted(id, registrant_id_was, deliver_emails).deliver
previous_registrant = Registrant.find(registrant_id_was)
DomainMailer.pending_deleted(domain: self, registrant: previous_registrant).deliver
end
def cancel_pending_delete

View file

@ -1,6 +1,14 @@
Tere
<br><br>
Registrisse laekus taotlus domeeni <%= @domain.name %> kustutamiseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja <%= @domain.registrar_name %> poole.
Registrisse laekus taotlus domeeni <%= @domain.name %> kustutamiseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole:
<p>
<%= @registrar.name %><br>
Email: <%= @registrar.email %><br>
Telefon: <%= @registrar.phone %><br>
Veebileht: <%= @registrar.url %>
</p>
<br><br>
Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan.
<br><br>
@ -14,7 +22,15 @@ Eesti Interneti Sihtasutus
<br><br>
Hi,
<br><br>
Application for deletion of your domain <%= @domain.name %> has been filed. Please make sure that the application is correct. Incase of problems please contact your registrar <%= @domain.registrar_name %>.
Application for deletion of your domain <%= @domain.name %> has been filed. Please make sure that the application is correct. Incase of problems please contact your registrar:
<p>
<%= @registrar.name %><br>
Email: <%= @registrar.email %><br>
Phone: <%= @registrar.phone %><br>
Website: <%= @registrar.url %>
</p>
<br><br>
To confirm the update please visit this website, once again review the data and press approve:<br>
<%= link_to @verification_url, @verification_url %>

View file

@ -1,11 +1,16 @@
Tere
Registrisse laekus taotlus domeeni <%= @domain.name %> kustutamiseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja <%= @domain.registrar_name %> poole.
Registrisse laekus taotlus domeeni <%= @domain.name %> kustutamiseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole:
<%= @registrar.name %>
Email: <%= @registrar.email %>
Telefon: <%= @registrar.phone %>
Veebileht: <%= @registrar.url %>
Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan.
Taotlus on aktiivne <%= Setting.expire_pending_confirmation %> tundi ja lükatakse automaatselt tagasi kui te seda enne ise ei kinnita või tagasi lükka.
<%= link_to @verification_url, @verification_url %>
<%= @verification_url %>
Lugupidamisega
Eesti Interneti Sihtasutus
@ -14,10 +19,15 @@ Eesti Interneti Sihtasutus
Hi,
Application for deletion of your domain <%= @domain.name %> has been filed. Please make sure that the application is correct. Incase of problems please contact your registrar <%= @domain.registrar_name %>.
Application for deletion of your domain <%= @domain.name %> has been filed. Please make sure that the application is correct. In case of problems please contact your registrar:
<%= @registrar.name %>
Email: <%= @registrar.email %>
Phone: <%= @registrar.phone %>
Website: <%= @registrar.url %>
To confirm the update please visit this website, once again review the data and press approve:
<%= link_to @verification_url, @verification_url %>
<%= @verification_url %>
The application will remain in pending status for <%= Setting.expire_pending_confirmation %> hrs and will be automatically rejected if it is not approved nor rejected before.

View file

@ -803,7 +803,6 @@ en:
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}"
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"

View file

@ -4,3 +4,5 @@ en:
subject: The %{domain_name} domain has expired
force_delete:
subject: Kustutusmenetluse teade
pending_deleted:
subject: Kinnitustaotlus domeeni %{domain_name} kustutamiseks .ee registrist / Application for approval for deletion of %{domain_name}

View file

@ -1,6 +1,45 @@
require 'rails_helper'
RSpec.describe DomainMailer do
describe '#pending_deleted' do
let(:domain) { instance_spy(Domain, name: 'test.com') }
let(:registrant) { instance_spy(Registrant, email: 'registrant@test.com') }
let(:domain_presenter) { instance_spy(DomainPresenter) }
let(:registrar_presenter) { instance_spy(RegistrarPresenter) }
subject(:message) { described_class.pending_deleted(domain: domain, registrant: registrant) }
before :example do
expect(DomainPresenter).to receive(:new).and_return(domain_presenter)
expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter)
end
it 'has sender' do
expect(message.from).to eq(['noreply@internet.ee'])
end
it 'has registrant email as a recipient' do
expect(message.to).to match_array(['registrant@test.com'])
end
it 'has subject' do
subject = 'Kinnitustaotlus domeeni test.com kustutamiseks .ee registrist' \
' / Application for approval for deletion of test.com'
expect(message.subject).to eq(subject)
end
it 'has confirmation url' do
allow(domain).to receive(:id).and_return(1)
expect(domain).to receive(:registrant_verification_token).and_return('test')
url = registrant_domain_delete_confirm_url(domain, token: 'test')
expect(message.body.parts.first.decoded).to include(url)
end
it 'sends message' do
expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end
describe '#force_delete' do
let(:domain) { instance_spy(Domain, name: 'test.com') }
let(:domain_presenter) { instance_spy(DomainPresenter) }
@ -15,18 +54,15 @@ RSpec.describe DomainMailer do
end
it 'has sender' do
message.deliver!
expect(message.from).to eq(['noreply@internet.ee'])
end
it 'has recipient' do
expect(domain).to receive(:primary_contact_emails).and_return(['recipient@test.com'])
message.deliver!
expect(message.to).to match_array(['recipient@test.com'])
end
it 'has valid subject' do
message.deliver!
expect(message.subject).to eq('Kustutusmenetluse teade')
end
@ -47,18 +83,15 @@ RSpec.describe DomainMailer do
end
it 'has sender' do
message.deliver!
expect(message.from).to eq(['noreply@internet.ee'])
end
it 'has recipient' do
expect(domain).to receive(:primary_contact_emails).and_return(['recipient@test.com'])
message.deliver!
expect(message.to).to match_array(['recipient@test.com'])
end
it 'has valid subject' do
message.deliver!
expect(message.subject).to eq('The test.com domain has expired')
end

View file

@ -801,4 +801,22 @@ RSpec.describe Domain, db: false do
))
end
end
describe '#pending_delete!' do
let(:domain) { described_class.new }
let(:previous_registrant) { instance_double(Registrant) }
let(:message) { instance_double(Mail::Message) }
before :example do
expect(Registrant).to receive(:find).and_return(previous_registrant)
allow(domain).to receive(:registrant_verification_asked?).and_return(true)
allow(domain).to receive(:save)
end
it 'sends notification email' do
expect(DomainMailer).to receive(:pending_deleted).with(domain: domain, registrant: previous_registrant).and_return(message)
expect(message).to receive(:deliver)
domain.pending_delete!
end
end
end

View file

@ -0,0 +1,9 @@
require 'rails_helper'
RSpec.describe Registrant::DomainDeleteConfirmsController do
describe 'routing' do
it 'routes to #show' do
expect(get: '/registrant/domain_delete_confirms/1').to route_to('registrant/domain_delete_confirms#show', id: '1')
end
end
end

View file

@ -0,0 +1,41 @@
require 'rails_helper'
RSpec.describe 'mailers/domain_mailer/pending_deleted.html.erb' do
let(:domain) { instance_spy(DomainPresenter) }
let(:registrar) { instance_spy(RegistrarPresenter) }
let(:lang_count) { 2 }
before :example do
assign(:domain, domain)
assign(:registrar, registrar)
assign(:verification_url, 'test url')
end
it 'has domain name' do
mention_count = 1 * lang_count
expect(domain).to receive(:name).exactly(mention_count).times.and_return('test domain name')
render
expect(rendered).to have_text('test domain name', count: mention_count)
end
it 'has verification url' do
mention_count = 1 * lang_count
render
expect(rendered).to have_text('test url', count: mention_count)
end
registrar_attributes = %i(
name
email
phone
url
)
registrar_attributes.each do |attr_name|
it "has registrar #{attr_name}" do
expect(registrar).to receive(attr_name).exactly(lang_count).times.and_return("test registrar #{attr_name}")
render
expect(rendered).to have_text("test registrar #{attr_name}", count: lang_count)
end
end
end

View file

@ -0,0 +1,41 @@
require 'rails_helper'
RSpec.describe 'mailers/domain_mailer/pending_deleted.text.erb' do
let(:domain) { instance_spy(DomainPresenter) }
let(:registrar) { instance_spy(RegistrarPresenter) }
let(:lang_count) { 2 }
before :example do
assign(:domain, domain)
assign(:registrar, registrar)
end
it 'has domain name' do
mention_count = 1 * lang_count
expect(domain).to receive(:name).exactly(mention_count).times.and_return('test domain name')
render
expect(rendered).to have_text('test domain name', count: mention_count)
end
it 'has verification url' do
mention_count = 1 * lang_count
assign(:verification_url, 'test url')
render
expect(rendered).to have_text('test url', count: mention_count)
end
registrar_attributes = %i(
name
email
phone
url
)
registrar_attributes.each do |attr_name|
it "has registrar #{attr_name}" do
expect(registrar).to receive(attr_name).exactly(lang_count).times.and_return("test registrar #{attr_name}")
render
expect(rendered).to have_text("test registrar #{attr_name}", count: lang_count)
end
end
end