Skip to content

Commit

Permalink
Merge pull request #2187 from internetee/2185-mail-validation-event-t…
Browse files Browse the repository at this point in the history
…hreshold-not-applied

2185 mail validation event threshold not applied
  • Loading branch information
vohmar authored Oct 22, 2021
2 parents 8eea84d + 1048fbd commit 38ceccf
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
10 changes: 8 additions & 2 deletions app/interactions/domains/force_delete_lift/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ def template_of_invalid_email?(domain)
end

def contact_emails_valid?(domain)
domain.contacts.all(&:need_to_lift_force_delete?) &&
domain.registrant.need_to_lift_force_delete?
flag = nil

domain.contacts.each do |c|
flag = c.need_to_lift_force_delete?
return flag unless flag
end

flag && domain.registrant.need_to_lift_force_delete?
end

def bounces_absent?(domain)
Expand Down
14 changes: 11 additions & 3 deletions app/models/concerns/email_verifable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ def email_verification_failed?
need_to_start_force_delete?
end

def validate_email_data(level:, count:)
validation_events.recent.order(id: :desc).limit(count).all? do |event|
event.check_level == level.to_s && event.failed?
end
end

def need_to_start_force_delete?
ValidationEvent::INVALID_EVENTS_COUNT_BY_LEVEL.any? do |level, count|
validation_events.recent.order(id: :desc).limit(count).all? do |event|
event.check_level == level.to_s && event.failed?
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
end
end

false
end

def need_to_lift_force_delete?
Expand Down
4 changes: 2 additions & 2 deletions lib/tasks/verify_email.rake
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ def prepare_contacts(options)
if options[:domain_name].present?
contacts_by_domain(options[:domain_name])
else
Contact.recently_not_validated
Contact.all
end
end

def contacts_by_domain(domain_name)
domain = ::Domain.find_by(name: domain_name)
return unless domain

domain.contacts.recently_not_validated
domain.contacts
end

def opts_hash
Expand Down
3 changes: 2 additions & 1 deletion test/models/bounced_mail_address_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ def test_email_with_bounce_considered_nonverified
BouncedMailAddress.record(sns_bounce_payload)
bounced_mail = BouncedMailAddress.last
registrant = domains(:shop).registrant

registrant.verify_email(check_level: 'smtp')

assert_equal registrant.email, bounced_mail.email
assert registrant.email_verification_failed?
end
Expand Down
22 changes: 21 additions & 1 deletion test/models/validation_event_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def test_if_fd_need_to_be_set_if_invalid_email

contact = @domain.admin_contacts.first
contact.update_attribute(:email, email)
contact.verify_email
(ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD).times do
contact.verify_email
end
contact.reload

refute contact.validation_events.last.success?
Expand All @@ -42,6 +44,24 @@ def test_if_fd_need_to_be_lifted_if_email_fixed
assert contact.validation_events.last.success?
end

def test_fd_didnt_set_if_mx_interation_less_then_value
@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 = '[email protected]'
contact = @domain.admin_contacts.first
contact.update_attribute(:email, email)
(ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD - 1).times do
contact.verify_email(check_level: 'mx')
end
contact.reload

refute contact.validation_events.limit(ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD)
.any?(&:success?)
assert_not contact.need_to_start_force_delete?
end

def test_if_fd_need_to_be_set_if_invalid_mx
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
assert_not @domain.force_delete_scheduled?
Expand Down

0 comments on commit 38ceccf

Please sign in to comment.