From 5883452fa291b40b88fbafb230dbf8a9f8bcc695 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 28 Jul 2015 18:07:47 +0300 Subject: [PATCH] Added pending delete expired email #2786 --- app/mailers/domain_mailer.rb | 10 +++++++ app/models/domain.rb | 9 +++++- ...nding_delete_expired_notification.html.erb | 15 ++++++++++ ...nding_delete_expired_notification.text.erb | 15 ++++++++++ config/locales/en.yml | 1 + spec/mailers/domain_mailer_spec.rb | 29 ++++++++++++++++++- 6 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 app/views/mailers/domain_mailer/pending_delete_expired_notification.html.erb create mode 100644 app/views/mailers/domain_mailer/pending_delete_expired_notification.text.erb diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index 0e7614199..9b942504b 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -143,4 +143,14 @@ class DomainMailer < ApplicationMailer subject: "#{I18n.t(:pending_delete_rejected_notification_subject, name: @domain.name)} [#{@domain.name}]") end + + def pending_delete_expired_notification(domain) + @domain = domain + # no delivery off control, driggered by cron, no epp request + + return if whitelist_blocked?(@domain.registrant.email) + mail(to: @domain.registrant.email, + subject: "#{I18n.t(:pending_delete_expired_notification_subject, + name: @domain.name)} [#{@domain.name}]") + end end diff --git a/app/models/domain.rb b/app/models/domain.rb index 014faf0c5..b951e7f8e 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -184,6 +184,7 @@ class Domain < ActiveRecord::Base # rubocop: disable Metrics/AbcSize # rubocop: disable Metrics/CyclomaticComplexity + # rubocop: disable Metrics/PerceivedComplexity def clean_expired_pendings STDOUT << "#{Time.zone.now.utc} - Clean expired domain pendings\n" unless Rails.env.test? @@ -198,13 +199,19 @@ class Domain < ActiveRecord::Base next end count += 1 - DomainMailer.pending_update_expired_notification_for_new_registrant(domain).deliver_now + if domain.pending_update? + DomainMailer.pending_update_expired_notification_for_new_registrant(domain).deliver_now + end + if domain.pending_delete? + DomainMailer.pending_delete_expired_notification(domain).deliver_now + end domain.clean_pendings! STDOUT << "#{Time.zone.now.utc} Domain.clean_expired_pendings: ##{domain.id}\n" unless Rails.env.test? end STDOUT << "#{Time.zone.now.utc} - Successfully cancelled #{count} domain pendings\n" unless Rails.env.test? count end + # rubocop: enable Metrics/PerceivedComplexity # rubocop: enable Metrics/AbcSize # rubocop: enable Metrics/CyclomaticComplexity diff --git a/app/views/mailers/domain_mailer/pending_delete_expired_notification.html.erb b/app/views/mailers/domain_mailer/pending_delete_expired_notification.html.erb new file mode 100644 index 000000000..c5ed71c39 --- /dev/null +++ b/app/views/mailers/domain_mailer/pending_delete_expired_notification.html.erb @@ -0,0 +1,15 @@ +Tere, +

+Domeeni <%= @domain.name %> kustutamise taotlust ei kinnitatud tähtaegselt registreerija <%= @domain.registrant_name %> poolt. Domeeni <%= @domain.name %> kustutamine on sellest tulenevalt tühistatud. +

+Lugupidamisega
+Eesti Interneti SA +

+
+

+Hi, +

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

+Best Regards,
+Estonian Internet Foundation diff --git a/app/views/mailers/domain_mailer/pending_delete_expired_notification.text.erb b/app/views/mailers/domain_mailer/pending_delete_expired_notification.text.erb new file mode 100644 index 000000000..5ff510820 --- /dev/null +++ b/app/views/mailers/domain_mailer/pending_delete_expired_notification.text.erb @@ -0,0 +1,15 @@ +Tere, + +Domeeni <%= @domain.name %> kustutamise taotlust ei kinnitatud tähtaegselt registreerija <%= @domain.registrant_name %> poolt. Domeeni <%= @domain.name %> kustutamine on sellest tulenevalt tühistatud. + +Lugupidamisega +Eesti Interneti SA + +-------------------------------------- + +Hi, + +Domain <%= @domain.name %> deletion cancelled. + +Best Regards, +Estonian Internet Foundation diff --git a/config/locales/en.yml b/config/locales/en.yml index 9defb35db..bebe2bef0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -785,6 +785,7 @@ en: 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" 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 44e6d0e42..9d5172352 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -249,7 +249,7 @@ describe DomainMailer do end end - describe 'email pending delete notification' do + describe 'pending delete rejected notification' do before :all do @registrant = Fabricate(:registrant, email: 'test@example.com') @domain = Fabricate(:domain, name: 'delete-pending-rejected.ee', registrant: @registrant) @@ -275,4 +275,31 @@ describe DomainMailer do @mail.body.encoded.should =~ /deletion rejected/ end end + + describe 'pending delete rejected notification' do + before :all do + @registrant = Fabricate(:registrant, email: 'test@example.com') + @domain = Fabricate(:domain, name: 'delete-pending-expired.ee', registrant: @registrant) + @domain.deliver_emails = true + @domain.registrant_verification_token = '123' + @domain.registrant_verification_asked_at = Time.zone.now + @mail = DomainMailer.pending_delete_expired_notification(@domain) + end + + it 'should render email subject' do + @mail.subject.should =~ /deletion cancelled/ + 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 cancelled/ + end + end end