From 62acd8892a93b45109950e7e14d3dd366a9e4deb Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Tue, 9 Jun 2020 15:56:45 +0500 Subject: [PATCH] Add nonverified email color to registrar show --- app/controllers/admin/contacts_controller.rb | 12 +++++++++--- app/models/contact.rb | 9 +++------ app/models/registrar.rb | 18 ++++++++++-------- .../admin/contacts/partials/_general.haml | 2 +- app/views/admin/registrars/index.html.erb | 4 ++-- .../admin/registrars/show/_billing.html.erb | 6 ++++-- .../admin/registrars/show/_contacts.html.erb | 6 ++++-- 7 files changed, 33 insertions(+), 24 deletions(-) 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}" %> - > + > <%= "#{x.email}" %> <% if x[:billing_email].present? %> - > + > <%= "#{x[:billing_email]}" %> <% end %> diff --git a/app/views/admin/registrars/show/_billing.html.erb b/app/views/admin/registrars/show/_billing.html.erb index da79b9074..ab731ce1d 100644 --- a/app/views/admin/registrars/show/_billing.html.erb +++ b/app/views/admin/registrars/show/_billing.html.erb @@ -15,7 +15,9 @@
<%= registrar.accounting_customer_code %>
<%= Registrar.human_attribute_name :billing_email %>
-
<%= registrar.billing_email %>
+
> + <%= registrar.billing_email %> +
<%= Registrar.human_attribute_name :reference_no %>
<%= registrar.reference_no %>
@@ -24,4 +26,4 @@
<%= registrar.iban %>
- \ No newline at end of file + diff --git a/app/views/admin/registrars/show/_contacts.html.erb b/app/views/admin/registrars/show/_contacts.html.erb index f467e6a51..b5a222dd5 100644 --- a/app/views/admin/registrars/show/_contacts.html.erb +++ b/app/views/admin/registrars/show/_contacts.html.erb @@ -15,7 +15,9 @@
<%= @registrar.phone %>
<%= Registrar.human_attribute_name :email %>
-
<%= @registrar.email %>
+
> + <%= @registrar.email %> +
- \ No newline at end of file +