mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 22:54:47 +02:00
Add thirs status - verification failed
This commit is contained in:
parent
f8eea08357
commit
56ac816dd1
13 changed files with 96 additions and 40 deletions
|
@ -30,7 +30,7 @@ module Admin
|
||||||
if params[:only_no_country_code].eql?('1')
|
if params[:only_no_country_code].eql?('1')
|
||||||
contacts = contacts.where("ident_country_code is null or ident_country_code=''")
|
contacts = contacts.where("ident_country_code is null or ident_country_code=''")
|
||||||
end
|
end
|
||||||
contacts = contacts.email_not_verified if params[:email_not_verified].eql?('1')
|
contacts = contacts.email_verification_failed if params[:email_verification_failed].eql?('1')
|
||||||
contacts
|
contacts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -108,4 +108,14 @@ module ApplicationHelper
|
||||||
def body_css_class
|
def body_css_class
|
||||||
[controller_path.split('/').map!(&:dasherize), action_name.dasherize, 'page'].join('-')
|
[controller_path.split('/').map!(&:dasherize), action_name.dasherize, 'page'].join('-')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def verified_email_span(verification)
|
||||||
|
content_tag(:span, verification.email, class: verified_email_class(verification))
|
||||||
|
end
|
||||||
|
|
||||||
|
def verified_email_class(verification)
|
||||||
|
return 'text-danger' if verification.failed?
|
||||||
|
return 'text-primary' if verification.not_verified?
|
||||||
|
return 'text-success' if verification.verified?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,10 +23,9 @@ class Contact < ApplicationRecord
|
||||||
|
|
||||||
accepts_nested_attributes_for :legal_documents
|
accepts_nested_attributes_for :legal_documents
|
||||||
|
|
||||||
scope :email_not_verified, lambda {
|
scope :email_verification_failed, lambda {
|
||||||
joins('LEFT JOIN :email_address_verifications emv ON contacts.email = emv.email')
|
joins('LEFT JOIN email_address_verifications emv ON contacts.email = emv.email')
|
||||||
.where('verified_at IS NULL OR verified_at <= ?',
|
.where('success = false and verified_at IS NOT NULL')
|
||||||
EmailAddressVerification.verification_period)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
validates :name, :email, presence: true
|
validates :name, :email, presence: true
|
||||||
|
|
|
@ -6,7 +6,11 @@ class EmailAddressVerification < ApplicationRecord
|
||||||
}
|
}
|
||||||
|
|
||||||
scope :verified_recently, lambda {
|
scope :verified_recently, lambda {
|
||||||
where('verified_at IS NOT NULL and verified_at >= ?', verification_period)
|
where('verified_at IS NOT NULL and verified_at >= ?', verification_period).where(success: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
scope :verification_failed, lambda {
|
||||||
|
where.not(verified_at: nil).where(success: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
def recently_verified?
|
def recently_verified?
|
||||||
|
@ -22,16 +26,28 @@ class EmailAddressVerification < ApplicationRecord
|
||||||
Time.zone.now - RECENTLY_VERIFIED_PERIOD
|
Time.zone.now - RECENTLY_VERIFIED_PERIOD
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def not_verified?
|
||||||
|
verified_at.blank? && !success
|
||||||
|
end
|
||||||
|
|
||||||
|
def failed?
|
||||||
|
verified_at.present? && !success
|
||||||
|
end
|
||||||
|
|
||||||
|
def verified?
|
||||||
|
success
|
||||||
|
end
|
||||||
|
|
||||||
def verify
|
def verify
|
||||||
# media = success ? :mx : :smtp
|
# media = success ? :mx : :smtp
|
||||||
media = :mx
|
media = :regex
|
||||||
validation_request = Truemail.validate(email, with: media)
|
validation_request = Truemail.validate(email, with: media)
|
||||||
|
|
||||||
if validation_request.result.success
|
if validation_request.result.success
|
||||||
update(verified_at: Time.zone.now,
|
update(verified_at: Time.zone.now,
|
||||||
success: true)
|
success: true)
|
||||||
else
|
else
|
||||||
update(verified_at: nil,
|
update(verified_at: Time.zone.now,
|
||||||
success: false)
|
success: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -13,16 +13,6 @@ class Registrar < ApplicationRecord
|
||||||
has_many :nameservers, through: :domains
|
has_many :nameservers, through: :domains
|
||||||
has_many :whois_records
|
has_many :whois_records
|
||||||
has_many :white_ips, dependent: :destroy
|
has_many :white_ips, dependent: :destroy
|
||||||
# belongs_to :email_address_verification, class_name: 'EmailAddressVerification',
|
|
||||||
# primary_key: 'email',
|
|
||||||
# foreign_key: 'email',
|
|
||||||
# optional: true,
|
|
||||||
# inverse_of: :registrar
|
|
||||||
# belongs_to :billing_email_address_verification, class_name: 'EmailAddressVerification',
|
|
||||||
# primary_key: 'email',
|
|
||||||
# foreign_key: 'billing_email',
|
|
||||||
# optional: true,
|
|
||||||
# inverse_of: :billing_registrar
|
|
||||||
|
|
||||||
delegate :balance, to: :cash_account, allow_nil: true
|
delegate :balance, to: :cash_account, allow_nil: true
|
||||||
|
|
||||||
|
|
|
@ -65,8 +65,8 @@
|
||||||
= check_box_tag :only_no_country_code, '1',params[:only_no_country_code].eql?('1'), style: 'width:auto;height:auto;float:right'
|
= check_box_tag :only_no_country_code, '1',params[:only_no_country_code].eql?('1'), style: 'width:auto;height:auto;float:right'
|
||||||
.col-md-3
|
.col-md-3
|
||||||
.form-group
|
.form-group
|
||||||
= label_tag :email_not_verified, "Email not verified"
|
= label_tag :email_verification_failed, "Email verification failed"
|
||||||
= check_box_tag :email_not_verified, '1',params[:email_not_verified].eql?('1'), style: 'width:auto;height:auto;float:right'
|
= check_box_tag :email_verification_failed, '1',params[:email_verification_failed].eql?('1'), style: 'width:auto;height:auto;float:right'
|
||||||
|
|
||||||
.row
|
.row
|
||||||
.col-md-3{style: 'padding-top: 25px;float:right;'}
|
.col-md-3{style: 'padding-top: 25px;float:right;'}
|
||||||
|
@ -100,8 +100,7 @@
|
||||||
%td= link_to(contact, admin_contact_path(contact))
|
%td= link_to(contact, admin_contact_path(contact))
|
||||||
%td= contact.code
|
%td= contact.code
|
||||||
%td= ident_for(contact)
|
%td= ident_for(contact)
|
||||||
%td{class: ('text-danger' unless contact.email_verification.success)}
|
%td= verified_email_span(contact.email_verification)
|
||||||
= contact.email
|
|
||||||
%td= l(contact.created_at, format: :short)
|
%td= l(contact.created_at, format: :short)
|
||||||
%td
|
%td
|
||||||
- if contact.registrar
|
- if contact.registrar
|
||||||
|
|
|
@ -17,8 +17,7 @@
|
||||||
%dd= ident_for(@contact)
|
%dd= ident_for(@contact)
|
||||||
|
|
||||||
%dt= t(:email)
|
%dt= t(:email)
|
||||||
%dd{class: ('text-danger' unless @contact.email_verification&.success)}
|
%dd= verified_email_span(@contact.email_verification)
|
||||||
= @contact.email
|
|
||||||
|
|
||||||
%dt= t(:phone)
|
%dt= t(:phone)
|
||||||
%dd= @contact.phone
|
%dd= @contact.phone
|
||||||
|
|
|
@ -49,13 +49,9 @@
|
||||||
<%= "#{x.test_registrar}" %>
|
<%= "#{x.test_registrar}" %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<span class=<%= 'text-danger' unless x.email_verification&.success %>>
|
<%= verified_email_span(x.email_verification) %>
|
||||||
<%= "#{x.email}" %>
|
|
||||||
</span>
|
|
||||||
<% if x[:billing_email].present? %>
|
<% if x[:billing_email].present? %>
|
||||||
<span class=<%= 'text-danger' unless x.billing_email_verification&.success %>>
|
<%= verified_email_span(x.billing_email_verification) %>
|
||||||
<%= "#{x[:billing_email]}" %>
|
|
||||||
</span>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
<dd><%= registrar.accounting_customer_code %></dd>
|
<dd><%= registrar.accounting_customer_code %></dd>
|
||||||
|
|
||||||
<dt><%= Registrar.human_attribute_name :billing_email %></dt>
|
<dt><%= Registrar.human_attribute_name :billing_email %></dt>
|
||||||
<dd class=<%= 'text-danger' unless @registrar.billing_email_verification&.success%>>
|
<dd>
|
||||||
<%= registrar.billing_email %>
|
<%= verified_email_span(registrar.billing_email_verification) %>
|
||||||
</dd>
|
</dd>
|
||||||
|
|
||||||
<dt><%= Registrar.human_attribute_name :reference_no %></dt>
|
<dt><%= Registrar.human_attribute_name :reference_no %></dt>
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
<dd><%= @registrar.phone %></dd>
|
<dd><%= @registrar.phone %></dd>
|
||||||
|
|
||||||
<dt><%= Registrar.human_attribute_name :email %></dt>
|
<dt><%= Registrar.human_attribute_name :email %></dt>
|
||||||
<dd class=<%= 'text-danger' unless @registrar.email_verification&.success %>>
|
<dd>
|
||||||
<%= @registrar.email %>
|
<%= verified_email_span(@registrar.email_verification) %>
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
class FillEmailVerifications < ActiveRecord::Migration[6.0]
|
class FillEmailVerifications < ActiveRecord::Migration[6.0]
|
||||||
def up
|
def up
|
||||||
registrar_billing_emails = Registrar.pluck(:billing_email).uniq.reject(&:blank?)
|
registrar_billing_emails = Registrar.pluck(:billing_email).uniq.reject(&:blank?).map(&:downcase)
|
||||||
registrar_emails = Registrar.pluck(:email).uniq.reject(&:blank?)
|
registrar_emails = Registrar.pluck(:email).uniq.reject(&:blank?).map(&:downcase)
|
||||||
contact_emails = Contact.pluck(:email).uniq.reject(&:blank?)
|
contact_emails = Contact.pluck(:email).uniq.reject(&:blank?).map(&:downcase)
|
||||||
|
|
||||||
emails = (contact_emails + registrar_emails + registrar_billing_emails).uniq
|
emails = (contact_emails + registrar_emails + registrar_billing_emails).uniq
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,7 @@ namespace :verify_email do
|
||||||
desc 'Stars verifying email jobs'
|
desc 'Stars verifying email jobs'
|
||||||
task all_domains: :environment do
|
task all_domains: :environment do
|
||||||
verifications_by_domain = EmailAddressVerification.not_verified_recently.group_by(&:domain)
|
verifications_by_domain = EmailAddressVerification.not_verified_recently.group_by(&:domain)
|
||||||
verifications_by_domain.each do |domain, verifications|
|
verifications_by_domain.each do |_domain, verifications|
|
||||||
next if domain == 'not_found'
|
|
||||||
|
|
||||||
ver = verifications.sample # Verify random email to not to clog the SMTP servers
|
ver = verifications.sample # Verify random email to not to clog the SMTP servers
|
||||||
VerifyEmailsJob.enqueue(ver.id)
|
VerifyEmailsJob.enqueue(ver.id)
|
||||||
next
|
next
|
||||||
|
|
49
test/tasks/emails/verify_email_task_test.rb
Normal file
49
test/tasks/emails/verify_email_task_test.rb
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class VerifyEmailTaskTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
|
def setup
|
||||||
|
@contact = contacts(:john)
|
||||||
|
@invalid_contact = contacts(:invalid_email)
|
||||||
|
@contact_verification = @contact.email_verification
|
||||||
|
@invalid_contact_verification = @invalid_contact.email_verification
|
||||||
|
|
||||||
|
@default_whitelist = Truemail.configure.whitelisted_domains
|
||||||
|
@default_blacklist = Truemail.configure.blacklisted_domains
|
||||||
|
Truemail.configure.whitelisted_domains = whitelisted_domains
|
||||||
|
Truemail.configure.blacklisted_domains = blacklisted_domains
|
||||||
|
end
|
||||||
|
|
||||||
|
def teardown
|
||||||
|
Truemail.configure.whitelisted_domains = @default_whitelist
|
||||||
|
Truemail.configure.blacklisted_domains = @default_blacklist
|
||||||
|
end
|
||||||
|
|
||||||
|
def domain(email)
|
||||||
|
Mail::Address.new(email).domain
|
||||||
|
rescue Mail::Field::IncompleteParseError
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def whitelisted_domains
|
||||||
|
[domain(@contact.email)].reject(&:blank?)
|
||||||
|
end
|
||||||
|
|
||||||
|
def blacklisted_domains
|
||||||
|
[domain(@invalid_contact.email)].reject(&:blank?)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_tasks_verifies_emails
|
||||||
|
capture_io { run_task }
|
||||||
|
|
||||||
|
@contact_verification.reload
|
||||||
|
@invalid_contact_verification.reload
|
||||||
|
|
||||||
|
assert @contact_verification.verified?
|
||||||
|
assert @invalid_contact_verification.failed?
|
||||||
|
end
|
||||||
|
|
||||||
|
def run_task
|
||||||
|
Rake::Task['verify_email:all_domains'].execute
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue