mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Updated pagination size and registrar trigger now honors only whois attributes
This commit is contained in:
parent
4cf57239a0
commit
64152479a9
8 changed files with 77 additions and 26 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
10
config/initializers/kaminari_config.rb
Normal file
10
config/initializers/kaminari_config.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
Kaminari.configure do |config|
|
||||
config.default_per_page = 75
|
||||
# config.max_per_page = nil
|
||||
# config.window = 4
|
||||
# config.outer_window = 0
|
||||
# config.left = 0
|
||||
# config.right = 0
|
||||
# config.page_method_name = :page
|
||||
# config.param_name = :page
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
class AddRegistrarIdToWhoisRecord < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :whois_records, :registrar_id, :integer
|
||||
add_index :whois_records, :registrar_id
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150429135339) do
|
||||
ActiveRecord::Schema.define(version: 20150430121807) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -917,11 +917,13 @@ ActiveRecord::Schema.define(version: 20150429135339) do
|
|||
t.string "name"
|
||||
t.text "body"
|
||||
t.json "json"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "registrar_id"
|
||||
end
|
||||
|
||||
add_index "whois_records", ["domain_id"], name: "index_whois_records_on_domain_id", using: :btree
|
||||
add_index "whois_records", ["registrar_id"], name: "index_whois_records_on_registrar_id", using: :btree
|
||||
|
||||
create_table "zonefile_settings", force: :cascade do |t|
|
||||
t.string "origin"
|
||||
|
|
|
@ -1,19 +1,25 @@
|
|||
namespace :whois do
|
||||
desc 'Regenerate whois records at Registry master database (slow)'
|
||||
desc 'Regenerate Registry whois_records table and sync with whois server (slower)'
|
||||
task regenerate: :environment do
|
||||
start = Time.zone.now.to_f
|
||||
print "-----> Regenerate whois records at Registry master database..."
|
||||
Domain.included.find_each(batch_size: 50000).with_index do |d, index|
|
||||
d.update_whois_record
|
||||
print '.' if index % 100 == 0
|
||||
|
||||
@i = 0
|
||||
print "-----> Regenerate Registry whois_records table and sync with whois server..."
|
||||
ActiveRecord::Base.uncached do
|
||||
puts "\n#{@i}"
|
||||
Domain.included.find_in_batches(batch_size: 10000) do |batch|
|
||||
batch.map { |d| d.update_whois_record }
|
||||
puts(@i += 10000)
|
||||
GC.start
|
||||
end
|
||||
end
|
||||
puts "\n-----> all done in #{(Time.zone.now.to_f - start).round(2)} seconds"
|
||||
end
|
||||
|
||||
desc 'Delete whois database data and sync with Registry master database (fast)'
|
||||
desc 'Delete whois database data and import from Registry master database (faster)'
|
||||
task export: :environment do
|
||||
start = Time.zone.now.to_f
|
||||
print "-----> Delete whois database data and sync with Registry master database..."
|
||||
print "-----> Delete whois database data and import from Registry whois_records table..."
|
||||
whois_records = WhoisRecord.pluck(:name, :body, :json)
|
||||
Whois::Record.delete_all
|
||||
Whois::Record.import([:name, :body, :json], whois_records)
|
||||
|
@ -37,18 +43,5 @@ namespace :whois do
|
|||
puts "\n#{e}"
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Force whois schema into exsisting whois database'
|
||||
task force_load: [:environment] do
|
||||
whois_db = "whois_#{Rails.env}"
|
||||
begin
|
||||
puts "\n------------------------ #{whois_db} schema loading ------------------------------\n"
|
||||
ActiveRecord::Base.clear_all_connections!
|
||||
ActiveRecord::Base.establish_connection(whois_db.to_sym)
|
||||
load("#{Rails.root}/db/#{schema_file(whois_db)}")
|
||||
rescue => e
|
||||
puts "\n#{e}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,6 +23,10 @@ describe WhoisRecord do
|
|||
it 'should not have whois body' do
|
||||
@whois_record.body.should == nil
|
||||
end
|
||||
|
||||
it 'should not have registrar' do
|
||||
@whois_record.registrar.should == nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'with valid attributes' do
|
||||
|
@ -41,6 +45,10 @@ describe WhoisRecord do
|
|||
@whois_record.errors.full_messages.should match_array([])
|
||||
end
|
||||
|
||||
it 'should have registrar' do
|
||||
@whois_record.registrar.present?.should == true
|
||||
end
|
||||
|
||||
it 'should have whois body by default' do
|
||||
@whois_record.body.present?.should == true
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue