From acb9f2ee087cf4d31891fdb00a1602ee5bc62498 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 17:49:35 +0300 Subject: [PATCH] Added domain delete rejection notification #2786 --- app/jobs/domain_delete_confirm_job.rb | 1 + app/mailers/domain_mailer.rb | 20 ++++++++++++++ ...ding_delete_rejected_notification.html.erb | 15 +++++++++++ ...ding_delete_rejected_notification.text.erb | 15 +++++++++++ config/locales/en.yml | 1 + spec/mailers/domain_mailer_spec.rb | 27 +++++++++++++++++++ 6 files changed, 79 insertions(+) create mode 100644 app/views/mailers/domain_mailer/pending_delete_rejected_notification.html.erb create mode 100644 app/views/mailers/domain_mailer/pending_delete_rejected_notification.text.erb diff --git a/app/jobs/domain_delete_confirm_job.rb b/app/jobs/domain_delete_confirm_job.rb index 90a76e47b..153ef7012 100644 --- a/app/jobs/domain_delete_confirm_job.rb +++ b/app/jobs/domain_delete_confirm_job.rb @@ -8,6 +8,7 @@ class DomainDeleteConfirmJob < Que::Job domain.apply_pending_delete! domain.clean_pendings! when RegistrantVerification::REJECTED + DomainMailer.pending_delete_rejected_notification(domain).deliver_now domain.clean_pendings! end destroy # it's best to destroy the job in the same transaction diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index eb724a222..0e7614199 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -123,4 +123,24 @@ class DomainMailer < ApplicationMailer subject: "#{I18n.t(:domain_pending_deleted_subject, name: @domain.name)} [#{@domain.name}]") end + + def pending_delete_rejected_notification(domain) + @domain = domain + # no delivery off control, driggered by que, no epp request + + 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 + + return if whitelist_blocked?(@domain.registrant.email) + mail(to: @domain.registrant.email, + subject: "#{I18n.t(:pending_delete_rejected_notification_subject, + name: @domain.name)} [#{@domain.name}]") + end end diff --git a/app/views/mailers/domain_mailer/pending_delete_rejected_notification.html.erb b/app/views/mailers/domain_mailer/pending_delete_rejected_notification.html.erb new file mode 100644 index 000000000..e89a02327 --- /dev/null +++ b/app/views/mailers/domain_mailer/pending_delete_rejected_notification.html.erb @@ -0,0 +1,15 @@ +Tere, +

+Domeeni <%= @domain.name %> kustutamise taotlus on registreerija <%= @domain.registrar_name %> poolt tagasi lükatud. +

+Lugupidamisega
+Eesti Interneti SA +

+
+

+Hi, +

+Domain <%= @domain.name %> deletion rejected. +

+Best Regards,
+Estonian Internet Foundation diff --git a/app/views/mailers/domain_mailer/pending_delete_rejected_notification.text.erb b/app/views/mailers/domain_mailer/pending_delete_rejected_notification.text.erb new file mode 100644 index 000000000..d3600a3c7 --- /dev/null +++ b/app/views/mailers/domain_mailer/pending_delete_rejected_notification.text.erb @@ -0,0 +1,15 @@ +Tere, + +Domeeni <%= @domain.name %> kustutamise taotlus on registreerija <%= @domain.registrar_name %> poolt tagasi lükatud. + +Lugupidamisega +Eesti Interneti SA + +-------------------------------------- + +Hi, + +Domain <%= @domain.name %> deletion rejected. + +Best Regards, +Estonian Internet Foundation diff --git a/config/locales/en.yml b/config/locales/en.yml index 98f759105..9defb35db 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -784,6 +784,7 @@ en: 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" whois: WHOIS login_failed_check_id_card: 'Log in failed, check ID card' not_valid_domain_verification_title: Domain verification not available diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb index f1765d308..44e6d0e42 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -248,4 +248,31 @@ describe DomainMailer do @mail.body.encoded.should =~ %r{registrant\/domain_delete_con} # somehowe delete_confirms not matching end end + + describe 'email pending delete notification' do + before :all do + @registrant = Fabricate(:registrant, email: 'test@example.com') + @domain = Fabricate(:domain, name: 'delete-pending-rejected.ee', registrant: @registrant) + @domain.deliver_emails = true + @domain.registrant_verification_token = '123' + @domain.registrant_verification_asked_at = Time.zone.now + @mail = DomainMailer.pending_delete_rejected_notification(@domain) + end + + it 'should render email subject' do + @mail.subject.should =~ /kustutamise taotlus tagasi lükatud/ + end + + it 'should have sender email' do + @mail.from.should == ["noreply@internet.ee"] + end + + it 'should send confirm email to old registrant email' do + @mail.to.should == ["test@example.com"] + end + + it 'should render body' do + @mail.body.encoded.should =~ /deletion rejected/ + end + end end