From e320a7ced1abcb8b4249e3e1e459ff13e65aaa8a Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Mon, 11 Apr 2022 15:18:11 +0300 Subject: [PATCH] fix poll message spam after validation email --- .../domains/force_delete/notify_registrar.rb | 26 ++++++++++++------- .../domains/force_delete_email/base.rb | 17 +++++++----- test/models/domain/force_delete_test.rb | 2 +- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/app/interactions/domains/force_delete/notify_registrar.rb b/app/interactions/domains/force_delete/notify_registrar.rb index e4aa48976a..25d59bf294 100644 --- a/app/interactions/domains/force_delete/notify_registrar.rb +++ b/app/interactions/domains/force_delete/notify_registrar.rb @@ -6,18 +6,26 @@ def execute 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)) + template = I18n.t('force_delete_set_on_domain', + domain_name: domain.name, + outzone_date: domain.outzone_date, + purge_date: domain.purge_date) + + return if domain.registrar.notifications.last.text.include? template + + domain.registrar.notifications.create!(text: template) 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)) + template = I18n.t('force_delete_auto_email', + domain_name: domain.name, + outzone_date: domain.outzone_date, + purge_date: domain.purge_date, + email: email) + + return if domain.registrar.notifications.last.text.include? template + + domain.registrar.notifications.create!(text: template) end end end diff --git a/app/interactions/domains/force_delete_email/base.rb b/app/interactions/domains/force_delete_email/base.rb index 04e7dde5de..d75749b507 100644 --- a/app/interactions/domains/force_delete_email/base.rb +++ b/app/interactions/domains/force_delete_email/base.rb @@ -31,18 +31,21 @@ def expired_or_hold_domains_exists?(domains) def before_execute_force_delete(domain) if domain.force_delete_scheduled? && !domain.status_notes[DomainStatus::FORCE_DELETE].nil? added_additional_email_into_notes(domain) - notify_registrar(domain) else process_force_delete(domain) end end def notify_registrar(domain) - 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: domain.status_notes[DomainStatus::FORCE_DELETE])) + template = I18n.t('force_delete_auto_email', + domain_name: domain.name, + outzone_date: domain.outzone_date, + purge_date: domain.purge_date, + email: domain.status_notes[DomainStatus::FORCE_DELETE]) + + return if domain.registrar.notifications.last.text.include? template + + domain.registrar.notifications.create!(text: template) end def process_force_delete(domain) @@ -56,6 +59,8 @@ def process_force_delete(domain) def added_additional_email_into_notes(domain) return if domain.status_notes[DomainStatus::FORCE_DELETE].include? email + # notify_registrar(domain) + domain.status_notes[DomainStatus::FORCE_DELETE].concat(" #{email}") domain.save(validate: false) end diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index 974c445e62..b80313ca52 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -437,7 +437,7 @@ def test_add_invalid_email_to_domain_status_notes assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], invalid_emails notification = domain.registrar.notifications.last - assert notification.text.include? asserted_text + assert_not notification.text.include? asserted_text end def test_remove_invalid_email_from_domain_status_notes