Add forceDelete on email_verification failed

This commit is contained in:
Alex Sherman 2021-03-17 15:11:20 +05:00
parent 4522e4427e
commit a8e3d67556
4 changed files with 14 additions and 7 deletions

View file

@ -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

View file

@ -45,6 +45,6 @@ class BouncedMailAddress < ApplicationRecord
end
def force_delete_from_bounce
Domains::ForceDeleteBounce::Base.run(bounced_mail_address: self)
Domains::ForceDeleteEmail::Base.run(email: email)
end
end

View file

@ -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)
@ -40,6 +41,12 @@ class EmailAddressVerification < ApplicationRecord
success
end
def check_force_delete
return unless failed?
Domains::ForceDeleteEmail::Base.run(email: email)
end
def verify
validation_request = Truemail.validate(email)

View file

@ -344,10 +344,10 @@ class ForceDeleteTest < ActionMailer::TestCase
Truemail.configure.default_validation_type = :regex
contact = @domain.admin_contacts.first
contact.update(email: 'some@strangesentence@internet.ee')
contact.update_attribute(:email, 'some@strangesentence@internet.ee')
contact.email_verification.verify
assert contact.email_verification_failed?
assert contact.invalid?
@domain.reload