From 2f86b3c76bc6103ba6a8297a8a8649eb5c7a86c4 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 27 Mar 2018 18:34:48 +0300 Subject: [PATCH 1/6] Remove Domain#valid_from As unused. `created_at` is the same value as `valid_from`. #787 --- app/models/domain.rb | 1 + app/models/epp/domain.rb | 1 - app/views/admin/domains/partials/_general.html.erb | 3 --- app/views/admin/domains/partials/_version.haml | 4 +--- app/views/registrant/domains/partials/_general.html.erb | 3 --- db/migrate/20180327151906_remove_domains_valid_from.rb | 5 +++++ db/structure.sql | 3 ++- doc/models_complete.svg | 1 - lib/tasks/dev.rake | 2 -- lib/tasks/import.rake | 1 - spec/models/epp/domain_spec.rb | 6 +----- 11 files changed, 10 insertions(+), 20 deletions(-) create mode 100644 db/migrate/20180327151906_remove_domains_valid_from.rb diff --git a/app/models/domain.rb b/app/models/domain.rb index 9eef0f30f..f8500a206 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -654,6 +654,7 @@ class Domain < ActiveRecord::Base def as_json(_options) hash = super hash['auth_info'] = hash.delete('transfer_code') # API v1 requirement + hash['valid_from'] = hash['created_at'] # API v1 requirement hash end diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index fb01fe38a..2ead51ea3 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -54,7 +54,6 @@ class Epp::Domain < Domain domain.attributes = domain.attrs_from(frame, current_user) domain.attach_default_contacts domain.registered_at = Time.zone.now - domain.valid_from = Time.zone.now period = domain.period.to_i plural_period_unit_name = (domain.period_unit == 'm' ? 'months' : 'years').to_sym diff --git a/app/views/admin/domains/partials/_general.html.erb b/app/views/admin/domains/partials/_general.html.erb index eeeef6eb5..7e09a7756 100644 --- a/app/views/admin/domains/partials/_general.html.erb +++ b/app/views/admin/domains/partials/_general.html.erb @@ -22,9 +22,6 @@ class: 'form-control input-sm' %> -
<%= t(:valid_from) %>
-
<%= l(@domain.valid_from) %>
-
<%= t(:valid_to) %>
<%= l(@domain.valid_to) %>
diff --git a/app/views/admin/domains/partials/_version.haml b/app/views/admin/domains/partials/_version.haml index b15bda0dd..da0a0ece1 100644 --- a/app/views/admin/domains/partials/_version.haml +++ b/app/views/admin/domains/partials/_version.haml @@ -66,12 +66,10 @@ %p = link_to t(:pending_epp), '#', class: 'js-pending' - %td{class: changing_css_class(version, "period", "period_unit", "valid_from", "valid_to")} + %td{class: changing_css_class(version, "period", "period_unit", "valid_to")} %p = "#{domain.period}#{domain.period_unit}" %br - = "#{l(domain.valid_from, format: :date)}" - %br = "#{l(domain.valid_to, format: :date)}" %td diff --git a/app/views/registrant/domains/partials/_general.html.erb b/app/views/registrant/domains/partials/_general.html.erb index 72ae8aad7..eed058437 100644 --- a/app/views/registrant/domains/partials/_general.html.erb +++ b/app/views/registrant/domains/partials/_general.html.erb @@ -22,9 +22,6 @@ class: 'form-control input-sm' %> -
<%= t(:valid_from) %>
-
<%= l(@domain.valid_from) %>
-
<%= t(:valid_to) %>
<%= l(@domain.valid_to) %>
diff --git a/db/migrate/20180327151906_remove_domains_valid_from.rb b/db/migrate/20180327151906_remove_domains_valid_from.rb new file mode 100644 index 000000000..3514fc9f2 --- /dev/null +++ b/db/migrate/20180327151906_remove_domains_valid_from.rb @@ -0,0 +1,5 @@ +class RemoveDomainsValidFrom < ActiveRecord::Migration + def change + remove_column :domains, :valid_from, :datetime + end +end diff --git a/db/structure.sql b/db/structure.sql index a9257ffa3..e5f1dad00 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -872,7 +872,6 @@ CREATE TABLE domains ( registrar_id integer NOT NULL, registered_at timestamp without time zone, status character varying, - valid_from timestamp without time zone, valid_to timestamp without time zone, registrant_id integer NOT NULL, transfer_code character varying NOT NULL, @@ -4679,3 +4678,5 @@ INSERT INTO schema_migrations (version) VALUES ('20180306183549'); INSERT INTO schema_migrations (version) VALUES ('20180308123240'); +INSERT INTO schema_migrations (version) VALUES ('20180327151906'); + diff --git a/doc/models_complete.svg b/doc/models_complete.svg index 296d20c67..d014e0c8d 100644 --- a/doc/models_complete.svg +++ b/doc/models_complete.svg @@ -852,7 +852,6 @@ registrar_id :integer registered_at :datetime status :string -valid_from :datetime valid_to :datetime registrant_id :integer transfer_code :string diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index f4b133ed1..e4c120a8d 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -23,7 +23,6 @@ namespace :dev do period: period, period_unit: period_unit, registered_at: reg_time, - valid_from: reg_time, expire_time: reg_time + period.send(duration.second.to_sym), created_at: reg_time, updated_at: reg_time, @@ -151,7 +150,6 @@ namespace :dev do period: period, period_unit: 'y', registered_at: Time.zone.now, - valid_from: Time.zone.now, expire_time: Time.zone.now + period.years, registrar: registrar, registrant: registrants.sample) diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index f26ad252f..45f3cae99 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -337,7 +337,6 @@ namespace :import do name registrar_id registered_at - valid_from valid_to transfer_code created_at diff --git a/spec/models/epp/domain_spec.rb b/spec/models/epp/domain_spec.rb index de0b8f4e1..402305527 100644 --- a/spec/models/epp/domain_spec.rb +++ b/spec/models/epp/domain_spec.rb @@ -21,11 +21,7 @@ RSpec.describe Epp::Domain, db: false do expect(domain.registered_at).to eq(Time.zone.parse('05.07.2010')) end - it 'has :valid_from set to now' do - expect(domain.valid_from).to eq(Time.zone.parse('05.07.2010')) - end - - it 'has :valid_to set to the beginning of next day after :valid_from' do + it 'has :valid_to set to the beginning of next day after :registered_at' do expect(domain.valid_to).to eq(Time.zone.parse('06.07.2011 00:00')) end end From 77104582f79107af4c38f7c4fab95f4ac969d585 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 31 Mar 2018 12:55:08 +0300 Subject: [PATCH 2/6] Fix attribute name --- app/models/domain.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index f8500a206..d5c860913 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -654,7 +654,7 @@ class Domain < ActiveRecord::Base def as_json(_options) hash = super hash['auth_info'] = hash.delete('transfer_code') # API v1 requirement - hash['valid_from'] = hash['created_at'] # API v1 requirement + hash['valid_from'] = hash['registered_at'] # API v1 requirement hash end From c675512b22a566ba0b5d9ef7690c92b747fa5cde Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 31 Mar 2018 23:31:40 +0300 Subject: [PATCH 3/6] Change `domains.valid_to` DB column to NOT NULL #800 --- app/models/whois_record.rb | 2 +- app/views/epp/domains/create.xml.builder | 2 +- app/views/epp/domains/info.xml.builder | 2 +- app/views/epp/domains/partials/_transfer.xml.builder | 2 +- app/views/epp/domains/renew.xml.builder | 2 +- .../20180331200125_change_domains_valid_to_to_not_null.rb | 5 +++++ db/structure.sql | 4 +++- spec/factories/domain.rb | 1 + 8 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20180331200125_change_domains_valid_to_to_not_null.rb diff --git a/app/models/whois_record.rb b/app/models/whois_record.rb index bd16e0c99..45cff4036 100644 --- a/app/models/whois_record.rb +++ b/app/models/whois_record.rb @@ -48,7 +48,7 @@ class WhoisRecord < ActiveRecord::Base h[:status] = domain.statuses.map { |x| status_map[x] || x } h[:registered] = domain.registered_at.try(:to_s, :iso8601) h[:changed] = domain.updated_at.try(:to_s, :iso8601) - h[:expire] = domain.valid_to.try(:to_date).try(:to_s) + h[:expire] = domain.valid_to.to_date.to_s h[:outzone] = domain.outzone_at.try(:to_date).try(:to_s) h[:delete] = [domain.delete_at, domain.force_delete_at].compact.min.try(:to_date).try(:to_s) diff --git a/app/views/epp/domains/create.xml.builder b/app/views/epp/domains/create.xml.builder index 213a2aa8f..2293f5657 100644 --- a/app/views/epp/domains/create.xml.builder +++ b/app/views/epp/domains/create.xml.builder @@ -8,7 +8,7 @@ xml.epp_head do xml.tag!('domain:creData', 'xmlns:domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd') do xml.tag!('domain:name', @domain.name) xml.tag!('domain:crDate', @domain.created_at.try(:iso8601)) - xml.tag!('domain:exDate', @domain.valid_to.try(:iso8601)) + xml.tag!('domain:exDate', @domain.valid_to.iso8601) end end diff --git a/app/views/epp/domains/info.xml.builder b/app/views/epp/domains/info.xml.builder index 8bf169acd..2d10f8baf 100644 --- a/app/views/epp/domains/info.xml.builder +++ b/app/views/epp/domains/info.xml.builder @@ -48,7 +48,7 @@ xml.epp_head do xml.tag!('domain:upDate', @domain.updated_at.try(:iso8601)) end - xml.tag!('domain:exDate', @domain.valid_to.try(:iso8601)) + xml.tag!('domain:exDate', @domain.valid_to.iso8601) # TODO Make domain transferrable #xml.tag!('domain:trDate', @domain.transferred_at) if @domain.transferred_at diff --git a/app/views/epp/domains/partials/_transfer.xml.builder b/app/views/epp/domains/partials/_transfer.xml.builder index 151af28b3..bfcc7db94 100644 --- a/app/views/epp/domains/partials/_transfer.xml.builder +++ b/app/views/epp/domains/partials/_transfer.xml.builder @@ -5,5 +5,5 @@ builder.tag!('domain:trnData', 'xmlns:domain' => 'https://epp.tld.ee/schema/doma builder.tag!('domain:reDate', dt.transfer_requested_at.try(:iso8601)) builder.tag!('domain:acID', dt.old_registrar.code) builder.tag!('domain:acDate', dt.transferred_at.try(:iso8601) || dt.wait_until.try(:iso8601)) - builder.tag!('domain:exDate', dt.domain_valid_to.try(:iso8601)) + builder.tag!('domain:exDate', dt.domain_valid_to.iso8601) end diff --git a/app/views/epp/domains/renew.xml.builder b/app/views/epp/domains/renew.xml.builder index 5d03c7128..e407ff0e7 100644 --- a/app/views/epp/domains/renew.xml.builder +++ b/app/views/epp/domains/renew.xml.builder @@ -7,7 +7,7 @@ xml.epp_head do xml.resData do xml.tag!('domain:renData', 'xmlns:domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd') do xml.tag!('domain:name', @domain[:name]) - xml.tag!('domain:exDate', @domain.valid_to.try(:iso8601)) + xml.tag!('domain:exDate', @domain.valid_to.iso8601) end end diff --git a/db/migrate/20180331200125_change_domains_valid_to_to_not_null.rb b/db/migrate/20180331200125_change_domains_valid_to_to_not_null.rb new file mode 100644 index 000000000..049b08806 --- /dev/null +++ b/db/migrate/20180331200125_change_domains_valid_to_to_not_null.rb @@ -0,0 +1,5 @@ +class ChangeDomainsValidToToNotNull < ActiveRecord::Migration + def change + change_column_null :domains, :valid_to, false + end +end diff --git a/db/structure.sql b/db/structure.sql index 374b17b5b..2e662f6f5 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -873,7 +873,7 @@ CREATE TABLE domains ( registered_at timestamp without time zone, status character varying, valid_from timestamp without time zone, - valid_to timestamp without time zone, + valid_to timestamp without time zone NOT NULL, registrant_id integer NOT NULL, transfer_code character varying NOT NULL, created_at timestamp without time zone, @@ -4695,3 +4695,5 @@ INSERT INTO schema_migrations (version) VALUES ('20180309053921'); INSERT INTO schema_migrations (version) VALUES ('20180309054510'); +INSERT INTO schema_migrations (version) VALUES ('20180331200125'); + diff --git a/spec/factories/domain.rb b/spec/factories/domain.rb index fc4d3a97b..8abac339c 100644 --- a/spec/factories/domain.rb +++ b/spec/factories/domain.rb @@ -3,6 +3,7 @@ FactoryBot.define do sequence(:name) { |n| "test#{n}.com" } period 1 period_unit 'y' # Year + valid_to Time.zone.parse('2010-07-05') registrar registrant From b694f0c2f643d2d61d65927b5b1b72c1e1790129 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 31 Mar 2018 12:00:19 +0300 Subject: [PATCH 4/6] Remove unused methods --- app/models/domain.rb | 11 ----------- app/models/epp/domain.rb | 10 ---------- app/models/registrar.rb | 5 ----- app/models/whois_record.rb | 14 -------------- 4 files changed, 40 deletions(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index 9eef0f30f..bb671dc2d 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -220,17 +220,6 @@ class Domain < ActiveRecord::Base end class << self - def included - includes( - :registrant, - :registrar, - :nameservers, - :whois_record, - { tech_contacts: :registrar }, - { admin_contacts: :registrar } - ) - end - def nameserver_required? Setting.nameserver_required end diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index fb01fe38a..43ad15bc7 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -38,16 +38,6 @@ class Epp::Domain < Domain ok end - before_save :link_contacts - def link_contacts - #TODO: cleanup cache if we think to cache dynamic statuses - end - - after_destroy :unlink_contacts - def unlink_contacts - #TODO: cleanup cache if we think to cache dynamic statuses - end - class << self def new_from_epp(frame, current_user) domain = Epp::Domain.new diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 5fd0008b5..525415cbe 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -105,11 +105,6 @@ class Registrar < ActiveRecord::Base cash_account.account_activities.create!(args) end - def credit!(args) - args[:currency] = 'EUR' - cash_account.account_activities.create!(args) - end - def address [street, city, state, zip].reject(&:blank?).compact.join(', ') end diff --git a/app/models/whois_record.rb b/app/models/whois_record.rb index bd16e0c99..e0ea4253d 100644 --- a/app/models/whois_record.rb +++ b/app/models/whois_record.rb @@ -9,20 +9,6 @@ class WhoisRecord < ActiveRecord::Base after_save :update_whois_server after_destroy :destroy_whois_record - class << self - def included - includes( - domain: [ - :registrant, - :registrar, - :nameservers, - { tech_contacts: :registrar }, - { admin_contacts: :registrar } - ] - ) - end - end - def self.find_by_name(name) WhoisRecord.where("lower(name) = ?", name.downcase) end From ce3b04bff0611e1ec4928fccd00ff889ee425d1b Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 9 Apr 2018 00:42:22 +0300 Subject: [PATCH 5/6] Do not show discarded domain details in WHOIS #789 --- app/models/whois_record.rb | 9 ++++++++- app/views/for_models/whois_discarded.erb | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 app/views/for_models/whois_discarded.erb diff --git a/app/models/whois_record.rb b/app/models/whois_record.rb index bd16e0c99..9f9b26c43 100644 --- a/app/models/whois_record.rb +++ b/app/models/whois_record.rb @@ -37,6 +37,12 @@ class WhoisRecord < ActiveRecord::Base h = HashWithIndifferentAccess.new return h if domain.blank? + if domain.discarded? + h[:name] = domain.name + h[:status] = ['deleteCandidate'] + return h + end + status_map = { 'ok' => 'ok (paid and in zone)' } @@ -102,7 +108,8 @@ class WhoisRecord < ActiveRecord::Base end def generated_body - template = Rails.root.join("app/views/for_models/whois.erb".freeze) + template_name = domain.discarded? ? 'whois_discarded.erb' : 'whois.erb' + template = Rails.root.join("app/views/for_models/#{template_name}".freeze) ERB.new(template.read, nil, "-").result(binding) end # rubocop:enable Metrics/MethodLength diff --git a/app/views/for_models/whois_discarded.erb b/app/views/for_models/whois_discarded.erb new file mode 100644 index 000000000..ecaa6f9af --- /dev/null +++ b/app/views/for_models/whois_discarded.erb @@ -0,0 +1,8 @@ +Estonia .ee Top Level Domain WHOIS server + +Domain: +name: <%= json['name'] %> +status: <%= json['status'] %> + +Estonia .ee Top Level Domain WHOIS server +More information at http://internet.ee From 4f17e3f48762e32df37741d61181d2a10ff6fdfc Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 16 Apr 2018 10:55:45 +0300 Subject: [PATCH 6/6] Update nokogiri gem --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 6d9105baf..efa504d8e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -275,7 +275,7 @@ GEM multi_json (1.12.1) multi_xml (0.6.0) netrc (0.11.0) - nokogiri (1.8.1) + nokogiri (1.8.2) mini_portile2 (~> 2.3.0) nori (2.6.0) open4 (1.3.4)