mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 12:08:27 +02:00
Return truemail
This reverts commit 862f5639ebbe4d3e6abd5d5be7fb7840e7b83bdf.
This commit is contained in:
parent
0a7b754c4c
commit
e4a02c2e47
35 changed files with 728 additions and 153 deletions
|
@ -13,10 +13,10 @@ module Admin
|
|||
search_params[:registrant_domains_id_not_null] = 1
|
||||
end
|
||||
|
||||
contacts = Contact.includes(:registrar).joins(:registrar).select('contacts.*, registrars.name')
|
||||
contacts = Contact.includes(:registrar).joins(:registrar)
|
||||
.select('contacts.*, registrars.name')
|
||||
contacts = contacts.filter_by_states(params[:statuses_contains].join(',')) if params[:statuses_contains]
|
||||
contacts = contacts.where("ident_country_code is null or ident_country_code=''") if params[:only_no_country_code].eql?('1')
|
||||
|
||||
contacts = filter_by_flags(contacts)
|
||||
|
||||
normalize_search_parameters do
|
||||
@q = contacts.search(search_params)
|
||||
|
@ -26,6 +26,14 @@ module Admin
|
|||
@contacts = @contacts.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
|
||||
end
|
||||
|
||||
def filter_by_flags(contacts)
|
||||
if params[:only_no_country_code].eql?('1')
|
||||
contacts = contacts.where("ident_country_code is null or ident_country_code=''")
|
||||
end
|
||||
contacts = contacts.email_verification_failed if params[:email_verification_failed].eql?('1')
|
||||
contacts
|
||||
end
|
||||
|
||||
def search
|
||||
render json: Contact.search_by_query(params[:q])
|
||||
end
|
||||
|
|
|
@ -108,4 +108,14 @@ module ApplicationHelper
|
|||
def body_css_class
|
||||
[controller_path.split('/').map!(&:dasherize), action_name.dasherize, 'page'].join('-')
|
||||
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
|
||||
|
|
45
app/jobs/verify_emails_job.rb
Normal file
45
app/jobs/verify_emails_job.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
class VerifyEmailsJob < Que::Job
|
||||
def run(verification_id)
|
||||
email_address_verification = run_condition(EmailAddressVerification.find(verification_id))
|
||||
|
||||
return if email_address_verification.recently_verified?
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
email_address_verification.verify
|
||||
log_success(email_address_verification)
|
||||
destroy
|
||||
end
|
||||
rescue StandardError => e
|
||||
log_error(verification: email_address_verification, error: e)
|
||||
raise e
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def run_condition(email_address_verification)
|
||||
destroy unless email_address_verification
|
||||
destroy if email_address_verification.recently_verified?
|
||||
|
||||
email_address_verification
|
||||
end
|
||||
|
||||
def logger
|
||||
@logger ||= Logger.new(Rails.root.join('log', 'email_verification.log'))
|
||||
end
|
||||
|
||||
def log_success(verification)
|
||||
email = verification.try(:email) || verification
|
||||
message = "Email address #{email} verification done"
|
||||
logger.info message
|
||||
end
|
||||
|
||||
def log_error(verification:, error:)
|
||||
email = verification.try(:email) || verification
|
||||
message = <<~TEXT.squish
|
||||
There was an error verifying email #{email}.
|
||||
The error message was the following: #{error}
|
||||
This job will retry.
|
||||
TEXT
|
||||
logger.error message
|
||||
end
|
||||
end
|
|
@ -75,6 +75,7 @@ module Concerns
|
|||
process_result(result: result, field: :billing_email)
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/LineLength
|
||||
def process_result(result:, field:)
|
||||
case result[:errors].keys.first
|
||||
when :smtp
|
||||
|
@ -85,5 +86,6 @@ module Concerns
|
|||
errors.add(field, I18n.t('activerecord.errors.models.contact.attributes.email.email_regex_check_error'))
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/LineLength
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,6 +7,7 @@ class Contact < ApplicationRecord
|
|||
include Concerns::Contact::Transferable
|
||||
include Concerns::Contact::Identical
|
||||
include Concerns::Contact::Disclosable
|
||||
include Concerns::EmailVerifable
|
||||
|
||||
belongs_to :original, class_name: self.name
|
||||
belongs_to :registrar, required: true
|
||||
|
@ -22,6 +23,11 @@ class Contact < ApplicationRecord
|
|||
|
||||
accepts_nested_attributes_for :legal_documents
|
||||
|
||||
scope :email_verification_failed, lambda {
|
||||
joins('LEFT JOIN email_address_verifications emv ON contacts.email = emv.email')
|
||||
.where('success = false and verified_at IS NOT NULL')
|
||||
}
|
||||
|
||||
validates :name, :email, presence: true
|
||||
validates :street, :city, :zip, :country_code, presence: true, if: lambda {
|
||||
self.class.address_processing?
|
||||
|
@ -29,8 +35,7 @@ class Contact < ApplicationRecord
|
|||
|
||||
validates :phone, presence: true, e164: true, phone: true
|
||||
|
||||
validates :email, format: /@/
|
||||
validates :email, email_format: { message: :invalid }, if: proc { |c| c.will_save_change_to_email? }
|
||||
validate :correct_email_format, if: proc { |c| c.will_save_change_to_email? }
|
||||
|
||||
validates :code,
|
||||
uniqueness: { message: :epp_id_taken },
|
||||
|
|
56
app/models/email_address_verification.rb
Normal file
56
app/models/email_address_verification.rb
Normal file
|
@ -0,0 +1,56 @@
|
|||
class EmailAddressVerification < ApplicationRecord
|
||||
RECENTLY_VERIFIED_PERIOD = 1.month
|
||||
|
||||
scope :not_verified_recently, lambda {
|
||||
where('verified_at IS NULL or verified_at < ?', verification_period)
|
||||
}
|
||||
|
||||
scope :verified_recently, lambda {
|
||||
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)
|
||||
}
|
||||
|
||||
scope :by_domain, ->(domain_name) { where(domain: domain_name) }
|
||||
|
||||
def recently_verified?
|
||||
verified_at.present? &&
|
||||
verified_at > verification_period
|
||||
end
|
||||
|
||||
def verification_period
|
||||
self.class.verification_period
|
||||
end
|
||||
|
||||
def self.verification_period
|
||||
Time.zone.now - RECENTLY_VERIFIED_PERIOD
|
||||
end
|
||||
|
||||
def not_verified?
|
||||
verified_at.blank? && !success
|
||||
end
|
||||
|
||||
def failed?
|
||||
verified_at.present? && !success
|
||||
end
|
||||
|
||||
def verified?
|
||||
success
|
||||
end
|
||||
|
||||
def verify
|
||||
validation_request = Truemail.validate(email)
|
||||
|
||||
if validation_request.result.success
|
||||
update(verified_at: Time.zone.now,
|
||||
success: true)
|
||||
else
|
||||
update(verified_at: Time.zone.now,
|
||||
success: false)
|
||||
end
|
||||
|
||||
validation_request.result
|
||||
end
|
||||
end
|
|
@ -60,6 +60,7 @@ class Epp::Contact < Contact
|
|||
|
||||
delegate :ident_attr_valid?, to: :class
|
||||
|
||||
# rubocop:disable Style/SymbolArray
|
||||
def epp_code_map
|
||||
{
|
||||
'2003' => [ # Required parameter missing
|
||||
|
@ -80,7 +81,7 @@ class Epp::Contact < Contact
|
|||
[:code, :too_long_contact_code],
|
||||
[:email, :email_smtp_check_error],
|
||||
[:email, :email_mx_check_error],
|
||||
[:email, :email_regex_check_error]
|
||||
[:email, :email_regex_check_error],
|
||||
],
|
||||
'2302' => [ # Object exists
|
||||
[:code, :epp_id_taken]
|
||||
|
@ -90,6 +91,7 @@ class Epp::Contact < Contact
|
|||
]
|
||||
}
|
||||
end
|
||||
# rubocop:enable Style/SymbolArray
|
||||
|
||||
def attach_legal_document(legal_document_data)
|
||||
return unless legal_document_data
|
||||
|
|
|
@ -88,7 +88,7 @@ class Nameserver < ApplicationRecord
|
|||
end
|
||||
|
||||
def normalize_attributes
|
||||
self.hostname = hostname.try(:strip).try(:downcase)
|
||||
self.hostname = hostname.try(:strip).try(:downcase).gsub(/\.$/, '')
|
||||
self.ipv4 = Array(ipv4).reject(&:blank?).map(&:strip)
|
||||
self.ipv6 = Array(ipv6).reject(&:blank?).map(&:strip).map(&:upcase)
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class Registrar < ApplicationRecord
|
||||
include Versions # version/registrar_version.rb
|
||||
include Concerns::Registrar::BookKeeping
|
||||
include Concerns::EmailVerifable
|
||||
include Concerns::Registrar::LegalDoc
|
||||
|
||||
has_many :domains, dependent: :restrict_with_error
|
||||
|
@ -29,14 +30,11 @@ class Registrar < ApplicationRecord
|
|||
validates :vat_rate, numericality: { greater_than_or_equal_to: 0, less_than: 100 },
|
||||
allow_nil: true
|
||||
|
||||
validate :forbid_special_code
|
||||
|
||||
attribute :vat_rate, ::Type::VATRate.new
|
||||
after_initialize :set_defaults
|
||||
|
||||
validates :email, email_format: { message: :invalid },
|
||||
allow_blank: true, if: proc { |c| c.will_save_change_to_email? }
|
||||
validates :billing_email, email_format: { message: :invalid }, allow_blank: true
|
||||
validate :correct_email_format, if: proc { |c| c.will_save_change_to_email? }
|
||||
validate :correct_billing_email_format
|
||||
|
||||
alias_attribute :contact_email, :email
|
||||
|
||||
|
|
|
@ -63,6 +63,10 @@
|
|||
.form-group
|
||||
= label_tag :only_no_country_code, "Ident CC missing"
|
||||
= 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
|
||||
.form-group
|
||||
= label_tag :email_verification_failed, "Email verification failed"
|
||||
= check_box_tag :email_verification_failed, '1',params[:email_verification_failed].eql?('1'), style: 'width:auto;height:auto;float:right'
|
||||
|
||||
.row
|
||||
.col-md-3{style: 'padding-top: 25px;float:right;'}
|
||||
|
@ -85,7 +89,9 @@
|
|||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'ident', t(:ident))
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'email', t(:created_at))
|
||||
= sort_link(@q, 'email', t(:email))
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'created_at', t(:created_at))
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'registrar_name', t(:registrar_name))
|
||||
%tbody
|
||||
|
@ -94,6 +100,7 @@
|
|||
%td= link_to(contact, admin_contact_path(contact))
|
||||
%td= contact.code
|
||||
%td= ident_for(contact)
|
||||
%td= verified_email_span(contact.email_verification)
|
||||
%td= l(contact.created_at, format: :short)
|
||||
%td
|
||||
- if contact.registrar
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
%dd= ident_for(@contact)
|
||||
|
||||
%dt= t(:email)
|
||||
%dd= @contact.email
|
||||
%dd= verified_email_span(@contact.email_verification)
|
||||
|
||||
%dt= t(:phone)
|
||||
%dd= @contact.phone
|
||||
|
|
|
@ -28,6 +28,9 @@
|
|||
<th class="col-xs-4">
|
||||
<%= t(:test_registrar) %>
|
||||
</th>
|
||||
<th class="col-xs-4">
|
||||
<%= t(:emails) %>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -45,6 +48,12 @@
|
|||
<td>
|
||||
<%= "#{x.test_registrar}" %>
|
||||
</td>
|
||||
<td>
|
||||
<%= verified_email_span(x.email_verification) %>
|
||||
<% if x[:billing_email].present? %>
|
||||
<%= verified_email_span(x.billing_email_verification) %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
|
|
@ -15,7 +15,9 @@
|
|||
<dd><%= registrar.accounting_customer_code %></dd>
|
||||
|
||||
<dt><%= Registrar.human_attribute_name :billing_email %></dt>
|
||||
<dd><%= registrar.billing_email %></dd>
|
||||
<dd>
|
||||
<%= verified_email_span(registrar.billing_email_verification) %>
|
||||
</dd>
|
||||
|
||||
<dt><%= Registrar.human_attribute_name :reference_no %></dt>
|
||||
<dd><%= registrar.reference_no %></dd>
|
||||
|
@ -24,4 +26,4 @@
|
|||
<dd><%= registrar.iban %></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -15,7 +15,9 @@
|
|||
<dd><%= @registrar.phone %></dd>
|
||||
|
||||
<dt><%= Registrar.human_attribute_name :email %></dt>
|
||||
<dd><%= @registrar.email %></dd>
|
||||
<dd>
|
||||
<%= verified_email_span(@registrar.email_verification) %>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue