diff --git a/app/controllers/admin/contacts_controller.rb b/app/controllers/admin/contacts_controller.rb index d48d5c09b..685a08c86 100644 --- a/app/controllers/admin/contacts_controller.rb +++ b/app/controllers/admin/contacts_controller.rb @@ -14,11 +14,9 @@ module Admin end contacts = Contact.includes(:registrar).joins(:registrar) - .includes(:email_address_verification) .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 = contacts.email_not_verified if params[:email_not_verified].eql?('1') + contacts = filter_by_flags(contacts) normalize_search_parameters do @q = contacts.search(search_params) @@ -28,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_not_verified if params[:email_not_verified].eql?('1') + contacts + end + def search render json: Contact.search_by_query(params[:q]) end diff --git a/app/models/contact.rb b/app/models/contact.rb index 556907ba4..a24a53a72 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -16,10 +16,6 @@ class Contact < ApplicationRecord has_many :legal_documents, as: :documentable has_many :registrant_domains, class_name: 'Domain', foreign_key: 'registrant_id' has_many :actions, dependent: :destroy - belongs_to :email_address_verification, class_name: 'EmailAddressVerification', - primary_key: 'email', - foreign_key: 'email', - optional: true attr_accessor :legal_document_id alias_attribute :kind, :ident_type @@ -28,8 +24,9 @@ class Contact < ApplicationRecord accepts_nested_attributes_for :legal_documents scope :email_not_verified, lambda { - joins(:email_address_verification) - .where('verified_at IS NULL OR verified_at <= ?', EmailAddressVerification.verification_period) + joins('LEFT JOIN :email_address_verifications emv ON contacts.email = emv.email') + .where('verified_at IS NULL OR verified_at <= ?', + EmailAddressVerification.verification_period) } validates :name, :email, presence: true diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 3fec53f21..9abdfdb68 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -13,14 +13,16 @@ class Registrar < ApplicationRecord has_many :nameservers, through: :domains has_many :whois_records has_many :white_ips, dependent: :destroy - belongs_to :email_address_verification, class_name: 'EmailAddressVerification', - primary_key: 'email', - foreign_key: 'email', - optional: true - belongs_to :billing_email_address_verification, class_name: 'EmailAddressVerification', - primary_key: 'email', - foreign_key: 'billing_email', - optional: true + # 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 diff --git a/app/views/admin/contacts/partials/_general.haml b/app/views/admin/contacts/partials/_general.haml index 7245ca218..c4a151294 100644 --- a/app/views/admin/contacts/partials/_general.haml +++ b/app/views/admin/contacts/partials/_general.haml @@ -17,7 +17,7 @@ %dd= ident_for(@contact) %dt= t(:email) - %dd{class: ('text-danger' unless @contact.email_verification.success)} + %dd{class: ('text-danger' unless @contact.email_verification&.success)} = @contact.email %dt= t(:phone) diff --git a/app/views/admin/registrars/index.html.erb b/app/views/admin/registrars/index.html.erb index 4b3fbd98a..6ed864972 100644 --- a/app/views/admin/registrars/index.html.erb +++ b/app/views/admin/registrars/index.html.erb @@ -49,11 +49,11 @@ <%= "#{x.test_registrar}" %>