Updated pagination size and registrar trigger now honors only whois attributes

This commit is contained in:
Priit Tark 2015-04-30 18:29:26 +03:00
parent 4cf57239a0
commit 64152479a9
8 changed files with 77 additions and 26 deletions

View file

@ -6,7 +6,7 @@ class Admin::RegistrarsController < AdminController
end
def index
@q = Registrar.search(params[:q])
@q = Registrar.ordered.search(params[:q])
@registrars = @q.result.page(params[:page])
end

View file

@ -8,6 +8,7 @@ class Registrar < ActiveRecord::Base
has_many :invoices, foreign_key: 'buyer_id'
has_many :accounts
has_many :nameservers, through: :domains
has_many :whois_records
belongs_to :country_deprecated, foreign_key: :country_id
@ -39,6 +40,15 @@ class Registrar < ActiveRecord::Base
validates :email, :billing_email, format: /@/, allow_blank: true
WHOIS_TRIGGERS = %w(name email phone street city state zip)
after_save :update_whois_records
def update_whois_records
if changed? && (changes.keys & WHOIS_TRIGGERS).present?
whois_records.map(&:save) # slow currently
end
end
class << self
def search_by_query(query)
res = search(name_or_reg_no_cont: query).result
@ -48,6 +58,11 @@ class Registrar < ActiveRecord::Base
def eis
find_by(reg_no: '90010019')
end
def ordered
order(name: :asc)
end
end
def issue_prepayment_invoice(amount, description = nil) # rubocop:disable Metrics/MethodLength

View file

@ -5,10 +5,25 @@ class WhoisRecord < ActiveRecord::Base
before_validation :populate
def populate
return if domain.blank?
return if domain_id.blank?
self.json = generate_json
self.name = json['name']
self.body = generated_body
self.name = json['name']
self.registrar_id = domain.registrar_id # for faster registrar updates
end
class << self
def included
includes(
domain: [
:registrant,
:registrar,
:nameservers,
{ tech_contacts: :registrar },
{ admin_contacts: :registrar }
]
)
end
end
# rubocop:disable Metrics/MethodLength
@ -24,10 +39,12 @@ class WhoisRecord < ActiveRecord::Base
h[:updated_at] = domain.updated_at.try(:to_s, :iso8601)
h[:valid_to] = domain.valid_to.try(:to_s, :iso8601)
# update registar triggers when adding new attributes
h[:registrar] = domain.registrar.name
h[:registrar_phone] = domain.registrar.phone
h[:registrar_address] = domain.registrar.address
h[:registrar_update_at] = domain.registrar.updated_at.try(:to_s, :iso8601)
h[:admin_contacts] = []
domain.admin_contacts.each do |ac|
@disclosed << [:email, ac.email]