mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 14:44:47 +02:00
added lift feature, fixed fd issues, changes mx to 2
This commit is contained in:
parent
5ea5dd7197
commit
8524503582
4 changed files with 52 additions and 6 deletions
|
@ -16,13 +16,14 @@ module EmailVerifable
|
|||
end
|
||||
|
||||
def need_to_start_force_delete?
|
||||
flag = false
|
||||
ValidationEvent::INVALID_EVENTS_COUNT_BY_LEVEL.each do |level, count|
|
||||
if validation_events.recent.count >= count && validate_email_data(level: level, count: count)
|
||||
return true
|
||||
flag = true
|
||||
end
|
||||
end
|
||||
|
||||
false
|
||||
flag
|
||||
end
|
||||
|
||||
def need_to_lift_force_delete?
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
# For email_validation event kind also check_level (regex/mx/smtp) is stored in the event_data
|
||||
class ValidationEvent < ApplicationRecord
|
||||
enum event_type: ValidationEvent::EventType::TYPES, _suffix: true
|
||||
VALIDATION_PERIOD = 45.minutes.freeze
|
||||
VALIDATION_PERIOD = 30.minutes.freeze
|
||||
VALID_CHECK_LEVELS = %w[regex mx smtp].freeze
|
||||
VALID_EVENTS_COUNT_THRESHOLD = 5
|
||||
|
||||
|
@ -26,7 +26,7 @@ class ValidationEvent < ApplicationRecord
|
|||
|
||||
belongs_to :validation_eventable, polymorphic: true
|
||||
|
||||
scope :recent, -> { where('created_at > ?', Time.zone.now - VALIDATION_PERIOD) }
|
||||
scope :recent, -> { where('created_at < ?', Time.zone.now - VALIDATION_PERIOD) }
|
||||
scope :successful, -> { where(success: true) }
|
||||
scope :failed, -> { where(success: false) }
|
||||
scope :regex, -> { where('event_data @> ?', { 'check_level': 'regex' }.to_json) }
|
||||
|
@ -69,5 +69,15 @@ class ValidationEvent < ApplicationRecord
|
|||
Domains::ForceDeleteEmail::Base.run(email: email)
|
||||
end
|
||||
|
||||
def lift_force_delete; end
|
||||
def lift_force_delete
|
||||
domain_contacts = Contact.where(email: email).map(&:domain_contacts).flatten
|
||||
registrant_ids = Registrant.where(email: email).pluck(:id)
|
||||
|
||||
domains = domain_contacts.map(&:domain).flatten +
|
||||
Domain.where(registrant_id: registrant_ids)
|
||||
|
||||
domains.each do |domain|
|
||||
Domains::ForceDeleteLift::Base.run(domain: domain)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -67,9 +67,14 @@ def failed_contacts
|
|||
failed_validations_ids = ValidationEvent.failed.pluck(:validation_eventable_id)
|
||||
contacts = Contact.where(id: failed_validations_ids)
|
||||
contacts.each do |contact|
|
||||
failed_contacts << contact unless contact.validation_events.last.success
|
||||
failed_contacts << contact unless contact.validation_events.order(created_at: :asc).last.success
|
||||
end
|
||||
|
||||
# failed_contacts.each do |f|
|
||||
# p "+++++++++"
|
||||
# p f
|
||||
# p "+++++++++"
|
||||
# end
|
||||
failed_contacts
|
||||
end
|
||||
|
||||
|
|
|
@ -120,6 +120,36 @@ class VerifyEmailTaskTest < ActiveJob::TestCase
|
|||
assert contact.domains.last.force_delete_scheduled?
|
||||
end
|
||||
|
||||
def test_change_failed_email_to_another_faield_email_shouldnt_to_remove_fd
|
||||
assert_equal ValidationEvent.count, 0
|
||||
run_task
|
||||
assert_equal Contact.count, 9
|
||||
assert_equal ValidationEvent.count, 8 # Contact has duplicate email and it is skip
|
||||
|
||||
contact = contacts(:john)
|
||||
v = ValidationEvent.find_by(validation_eventable_id: contact.id)
|
||||
v.update!(success: false)
|
||||
|
||||
4.times do
|
||||
contact.validation_events << v.dup
|
||||
end
|
||||
|
||||
run_task
|
||||
assert_equal ValidationEvent.all.count, 13
|
||||
|
||||
assert contact.domains.last.force_delete_scheduled?
|
||||
|
||||
contact.email = "another@inbox.txt"
|
||||
contact.save
|
||||
contact.reload
|
||||
v = ValidationEvent.find_by(validation_eventable_id: contact.id)
|
||||
v.update!(success: false)
|
||||
|
||||
run_task
|
||||
|
||||
assert contact.domains.last.force_delete_scheduled?
|
||||
end
|
||||
|
||||
def test_tasks_verifies_emails
|
||||
capture_io { run_task }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue