From aa34959ae5afa3e803a454a0244c3d327903a0e8 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Mon, 22 Mar 2021 14:21:08 +0500 Subject: [PATCH] Add notification on autoFD --- app/interactions/domains/force_delete/base.rb | 3 +++ .../domains/force_delete/notify_registrar.rb | 12 ++++++++++++ .../domains/force_delete_email/base.rb | 4 +++- app/models/concerns/domain/force_delete.rb | 4 ++-- config/locales/en.yml | 1 + test/models/domain/force_delete_test.rb | 18 +++++++++++++++--- 6 files changed, 36 insertions(+), 6 deletions(-) diff --git a/app/interactions/domains/force_delete/base.rb b/app/interactions/domains/force_delete/base.rb index d4ad2b8202..712d0c08e5 100644 --- a/app/interactions/domains/force_delete/base.rb +++ b/app/interactions/domains/force_delete/base.rb @@ -13,6 +13,9 @@ class Base < ActiveInteraction::Base string :reason, default: nil, description: 'Which mail template to use explicitly' + string :email, + default: nil, + description: 'Possible invalid email to notify on' validates :type, inclusion: { in: %i[fast_track soft] } end diff --git a/app/interactions/domains/force_delete/notify_registrar.rb b/app/interactions/domains/force_delete/notify_registrar.rb index 522502640b..e4aa48976a 100644 --- a/app/interactions/domains/force_delete/notify_registrar.rb +++ b/app/interactions/domains/force_delete/notify_registrar.rb @@ -2,11 +2,23 @@ module Domains module ForceDelete class NotifyRegistrar < Base def execute + email.present? ? notify_with_email : notify_without_email + end + + def notify_without_email domain.registrar.notifications.create!(text: I18n.t('force_delete_set_on_domain', domain_name: domain.name, outzone_date: domain.outzone_date, purge_date: domain.purge_date)) end + + def notify_with_email + domain.registrar.notifications.create!(text: I18n.t('force_delete_auto_email', + domain_name: domain.name, + outzone_date: domain.outzone_date, + purge_date: domain.purge_date, + email: email)) + end end end end diff --git a/app/interactions/domains/force_delete_email/base.rb b/app/interactions/domains/force_delete_email/base.rb index 7b7e56e5e0..3b93108feb 100644 --- a/app/interactions/domains/force_delete_email/base.rb +++ b/app/interactions/domains/force_delete_email/base.rb @@ -15,7 +15,9 @@ def execute next if domain.force_delete_scheduled? domain.schedule_force_delete(type: :soft, - notify_by_email: true, reason: 'invalid_email') + notify_by_email: true, + reason: 'invalid_email', + email: email) end end end diff --git a/app/models/concerns/domain/force_delete.rb b/app/models/concerns/domain/force_delete.rb index ca13eb5d12..bc89022d0a 100644 --- a/app/models/concerns/domain/force_delete.rb +++ b/app/models/concerns/domain/force_delete.rb @@ -45,9 +45,9 @@ def force_delete_scheduled? statuses.include?(DomainStatus::FORCE_DELETE) end - def schedule_force_delete(type: :fast_track, notify_by_email: false, reason: nil) + def schedule_force_delete(type: :fast_track, notify_by_email: false, reason: nil, email: nil) Domains::ForceDelete::SetForceDelete.run(domain: self, type: type, reason: reason, - notify_by_email: notify_by_email) + notify_by_email: notify_by_email, email: email) end def cancel_force_delete diff --git a/config/locales/en.yml b/config/locales/en.yml index 22f29a6e32..97c968996e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -626,6 +626,7 @@ en: created_at_until: 'Created at until' is_registrant: 'Is registrant' force_delete_set_on_domain: 'Force delete set on domain %{domain_name}. Outzone date: %{outzone_date}. Purge date: %{purge_date}' + force_delete_auto_email: 'Force delete set on domain %{domain_name}. Outzone date: %{outzone_date}. Purge date: %{purge_date}. Invalid email: %{email}' grace_period_started_domain: 'For domain %{domain_name} started 45-days redemption grace period, ForceDelete will be in effect from %{date}' force_delete_cancelled: 'Force delete is cancelled on domain %{domain_name}' contact_is_not_valid: 'Contact %{value} is not valid, please fix the invalid contact' diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index 68b0df87ac..837ad3adca 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -325,8 +325,10 @@ def test_schedules_force_delete_after_bounce @domain.update(valid_to: Time.zone.parse('2012-08-05')) assert_not @domain.force_delete_scheduled? travel_to Time.zone.parse('2010-07-05') + email = @domain.admin_contacts.first.email + asserted_text = "Invalid email: #{email}" - prepare_bounced_email_address(@domain.admin_contacts.first.email) + prepare_bounced_email_address(email) @domain.reload @@ -334,14 +336,18 @@ def test_schedules_force_delete_after_bounce assert_equal 'invalid_email', @domain.template_name assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date + notification = @domain.registrar.notifications.last + assert notification.text.include? asserted_text end def test_schedules_force_delete_after_registrant_bounce @domain.update(valid_to: Time.zone.parse('2012-08-05')) assert_not @domain.force_delete_scheduled? travel_to Time.zone.parse('2010-07-05') + email = @domain.registrant.email + asserted_text = "Invalid email: #{email}" - prepare_bounced_email_address(@domain.registrant.email) + prepare_bounced_email_address(email) @domain.reload @@ -349,17 +355,21 @@ def test_schedules_force_delete_after_registrant_bounce assert_equal 'invalid_email', @domain.template_name assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date + notification = @domain.registrar.notifications.last + assert notification.text.include? asserted_text end def test_schedules_force_delete_invalid_contact @domain.update(valid_to: Time.zone.parse('2012-08-05')) assert_not @domain.force_delete_scheduled? travel_to Time.zone.parse('2010-07-05') + email = 'some@strangesentence@internet.ee' + asserted_text = "Invalid email: #{email}" Truemail.configure.default_validation_type = :regex contact = @domain.admin_contacts.first - contact.update_attribute(:email, 'some@strangesentence@internet.ee') + contact.update_attribute(:email, email) contact.email_verification.verify assert contact.email_verification_failed? @@ -370,6 +380,8 @@ def test_schedules_force_delete_invalid_contact assert_equal 'invalid_email', @domain.template_name assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date + notification = @domain.registrar.notifications.last + assert notification.text.include? asserted_text end def prepare_bounced_email_address(email)