From 6c66ba7383ab19c5323434af34dff6ad4f75eea8 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Fri, 2 Sep 2022 12:39:00 +0300 Subject: [PATCH] returned back missing peace of code from #2349 branch --- app/models/concerns/domain/force_delete.rb | 8 +++++++- app/models/concerns/email_verifable.rb | 4 ++++ app/models/contact.rb | 5 +++++ app/models/domain.rb | 4 ++++ app/presenters/domain_presenter.rb | 4 ++++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/domain/force_delete.rb b/app/models/concerns/domain/force_delete.rb index 7dd309c41f..3fa3bf627a 100644 --- a/app/models/concerns/domain/force_delete.rb +++ b/app/models/concerns/domain/force_delete.rb @@ -34,7 +34,13 @@ def notification_template(explicit: nil) reason = explicit&.downcase return reason if %w[invalid_email invalid_phone].include?(reason) - registrant.org? ? 'legal_person' : 'private_person' + if contact_emails_verification_failed.present? + 'invalid_email' + elsif registrant.org? + 'legal_person' + else + 'private_person' + end end def force_delete_scheduled? diff --git a/app/models/concerns/email_verifable.rb b/app/models/concerns/email_verifable.rb index be9603031b..2d2191d8fb 100644 --- a/app/models/concerns/email_verifable.rb +++ b/app/models/concerns/email_verifable.rb @@ -5,6 +5,10 @@ module EmailVerifable scope :recently_not_validated, -> { where.not(id: ValidationEvent.validated_ids_by(name)) } end + def email_verification_failed? + need_to_start_force_delete? + end + def validate_email_data(level:, count:) validation_events.order(created_at: :desc).limit(count).all? do |event| event.check_level == level.to_s && event.failed? diff --git a/app/models/contact.rb b/app/models/contact.rb index 58c25f7778..e4628e3c06 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -24,6 +24,11 @@ class Contact < ApplicationRecord alias_attribute :kind, :ident_type alias_attribute :copy_from_id, :original_id # Old attribute name; for PaperTrail + scope :email_verification_failed, lambda { + joins('LEFT JOIN email_address_verifications emv ON contacts.email = emv.email') + .where('success = false and verified_at IS NOT NULL') + } + scope :with_different_company_name, (lambda do |company| where("ident = ? AND ident_country_code = 'EE' AND name != ?", company.registration_number, diff --git a/app/models/domain.rb b/app/models/domain.rb index d79da3bc88..a8fc323a0c 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -725,6 +725,10 @@ def domain_name DNS::DomainName.new(name) end + def contact_emails_verification_failed + contacts.select(&:email_verification_failed?)&.map(&:email)&.uniq + end + def as_csv_row [ name, diff --git a/app/presenters/domain_presenter.rb b/app/presenters/domain_presenter.rb index f19bbb62ff..8128817420 100644 --- a/app/presenters/domain_presenter.rb +++ b/app/presenters/domain_presenter.rb @@ -52,6 +52,10 @@ def force_delete_toggle_btn end end + def contact_emails_verification_failed + domain.contact_emails_verification_failed.join(', ') + end + def remove_registry_lock_btn return unless domain.locked_by_registrant?