mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 06:34:46 +02:00
Merge pull request #1903 from internetee/1898-lift-fd-if-contact-fixed
Remove ForceDelete if all domain emails are correct
This commit is contained in:
commit
fa9a4e2872
5 changed files with 119 additions and 5 deletions
47
app/interactions/domains/force_delete_lift/base.rb
Normal file
47
app/interactions/domains/force_delete_lift/base.rb
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
module Domains
|
||||||
|
module ForceDeleteLift
|
||||||
|
class Base < ActiveInteraction::Base
|
||||||
|
object :domain,
|
||||||
|
class: Domain,
|
||||||
|
description: 'Domain to check if ForceDelete needs to be listed'
|
||||||
|
|
||||||
|
def execute
|
||||||
|
prepare_email_verifications(domain)
|
||||||
|
|
||||||
|
lift_force_delete(domain) if force_delete_condition(domain)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def lift_force_delete(domain)
|
||||||
|
domain.cancel_force_delete
|
||||||
|
end
|
||||||
|
|
||||||
|
def force_delete_condition(domain)
|
||||||
|
domain.force_delete_scheduled? &&
|
||||||
|
template_of_invalid_email?(domain) &&
|
||||||
|
contact_emails_valid?(domain) &&
|
||||||
|
bounces_absent?(domain)
|
||||||
|
end
|
||||||
|
|
||||||
|
def template_of_invalid_email?(domain)
|
||||||
|
domain.template_name == 'invalid_email'
|
||||||
|
end
|
||||||
|
|
||||||
|
def contact_emails_valid?(domain)
|
||||||
|
domain.contacts.all? { |contact| contact.email_verification.verified? } &&
|
||||||
|
domain.registrant.email_verification.verified?
|
||||||
|
end
|
||||||
|
|
||||||
|
def prepare_email_verifications(domain)
|
||||||
|
domain.registrant.email_verification.verify
|
||||||
|
domain.contacts.each { |contact| contact.email_verification.verify }
|
||||||
|
end
|
||||||
|
|
||||||
|
def bounces_absent?(domain)
|
||||||
|
emails = domain.all_related_emails
|
||||||
|
BouncedMailAddress.where(email: emails).empty?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
12
app/jobs/check_force_delete_lift.rb
Normal file
12
app/jobs/check_force_delete_lift.rb
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
class CheckForceDeleteLift < ApplicationJob
|
||||||
|
queue_as :default
|
||||||
|
|
||||||
|
def perform
|
||||||
|
domains = Domain.where("force_delete_data->'template_name' = ?", 'invalid_email')
|
||||||
|
.where("force_delete_data->'force_delete_type' = ?", 'soft')
|
||||||
|
|
||||||
|
domains.each do |domain|
|
||||||
|
Domains::ForceDeleteLift::Base.run(domain: domain)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -2,16 +2,14 @@ module EmailVerifable
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
def email_verification
|
def email_verification
|
||||||
@email_verification ||= EmailAddressVerification.find_or_create_by(email: unicode_email,
|
EmailAddressVerification.find_or_create_by(email: unicode_email, domain: domain(email))
|
||||||
domain: domain(email))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def billing_email_verification
|
def billing_email_verification
|
||||||
return unless attribute_names.include?('billing_email')
|
return unless attribute_names.include?('billing_email')
|
||||||
|
|
||||||
@billing_email_verification ||= EmailAddressVerification
|
EmailAddressVerification.find_or_create_by(email: unicode_billing_email,
|
||||||
.find_or_create_by(email: unicode_billing_email,
|
domain: domain(billing_email))
|
||||||
domain: domain(billing_email))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def email_verification_failed?
|
def email_verification_failed?
|
||||||
|
|
|
@ -668,6 +668,10 @@ class Domain < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def all_related_emails
|
||||||
|
(admin_contacts.emails + tech_contacts.emails + [registrant.email]).uniq
|
||||||
|
end
|
||||||
|
|
||||||
def force_delete_contact_emails
|
def force_delete_contact_emails
|
||||||
(primary_contact_emails + tech_contacts.pluck(:email) +
|
(primary_contact_emails + tech_contacts.pluck(:email) +
|
||||||
["info@#{name}", "#{prepared_domain_name}@#{name}"]).uniq
|
["info@#{name}", "#{prepared_domain_name}@#{name}"]).uniq
|
||||||
|
|
|
@ -384,6 +384,59 @@ class ForceDeleteTest < ActionMailer::TestCase
|
||||||
assert notification.text.include? asserted_text
|
assert notification.text.include? asserted_text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_lifts_force_delete_if_contact_fixed
|
||||||
|
@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'
|
||||||
|
|
||||||
|
Truemail.configure.default_validation_type = :regex
|
||||||
|
|
||||||
|
contact = @domain.admin_contacts.first
|
||||||
|
contact.update_attribute(:email, email)
|
||||||
|
contact.email_verification.verify
|
||||||
|
|
||||||
|
assert contact.email_verification_failed?
|
||||||
|
|
||||||
|
@domain.reload
|
||||||
|
|
||||||
|
assert @domain.force_delete_scheduled?
|
||||||
|
contact.update_attribute(:email, 'aaa@bbb.com')
|
||||||
|
contact.email_verification.verify
|
||||||
|
|
||||||
|
assert_not contact.email_verification_failed?
|
||||||
|
CheckForceDeleteLift.perform_now
|
||||||
|
|
||||||
|
@domain.reload
|
||||||
|
assert_not @domain.force_delete_scheduled?
|
||||||
|
end
|
||||||
|
def test_lifts_force_delete_after_bounce_changes
|
||||||
|
@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(email)
|
||||||
|
|
||||||
|
@domain.reload
|
||||||
|
|
||||||
|
assert @domain.force_delete_scheduled?
|
||||||
|
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
|
||||||
|
|
||||||
|
@domain.registrant.update(email: 'aaa@bbb.com')
|
||||||
|
@domain.registrant.email_verification.verify
|
||||||
|
assert_not @domain.registrant.email_verification_failed?
|
||||||
|
CheckForceDeleteLift.perform_now
|
||||||
|
|
||||||
|
@domain.reload
|
||||||
|
assert_not @domain.force_delete_scheduled?
|
||||||
|
end
|
||||||
|
|
||||||
def prepare_bounced_email_address(email)
|
def prepare_bounced_email_address(email)
|
||||||
@bounced_mail = BouncedMailAddress.new
|
@bounced_mail = BouncedMailAddress.new
|
||||||
@bounced_mail.email = email
|
@bounced_mail.email = email
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue