mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 16:32:04 +02:00
Fixed FD test for new behaviour
This commit is contained in:
parent
90f862aa8f
commit
d48b0f4401
6 changed files with 193 additions and 34 deletions
|
@ -10,6 +10,18 @@ class ValidationEvent < ApplicationRecord
|
|||
VALID_CHECK_LEVELS = %w[regex mx smtp].freeze
|
||||
VALID_EVENTS_COUNT_THRESHOLD = 5
|
||||
|
||||
INVALID_EVENTS_COUNT_BY_LEVEL = {
|
||||
regex: 1,
|
||||
mx: 5,
|
||||
smtp: 1,
|
||||
}.freeze
|
||||
|
||||
REDEEM_EVENTS_COUNT_BY_LEVEL = {
|
||||
regex: 1,
|
||||
mx: 1,
|
||||
smtp: 1,
|
||||
}.freeze
|
||||
|
||||
store_accessor :event_data, :errors, :check_level, :email
|
||||
|
||||
belongs_to :validation_eventable, polymorphic: true
|
||||
|
@ -17,13 +29,45 @@ class ValidationEvent < ApplicationRecord
|
|||
scope :recent, -> { where('created_at > ?', VALIDATION_PERIOD) }
|
||||
scope :successful, -> { where(success: true) }
|
||||
scope :failed, -> { where(success: false) }
|
||||
scope :regex, -> { where('event_data @> ?', { 'check_level': 'regex' }.to_json) }
|
||||
scope :mx, -> { where('event_data @> ?', { 'check_level': 'mx' }.to_json) }
|
||||
scope :smtp, -> { where('event_data @> ?', { 'check_level': 'smtp' }.to_json) }
|
||||
scope :by_object, ->(object) { where(validation_eventable: object) }
|
||||
|
||||
after_create :check_for_force_delete
|
||||
|
||||
def self.validated_ids_by(klass)
|
||||
recent.successful.where('validation_eventable_type = ?', klass)
|
||||
.pluck(:validation_eventable_id)
|
||||
end
|
||||
|
||||
def event_type
|
||||
@event_type ||= ValidationEvent::EventType.new(self[:event_kind])
|
||||
def failed?
|
||||
!success
|
||||
end
|
||||
|
||||
def successful?
|
||||
success
|
||||
end
|
||||
|
||||
def event_type
|
||||
@event_type ||= ValidationEvent::EventType.new(self[:event_type])
|
||||
end
|
||||
|
||||
def object
|
||||
validation_eventable
|
||||
end
|
||||
|
||||
def check_for_force_delete
|
||||
if object.need_to_start_force_delete?
|
||||
start_force_delete
|
||||
elsif object.need_to_lift_force_delete?
|
||||
lift_force_delete
|
||||
end
|
||||
end
|
||||
|
||||
def start_force_delete
|
||||
Domains::ForceDeleteEmail::Base.run(email: email)
|
||||
end
|
||||
|
||||
def lift_force_delete; end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue