From fbd7ca3146d3c7995f0627c4243c2e75113ce063 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 14 Apr 2015 16:01:27 +0300 Subject: [PATCH 1/5] Added first version of whois update and sync tasks --- app/models/domain.rb | 23 +++++++++++++---------- lib/tasks/whois.rake | 28 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 lib/tasks/whois.rake diff --git a/app/models/domain.rb b/app/models/domain.rb index d6aa28718..5f3c6ed08 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -53,6 +53,7 @@ class Domain < ActiveRecord::Base end after_save :manage_automatic_statuses after_save :update_whois_body + after_save :update_whois_server validates :name_dirty, domain_name: true, uniqueness: true validates :period, numericality: { only_integer: true } @@ -118,6 +119,10 @@ class Domain < ActiveRecord::Base return period.to_i.months if unit == 'm' return period.to_i.years if unit == 'y' end + + def included + includes(:registrar, :nameservers, {tech_contacts: :registrar}, {admin_contacts: :registrar}) + end end def name=(value) @@ -228,12 +233,6 @@ class Domain < ActiveRecord::Base log end - def update_whois_server - wd = Whois::Domain.find_or_initialize_by(name: name) - wd.whois_body = whois_body - wd.save - end - # rubocop:disable Metrics/MethodLength def update_whois_body self.whois_body = <<-EOS @@ -260,14 +259,12 @@ class Domain < ActiveRecord::Base created: #{registrar.created_at.to_s(:db)} changed: #{registrar.updated_at.to_s(:db)} EOS - - update_whois_server end # rubocop:enable Metrics/MethodLength def contacts_body out = '' - admin_contacts.includes(:registrar).each do |c| + admin_contacts.each do |c| out << 'Admin contact:' out << "name: #{c.name}" out << "email: #{c.email}" @@ -275,7 +272,7 @@ class Domain < ActiveRecord::Base out << "created: #{c.created_at.to_s(:db)}" end - tech_contacts.includes(:registrar).each do |c| + tech_contacts.each do |c| out << 'Tech contact:' out << "name: #{c.name}" out << "email: #{c.email}" @@ -284,4 +281,10 @@ class Domain < ActiveRecord::Base end out end + + def update_whois_server + wd = Whois::Domain.find_or_initialize_by(name: name) + wd.whois_body = whois_body + wd.save + end end diff --git a/lib/tasks/whois.rake b/lib/tasks/whois.rake new file mode 100644 index 000000000..1ca5dcd44 --- /dev/null +++ b/lib/tasks/whois.rake @@ -0,0 +1,28 @@ +namespace :whois do + desc 'Regenerate Registry records and sync whois database' + task sync_all: :environment do + + end + + desc 'Regenerate whois records at Registry master database' + task generate: :environment do + start = Time.zone.now.to_f + print "-----> Update Registry whois records..." + Domain.included.find_each(batch_size: 100000).with_index do |d, index| + d.update_columns(whois_body: d.update_whois_body) + print '.' if index % 100 == 0 + end + puts "\n-----> all done in #{(Time.zone.now.to_f - start).round(2)} seconds" + end + + desc 'Sync whois database' + task sync: :environment do + start = Time.zone.now.to_f + print "-----> Sync whois database..." + Domain.select(:id, :name, :whois_body).find_each(batch_size: 100000).with_index do |d, index| + d.update_whois_server + print '.' if index % 100 == 0 + end + puts "\n-----> all done in #{(Time.zone.now.to_f - start).round(2)} seconds" + end +end From cff06e9286996f226c79dcd6d4d3507c885bc318 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 14 Apr 2015 17:24:26 +0300 Subject: [PATCH 2/5] Added whois rake tasks --- CHANGELOG.md | 4 ++++ lib/tasks/whois.rake | 31 ++++++++++++++++++------------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c78017d2a..670d5392d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +15.04.2015 + +* Added whois tasks, more info with rake -T whois + 02.04.2015 * Depricated DelayedJob, kill all running delayed jobs if needed diff --git a/lib/tasks/whois.rake b/lib/tasks/whois.rake index 1ca5dcd44..29d15fcb8 100644 --- a/lib/tasks/whois.rake +++ b/lib/tasks/whois.rake @@ -1,21 +1,15 @@ namespace :whois do - desc 'Regenerate Registry records and sync whois database' - task sync_all: :environment do - - end - - desc 'Regenerate whois records at Registry master database' - task generate: :environment do + desc 'Delete whois database data and import all from Registry (fast)' + task reset: :environment do start = Time.zone.now.to_f - print "-----> Update Registry whois records..." - Domain.included.find_each(batch_size: 100000).with_index do |d, index| - d.update_columns(whois_body: d.update_whois_body) - print '.' if index % 100 == 0 - end + print "-----> Reset whois database and sync..." + domains = Domain.pluck(:name, :whois_body) + Whois::Domain.delete_all + Whois::Domain.import([:name, :whois_body], domains) puts "\n-----> all done in #{(Time.zone.now.to_f - start).round(2)} seconds" end - desc 'Sync whois database' + desc 'Sync whois database without reset (slow)' task sync: :environment do start = Time.zone.now.to_f print "-----> Sync whois database..." @@ -25,4 +19,15 @@ namespace :whois do end puts "\n-----> all done in #{(Time.zone.now.to_f - start).round(2)} seconds" end + + desc 'Regenerate whois_body at Registry master database (slow)' + task generate: :environment do + start = Time.zone.now.to_f + print "-----> Update Registry records..." + Domain.included.find_each(batch_size: 100000).with_index do |d, index| + d.update_columns(whois_body: d.update_whois_body) + print '.' if index % 100 == 0 + end + puts "\n-----> all done in #{(Time.zone.now.to_f - start).round(2)} seconds" + end end From 6d95c22130cfe2d68a2b8d435ad1b2b297b49ee3 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 14 Apr 2015 17:44:21 +0300 Subject: [PATCH 3/5] Domain rubocop updates --- app/models/domain.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index 5f3c6ed08..64413bd6c 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -121,7 +121,12 @@ class Domain < ActiveRecord::Base end def included - includes(:registrar, :nameservers, {tech_contacts: :registrar}, {admin_contacts: :registrar}) + includes( + :registrar, + :nameservers, + { tech_contacts: :registrar }, + { admin_contacts: :registrar } + ) end end From 6b555d8db772ebcd71e986f82e12b155f5a2b93c Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 14 Apr 2015 18:06:41 +0300 Subject: [PATCH 4/5] Rename Accounting to Billing --- app/views/layouts/application.haml | 2 +- app/views/layouts/registrar/application.haml | 2 +- app/views/registrar/invoices/show.haml | 2 +- config/locales/en.yml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/layouts/application.haml b/app/views/layouts/application.haml index 73c55c1d7..fafc5ef19 100644 --- a/app/views/layouts/application.haml +++ b/app/views/layouts/application.haml @@ -42,7 +42,7 @@ = t('settings') %span.caret %ul.dropdown-menu{role: "menu"} - %li.dropdown-header= t('accounting') + %li.dropdown-header= t('billing') %li= link_to t('bank_statements'), admin_bank_statements_path %li.divider %li.dropdown-header= t('system') diff --git a/app/views/layouts/registrar/application.haml b/app/views/layouts/registrar/application.haml index 85e10adeb..4eec521ba 100644 --- a/app/views/layouts/registrar/application.haml +++ b/app/views/layouts/registrar/application.haml @@ -39,7 +39,7 @@ - if can? :show, Invoice - active_class = ['registrar/invoices'].include?(params[:controller]) ? 'active' :nil - %li{class: active_class}= link_to t('accounting'), registrar_invoices_path + %li{class: active_class}= link_to t('billing'), registrar_invoices_path - if can? :view, :registrar_xml_console - active_class = ['registrar/xml_consoles'].include?(params[:controller]) ? 'active' :nil diff --git a/app/views/registrar/invoices/show.haml b/app/views/registrar/invoices/show.haml index 84d26942e..99752e446 100644 --- a/app/views/registrar/invoices/show.haml +++ b/app/views/registrar/invoices/show.haml @@ -4,7 +4,7 @@ = t('invoice_no', no: @invoice.id) .col-sm-6 %h1.text-right.text-center-xs - = link_to(t('back_to_accounting'), registrar_invoices_path, class: 'btn btn-default') + = link_to(t('back_to_billing'), registrar_invoices_path, class: 'btn btn-default') %hr .row .col-md-6= render 'registrar/invoices/partials/banklinks' diff --git a/config/locales/en.yml b/config/locales/en.yml index 68e2991e1..db35f2d72 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -653,10 +653,9 @@ en: vat: 'VAT (%{vat_prc}%)' unpaid: 'Unpaid' your_current_credit_account_balance_is: 'Your current credit account balance is %{balance} EUR' - accounting: 'Accounting' + billing: 'Billing' your_account: 'Your account' pay_by_bank_link: 'Pay by bank link' - back_to_accounting: 'Back to accounting' issue_date: 'Issue date' due_date: 'Due date' payment_term: 'Payment term' @@ -676,6 +675,7 @@ en: import_th6_bank_statement: 'Import TH6 bank statement' back_to_bank_statements: 'Back to bank statements' back_to_bank_statement: 'Back to bank statement' + back_to_billing: 'Back to billing' imported_at: 'Imported at' bank_statement: 'Bank statement' bank_transactions: 'Bank transactions' From 604505c21bc3369822b2aa02e334caf01ffb3565 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 14 Apr 2015 18:31:50 +0300 Subject: [PATCH 5/5] Invoise bank update, Registrar migration --- app/assets/stylesheets/registrar.sass | 3 +++ app/views/registrar/invoices/show.haml | 3 ++- db/migrate/20150414151357_data_update.rb | 17 +++++++++++++++++ db/schema.rb | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20150414151357_data_update.rb diff --git a/app/assets/stylesheets/registrar.sass b/app/assets/stylesheets/registrar.sass index 0ab63cacb..005bde52a 100644 --- a/app/assets/stylesheets/registrar.sass +++ b/app/assets/stylesheets/registrar.sass @@ -42,3 +42,6 @@ hr background: image_url('bg.jpg') color: white !important background-size: 100% + +.semifooter + padding: 42px 0 80px 0 diff --git a/app/views/registrar/invoices/show.haml b/app/views/registrar/invoices/show.haml index 99752e446..bebe999f1 100644 --- a/app/views/registrar/invoices/show.haml +++ b/app/views/registrar/invoices/show.haml @@ -7,10 +7,11 @@ = link_to(t('back_to_billing'), registrar_invoices_path, class: 'btn btn-default') %hr .row - .col-md-6= render 'registrar/invoices/partials/banklinks' .col-md-6= render 'registrar/invoices/partials/details' .row .col-md-6= render 'registrar/invoices/partials/seller' .col-md-6= render 'registrar/invoices/partials/buyer' .row .col-md-12= render 'registrar/invoices/partials/items' +.row.semifooter + .col-md-12.text-right= render 'registrar/invoices/partials/banklinks' diff --git a/db/migrate/20150414151357_data_update.rb b/db/migrate/20150414151357_data_update.rb new file mode 100644 index 000000000..49cf38901 --- /dev/null +++ b/db/migrate/20150414151357_data_update.rb @@ -0,0 +1,17 @@ +class DataUpdate < ActiveRecord::Migration + def change + Registrar.where( + name: 'EIS', + reg_no: '90010019', + phone: '+372 727 1000', + country_code: 'EE', + vat_no: 'EE101286464', + email: 'info@internet.ee', + state: 'Harjumaa', + city: 'Tallinn', + street: 'Paldiski mnt 80', + zip: '10617', + url: 'www.internet.ee' + ).first_or_create! + end +end diff --git a/db/schema.rb b/db/schema.rb index eb4e3b731..d6b9facb1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150414092249) do +ActiveRecord::Schema.define(version: 20150414151357) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql"