mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 16:32:04 +02:00
Merge branch 'master' into 2236-removing-old-validation-events
This commit is contained in:
commit
bbc1380e46
169 changed files with 2190 additions and 1340 deletions
|
@ -19,12 +19,12 @@ module Actions
|
|||
def maybe_change_email
|
||||
return if Rails.env.test?
|
||||
|
||||
[:regex, :mx].each do |m|
|
||||
%i[regex mx].each do |m|
|
||||
result = Actions::SimpleMailValidator.run(email: contact.email, level: m)
|
||||
|
||||
next if result
|
||||
|
||||
contact.add_epp_error('2005', nil, "email didn't pass validation", I18n.t(:parameter_value_syntax_error))
|
||||
err_text = "email '#{contact.email}' didn't pass validation"
|
||||
contact.add_epp_error('2005', nil, nil, "#{I18n.t(:parameter_value_syntax_error)} #{err_text}")
|
||||
@error = true
|
||||
return
|
||||
end
|
||||
|
@ -84,6 +84,7 @@ module Actions
|
|||
return false if @error
|
||||
|
||||
contact.generate_code
|
||||
contact.email_history = contact.email
|
||||
contact.save
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,11 +23,12 @@ module Actions
|
|||
def maybe_change_email
|
||||
return if Rails.env.test?
|
||||
|
||||
[:regex, :mx].each do |m|
|
||||
%i[regex mx].each do |m|
|
||||
result = Actions::SimpleMailValidator.run(email: @new_attributes[:email], level: m)
|
||||
next if result
|
||||
|
||||
contact.add_epp_error('2005', nil, "email didn't pass validation", I18n.t(:parameter_value_syntax_error))
|
||||
err_text = "email '#{new_attributes[:email]}' didn't pass validation"
|
||||
contact.add_epp_error('2005', nil, nil, "#{I18n.t(:parameter_value_syntax_error)} #{err_text}")
|
||||
@error = true
|
||||
return
|
||||
end
|
||||
|
@ -36,12 +37,11 @@ module Actions
|
|||
end
|
||||
|
||||
def maybe_filtering_old_failed_records
|
||||
if contact.validation_events.count > 1
|
||||
contact.validation_events.order!(created_at: :asc)
|
||||
while contact.validation_events.count >= 1
|
||||
contact.validation_events.first.destroy
|
||||
end
|
||||
end
|
||||
validation_events = contact.validation_events
|
||||
return unless validation_events.count > 1
|
||||
|
||||
validation_events.order!(created_at: :asc)
|
||||
validation_events.first.destroy while validation_events.count >= 1
|
||||
end
|
||||
|
||||
def maybe_remove_address
|
||||
|
@ -112,10 +112,12 @@ module Actions
|
|||
|
||||
email_changed = contact.will_save_change_to_email?
|
||||
old_email = contact.email_was
|
||||
contact.email_history = old_email
|
||||
updated = contact.save
|
||||
|
||||
if updated && email_changed && contact.registrant?
|
||||
ContactMailer.email_changed(contact: contact, old_email: old_email).deliver_now
|
||||
if updated && email_changed
|
||||
contact.validation_events.where('event_data @> ?', { 'email': old_email }.to_json).destroy_all
|
||||
ContactMailer.email_changed(contact: contact, old_email: old_email).deliver_now if contact.registrant?
|
||||
end
|
||||
|
||||
updated
|
||||
|
|
|
@ -120,7 +120,7 @@ module Actions
|
|||
contact = Contact.find_by(code: contact_code)
|
||||
arr = admin ? @admin_contacts : @tech_contacts
|
||||
if contact
|
||||
arr << { contact_id: contact.id, contact_code_cache: contact.code }
|
||||
arr << { contact_id: contact.id, contact_code: contact.code }
|
||||
else
|
||||
domain.add_epp_error('2303', 'contact', contact_code, %i[domain_contacts not_found])
|
||||
end
|
||||
|
|
|
@ -45,6 +45,10 @@ module Actions
|
|||
def assign_new_registrant
|
||||
domain.add_epp_error('2306', nil, nil, %i[registrant cannot_be_missing]) unless params[:registrant][:code]
|
||||
|
||||
contact_code = params[:registrant][:code]
|
||||
contact = Contact.find_by(code: contact_code)
|
||||
validate_email(contact.email)
|
||||
|
||||
regt = Registrant.find_by(code: params[:registrant][:code])
|
||||
unless regt
|
||||
domain.add_epp_error('2303', 'registrant', params[:registrant], %i[registrant not_found])
|
||||
|
@ -120,9 +124,35 @@ module Actions
|
|||
@dnskeys << { id: dnkey.id, _destroy: 1 } if dnkey
|
||||
end
|
||||
|
||||
def start_validate_email(props)
|
||||
contact = Contact.find_by(code: props[0][:contact_code])
|
||||
|
||||
return if contact.nil?
|
||||
|
||||
validate_email(contact.email)
|
||||
end
|
||||
|
||||
def validate_email(email)
|
||||
return true if Rails.env.test?
|
||||
|
||||
%i[regex mx].each do |m|
|
||||
result = Actions::SimpleMailValidator.run(email: email, level: m)
|
||||
next if result
|
||||
|
||||
err_text = "email #{email} didn't pass validation"
|
||||
domain.add_epp_error('2005', nil, nil, "#{I18n.t(:parameter_value_syntax_error)} #{err_text}")
|
||||
@error = true
|
||||
return
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def assign_admin_contact_changes
|
||||
props = gather_domain_contacts(params[:contacts].select { |c| c[:type] == 'admin' })
|
||||
|
||||
start_validate_email(props) if props.present?
|
||||
|
||||
if props.any? && domain.admin_change_prohibited?
|
||||
domain.add_epp_error('2304', 'admin', DomainStatus::SERVER_ADMIN_CHANGE_PROHIBITED,
|
||||
I18n.t(:object_status_prohibits_operation))
|
||||
|
@ -136,6 +166,8 @@ module Actions
|
|||
props = gather_domain_contacts(params[:contacts].select { |c| c[:type] == 'tech' },
|
||||
admin: false)
|
||||
|
||||
start_validate_email(props) if props.present?
|
||||
|
||||
if props.any? && domain.tech_change_prohibited?
|
||||
domain.add_epp_error('2304', 'tech', DomainStatus::SERVER_TECH_CHANGE_PROHIBITED,
|
||||
I18n.t(:object_status_prohibits_operation))
|
||||
|
@ -173,7 +205,7 @@ module Actions
|
|||
domain.add_epp_error('2306', 'contact', code,
|
||||
%i[domain_contacts admin_contact_can_be_only_private_person])
|
||||
else
|
||||
add ? { contact_id: obj.id, contact_code_cache: obj.code } : { id: obj.id, _destroy: 1 }
|
||||
add ? { contact_id: obj.id, contact_code: obj.code } : { id: obj.id, _destroy: 1 }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -31,31 +31,27 @@ module Actions
|
|||
Rails.env.test? && check_level == 'smtp' ? :mx : check_level.to_sym
|
||||
end
|
||||
|
||||
def destroy_old_validations(validation_events, minimum_size, check_level)
|
||||
return unless validation_events.count > minimum_size && @check_level == check_level
|
||||
|
||||
validation_events.order!(created_at: :asc)
|
||||
validation_events.first.destroy while validation_events.count > minimum_size
|
||||
end
|
||||
|
||||
def filtering_old_failed_records(result)
|
||||
if @check_level == "mx" && !result.success && validation_eventable.validation_events.count > 3
|
||||
validation_eventable.validation_events.order!(created_at: :asc)
|
||||
while validation_eventable.validation_events.count > 3
|
||||
validation_eventable.validation_events.first.destroy
|
||||
end
|
||||
end
|
||||
events = validation_eventable.validation_events
|
||||
|
||||
if @check_level == "mx" && result.success && validation_eventable.validation_events.count > 1
|
||||
validation_eventable.validation_events.order!(created_at: :asc)
|
||||
while validation_eventable.validation_events.count > 1
|
||||
validation_eventable.validation_events.first.destroy
|
||||
end
|
||||
end
|
||||
destroy_old_validations(events, ValidationEvent::MX_CHECK, 'mx') unless result.success
|
||||
|
||||
if @check_level == "smtp" && validation_eventable.validation_events.count > 1
|
||||
validation_eventable.validation_events.order!(created_at: :asc)
|
||||
while validation_eventable.validation_events.count > 1
|
||||
validation_eventable.validation_events.first.destroy
|
||||
end
|
||||
end
|
||||
destroy_old_validations(events, ValidationEvent::REDEEM_EVENTS_COUNT_BY_LEVEL[:mx], 'mx') if result.success
|
||||
|
||||
destroy_old_validations(events, ValidationEvent::REDEEM_EVENTS_COUNT_BY_LEVEL[:smtp], 'smtp')
|
||||
end
|
||||
|
||||
def save_result(result)
|
||||
if !result.success && @check_level == "mx"
|
||||
contacts = Contact.where(email: email)
|
||||
|
||||
if !result.success && @check_level == 'mx'
|
||||
result_validation = Actions::AAndAaaaEmailValidation.call(email: @email, value: 'A')
|
||||
output_a_and_aaaa_validation_results(email: @email,
|
||||
result: result_validation,
|
||||
|
@ -65,11 +61,13 @@ module Actions
|
|||
output_a_and_aaaa_validation_results(email: @email,
|
||||
result: result_validation,
|
||||
type: 'AAAA')
|
||||
result.success = result_validation.present?
|
||||
end
|
||||
|
||||
result_validation.present? ? result.success = true : result.success = false
|
||||
validation_eventable.validation_events.create(validation_event_attrs(result))
|
||||
else
|
||||
validation_eventable.validation_events.create(validation_event_attrs(result))
|
||||
contacts.find_in_batches(batch_size: 500) do |contact_batches|
|
||||
contact_batches.each do |contact|
|
||||
contact.validation_events.create(validation_event_attrs(result))
|
||||
end
|
||||
end
|
||||
rescue ActiveRecord::RecordNotSaved
|
||||
logger.info "Cannot save validation result for #{log_object_id}"
|
||||
|
@ -97,8 +95,7 @@ module Actions
|
|||
when 'AAAA'
|
||||
ress = dns.getresources domain, Resolv::DNS::Resource::IN::AAAA
|
||||
end
|
||||
|
||||
result = ress.map { |r| r.address }
|
||||
result = ress.map(&:address)
|
||||
end
|
||||
|
||||
result
|
||||
|
|
|
@ -6,18 +6,26 @@ module Domains
|
|||
end
|
||||
|
||||
def notify_without_email
|
||||
domain.registrar.notifications.create!(text: I18n.t('force_delete_set_on_domain',
|
||||
domain_name: domain.name,
|
||||
outzone_date: domain.outzone_date,
|
||||
purge_date: domain.purge_date))
|
||||
template = I18n.t('force_delete_set_on_domain',
|
||||
domain_name: domain.name,
|
||||
outzone_date: domain.outzone_date,
|
||||
purge_date: domain.purge_date)
|
||||
|
||||
return if domain.registrar.notifications.last.text.include? template
|
||||
|
||||
domain.registrar.notifications.create!(text: template)
|
||||
end
|
||||
|
||||
def notify_with_email
|
||||
domain.registrar.notifications.create!(text: I18n.t('force_delete_auto_email',
|
||||
domain_name: domain.name,
|
||||
outzone_date: domain.outzone_date,
|
||||
purge_date: domain.purge_date,
|
||||
email: email))
|
||||
template = I18n.t('force_delete_auto_email',
|
||||
domain_name: domain.name,
|
||||
outzone_date: domain.outzone_date,
|
||||
purge_date: domain.purge_date,
|
||||
email: email)
|
||||
|
||||
return if domain.registrar.notifications.last.text.include? template
|
||||
|
||||
domain.registrar.notifications.create!(text: template)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,6 +11,8 @@ module Domains
|
|||
domains = domain_contacts.map(&:domain).flatten +
|
||||
Domain.where(registrant_id: registrant_ids)
|
||||
|
||||
return if expired_or_hold_domains_exists?(domains)
|
||||
|
||||
domains.each do |domain|
|
||||
next if domain.expired?
|
||||
|
||||
|
@ -20,6 +22,12 @@ module Domains
|
|||
|
||||
private
|
||||
|
||||
def expired_or_hold_domains_exists?(domains)
|
||||
domains.any? do |domain|
|
||||
domain.statuses.include?(DomainStatus::SERVER_HOLD) && email.include?(domain.name)
|
||||
end
|
||||
end
|
||||
|
||||
def before_execute_force_delete(domain)
|
||||
if domain.force_delete_scheduled? && !domain.status_notes[DomainStatus::FORCE_DELETE].nil?
|
||||
added_additional_email_into_notes(domain)
|
||||
|
@ -28,6 +36,18 @@ module Domains
|
|||
end
|
||||
end
|
||||
|
||||
def notify_registrar(domain)
|
||||
template = I18n.t('force_delete_auto_email',
|
||||
domain_name: domain.name,
|
||||
outzone_date: domain.outzone_date,
|
||||
purge_date: domain.purge_date,
|
||||
email: domain.status_notes[DomainStatus::FORCE_DELETE])
|
||||
|
||||
return if domain.registrar.notifications.last.text.include? template
|
||||
|
||||
domain.registrar.notifications.create!(text: template)
|
||||
end
|
||||
|
||||
def process_force_delete(domain)
|
||||
domain.schedule_force_delete(type: :soft,
|
||||
notify_by_email: true,
|
||||
|
@ -39,6 +59,8 @@ module Domains
|
|||
def added_additional_email_into_notes(domain)
|
||||
return if domain.status_notes[DomainStatus::FORCE_DELETE].include? email
|
||||
|
||||
# notify_registrar(domain)
|
||||
|
||||
domain.status_notes[DomainStatus::FORCE_DELETE].concat(" #{email}")
|
||||
domain.save(validate: false)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue