Skip to content

Commit

Permalink
Add forceDelete on email_verification failed
Browse files Browse the repository at this point in the history
  • Loading branch information
yulgolem committed Mar 17, 2021
1 parent 97c295a commit c2d6158
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module Domains
module ForceDeleteBounce
module ForceDeleteEmail
class Base < ActiveInteraction::Base
object :bounced_mail_address,
class: BouncedMailAddress,
string :email,
description: 'Bounced email to set ForceDelete from'

def execute
email = bounced_mail_address.email
domain_contacts = Contact.where(email: email).map(&:domain_contacts).flatten
domains = domain_contacts.map(&:domain).flatten
domains.each do |domain|
next if domain.force_delete_scheduled?

domain.schedule_force_delete(type: :soft,
notify_by_email: true, reason: 'invalid_email')
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/bounced_mail_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ def self.ses_configured?
end

def force_delete_from_bounce
Domains::ForceDeleteBounce::Base.run(bounced_mail_address: self)
Domains::ForceDeleteEmail::Base.run(email: email)
end
end
7 changes: 7 additions & 0 deletions app/models/email_address_verification.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class EmailAddressVerification < ApplicationRecord
RECENTLY_VERIFIED_PERIOD = 1.month
after_save :check_force_delete

scope :not_verified_recently, lambda {
where('verified_at IS NULL or verified_at < ?', verification_period)
Expand Down Expand Up @@ -40,6 +41,12 @@ def verified?
success
end

def check_force_delete
return unless failed?

Domains::ForceDeleteEmail::Base.run(email: email)
end

def verify
validation_request = Truemail.validate(email)

Expand Down
4 changes: 2 additions & 2 deletions test/models/domain/force_delete_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@ def test_schedules_force_delete_invalid_contact
Truemail.configure.default_validation_type = :regex

contact = @domain.admin_contacts.first
contact.update(email: 'some@[email protected]')
contact.update_attribute(:email, 'some@[email protected]')
contact.email_verification.verify

assert contact.email_verification_failed?
assert contact.invalid?

@domain.reload

Expand Down

0 comments on commit c2d6158

Please sign in to comment.