From 50346c80c877d5136a7d96878e36a7cbe18bd951 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 15 Jun 2015 12:57:57 +0300 Subject: [PATCH 01/15] Move statuses to domain #2623 --- app/models/admin_user.rb | 2 +- app/models/domain.rb | 24 +++++----- app/models/epp/domain.rb | 4 +- ...20150612125720_refactor_domain_statuses.rb | 15 +++++++ .../20150612123111_add_statuses_to_domain.rb | 5 +++ db/schema.rb | 44 +++++++++++-------- spec/epp/domain_spec.rb | 14 +++--- spec/models/domain_spec.rb | 15 +++---- 8 files changed, 78 insertions(+), 45 deletions(-) create mode 100644 db/data/20150612125720_refactor_domain_statuses.rb create mode 100644 db/migrate/20150612123111_add_statuses_to_domain.rb diff --git a/app/models/admin_user.rb b/app/models/admin_user.rb index 0634baef4..e062bb1d6 100644 --- a/app/models/admin_user.rb +++ b/app/models/admin_user.rb @@ -2,7 +2,7 @@ class AdminUser < User validates :username, :country_code, :roles, presence: true validates :identity_code, uniqueness: true, allow_blank: true validates :identity_code, presence: true, if: -> { country_code == 'EE' } - validates :email, presence: true + validates :email, presence: true validates :password, :password_confirmation, presence: true, if: :new_record? validates :password_confirmation, presence: true, if: :encrypted_password_changed? validate :validate_identity_code, if: -> { country_code == 'EE' } diff --git a/app/models/domain.rb b/app/models/domain.rb index 61ad23d43..76ee88afe 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -63,13 +63,16 @@ class Domain < ActiveRecord::Base true end + before_save :manage_automatic_statuses + before_save :touch_always_version def touch_always_version self.updated_at = Time.zone.now end - after_save :manage_automatic_statuses after_save :update_whois_record + after_initialize -> { self.statuses = [] if statuses.nil? } + validates :name_dirty, domain_name: true, uniqueness: true validates :puny_label, length: { maximum: 63 } validates :period, numericality: { only_integer: true } @@ -154,9 +157,10 @@ class Domain < ActiveRecord::Base d = Domain.where('valid_to <= ?', Time.zone.now) d.each do |x| next unless x.expirable? - x.domain_statuses.create(value: DomainStatus::EXPIRED) + x.statuses << DomainStatus::EXPIRED # TODO: This should be managed by automatic_statuses - x.domain_statuses.where(value: DomainStatus::OK).destroy_all + x.statuses.delete(DomainStatus::OK) + x.save(validate: false) end STDOUT << "#{Time.zone.now.utc} - Successfully expired #{d.count} domains\n" unless Rails.env.test? @@ -168,9 +172,10 @@ class Domain < ActiveRecord::Base d = Domain.where('outzone_at <= ?', Time.zone.now) d.each do |x| next unless x.server_holdable? - x.domain_statuses.create(value: DomainStatus::SERVER_HOLD) + x.statuses << DomainStatus::SERVER_HOLD # TODO: This should be managed by automatic_statuses - x.domain_statuses.where(value: DomainStatus::OK).destroy_all + x.statuses.delete(DomainStatus::OK) + x.save end STDOUT << "#{Time.zone.now.utc} - Successfully set server_hold to #{d.count} domains\n" unless Rails.env.test? @@ -445,14 +450,13 @@ class Domain < ActiveRecord::Base def manage_automatic_statuses # domain_statuses.create(value: DomainStatus::DELETE_CANDIDATE) if delete_candidateable? - if domain_statuses.empty? && valid? - domain_statuses.create(value: DomainStatus::OK) - elsif domain_statuses.length > 1 || !valid? - domain_statuses.find_by(value: DomainStatus::OK).try(:destroy) + if statuses.empty? && valid? + statuses << DomainStatus::OK + elsif statuses.length > 1 || !valid? + statuses.delete(DomainStatus::OK) end # otherwise domain_statuses are in old state for domain object - domain_statuses.reload end def children_log diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 4e7dc7f62..b2aaac28b 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -439,8 +439,8 @@ class Epp::Domain < Domain self.period = period self.period_unit = unit - domain_statuses.where(value: DomainStatus::SERVER_HOLD).destroy_all - domain_statuses.where(value: DomainStatus::EXPIRED).destroy_all + statuses.delete(DomainStatus::SERVER_HOLD) + statuses.delete(DomainStatus::EXPIRED) save end diff --git a/db/data/20150612125720_refactor_domain_statuses.rb b/db/data/20150612125720_refactor_domain_statuses.rb new file mode 100644 index 000000000..679a6642b --- /dev/null +++ b/db/data/20150612125720_refactor_domain_statuses.rb @@ -0,0 +1,15 @@ +class RefactorDomainStatuses < ActiveRecord::Migration + def self.up + Domain.all.each do |x| + x.statuses = [] + x.domain_statuses.each do |ds| + x.statuses << ds.value + end + x.save + end + end + + def self.down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/migrate/20150612123111_add_statuses_to_domain.rb b/db/migrate/20150612123111_add_statuses_to_domain.rb new file mode 100644 index 000000000..3e2b8a922 --- /dev/null +++ b/db/migrate/20150612123111_add_statuses_to_domain.rb @@ -0,0 +1,5 @@ +class AddStatusesToDomain < ActiveRecord::Migration + def change + add_column :domains, :statuses, :string, array: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 4dd3a3743..1e14d1c8e 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: 20150609103333) do +ActiveRecord::Schema.define(version: 20150612123111) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -19,7 +19,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do create_table "account_activities", force: :cascade do |t| t.integer "account_id" t.integer "invoice_id" - t.decimal "sum", precision: 10, scale: 2 + t.decimal "sum", precision: 8, scale: 2 t.string "currency" t.integer "bank_transaction_id" t.datetime "created_at" @@ -36,7 +36,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do create_table "accounts", force: :cascade do |t| t.integer "registrar_id" t.string "account_type" - t.decimal "balance", precision: 10, scale: 2, default: 0.0, null: false + t.decimal "balance", precision: 8, scale: 2, default: 0.0, null: false t.datetime "created_at" t.datetime "updated_at" t.string "currency" @@ -98,7 +98,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do t.string "buyer_name" t.string "document_no" t.string "description" - t.decimal "sum", precision: 10, scale: 2 + t.decimal "sum", precision: 8, scale: 2 t.string "reference_no" t.datetime "paid_at" t.datetime "created_at" @@ -114,7 +114,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do t.string "vk_rec_id" t.string "vk_stamp" t.string "vk_t_no" - t.decimal "vk_amount", precision: 10, scale: 2 + t.decimal "vk_amount", precision: 8, scale: 2 t.string "vk_curr" t.string "vk_rec_acc" t.string "vk_rec_name" @@ -203,6 +203,12 @@ ActiveRecord::Schema.define(version: 20150609103333) do t.string "updator_str" end + create_table "data_migrations", id: false, force: :cascade do |t| + t.string "version", null: false + end + + add_index "data_migrations", ["version"], name: "unique_data_migrations", unique: true, using: :btree + create_table "delegation_signers", force: :cascade do |t| t.integer "domain_id" t.string "key_tag" @@ -306,6 +312,8 @@ ActiveRecord::Schema.define(version: 20150609103333) do t.datetime "registrant_verification_asked_at" t.string "registrant_verification_token" t.json "pending_json" + t.datetime "force_delete_at" + t.string "statuses", array: true end add_index "domains", ["delete_at"], name: "index_domains_on_delete_at", using: :btree @@ -328,10 +336,10 @@ ActiveRecord::Schema.define(version: 20150609103333) do create_table "invoice_items", force: :cascade do |t| t.integer "invoice_id" - t.string "description", null: false + t.string "description", null: false t.string "unit" t.integer "amount" - t.decimal "price", precision: 10, scale: 2 + t.decimal "price", precision: 8, scale: 2 t.datetime "created_at" t.datetime "updated_at" t.string "creator_str" @@ -341,20 +349,20 @@ ActiveRecord::Schema.define(version: 20150609103333) do add_index "invoice_items", ["invoice_id"], name: "index_invoice_items_on_invoice_id", using: :btree create_table "invoices", force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "invoice_type", null: false - t.datetime "due_date", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "invoice_type", null: false + t.datetime "due_date", null: false t.string "payment_term" - t.string "currency", null: false + t.string "currency", null: false t.string "description" t.string "reference_no" - t.decimal "vat_prc", precision: 10, scale: 2, null: false + t.decimal "vat_prc", precision: 8, scale: 2, null: false t.datetime "paid_at" t.integer "seller_id" - t.string "seller_name", null: false + t.string "seller_name", null: false t.string "seller_reg_no" - t.string "seller_iban", null: false + t.string "seller_iban", null: false t.string "seller_bank" t.string "seller_swift" t.string "seller_vat_no" @@ -368,7 +376,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do t.string "seller_email" t.string "seller_contact_name" t.integer "buyer_id" - t.string "buyer_name", null: false + t.string "buyer_name", null: false t.string "buyer_reg_no" t.string "buyer_country_code" t.string "buyer_state" @@ -382,7 +390,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do t.string "updator_str" t.integer "number" t.datetime "cancelled_at" - t.decimal "sum_cache", precision: 10, scale: 2 + t.decimal "sum_cache", precision: 8, scale: 2 end add_index "invoices", ["buyer_id"], name: "index_invoices_on_buyer_id", using: :btree @@ -983,7 +991,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do t.text "crt" t.string "type" t.string "registrant_ident" - t.string "encrypted_password", default: "" + t.string "encrypted_password", default: "", null: false t.datetime "remember_created_at" t.integer "failed_attempts", default: 0, null: false t.datetime "locked_at" diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index da1653e78..62c17c577 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -2079,9 +2079,10 @@ describe 'EPP Domain', epp: true do Domain.start_expire_period Domain.start_redemption_grace_period - domain.domain_statuses.where(value: DomainStatus::EXPIRED).count.should == 1 - domain.domain_statuses.where(value: DomainStatus::SERVER_HOLD).count.should == 1 - domain.domain_statuses.where(value: DomainStatus::OK).count.should == 0 + domain.reload + domain.statuses.include?(DomainStatus::EXPIRED).should == true + domain.statuses.include?(DomainStatus::SERVER_HOLD).should == true + domain.statuses.include?(DomainStatus::OK).should == false exp_date = domain.valid_to.to_date @@ -2095,9 +2096,10 @@ describe 'EPP Domain', epp: true do response[:results][0][:msg].should == 'Command completed successfully' response[:results][0][:result_code].should == '1000' - domain.domain_statuses.where(value: DomainStatus::EXPIRED).count.should == 0 - domain.domain_statuses.where(value: DomainStatus::SERVER_HOLD).count.should == 0 - domain.domain_statuses.where(value: DomainStatus::OK).count.should == 1 + domain.reload + domain.statuses.include?(DomainStatus::EXPIRED).should == false + domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false + domain.statuses.include?(DomainStatus::OK).should == true domain.reload domain.valid_to.should be_within(5).of(new_valid_to) diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index bb2a5e23f..cc2946ced 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -441,24 +441,23 @@ describe Domain do it 'manages statuses automatically' do d = Fabricate(:domain) - expect(d.domain_statuses.count).to eq(1) - expect(d.domain_statuses.first.value).to eq(DomainStatus::OK) + expect(d.statuses.count).to eq(1) + expect(d.statuses.first).to eq(DomainStatus::OK) d.period = 2 d.save d.reload + expect(d.statuses.count).to eq(1) + expect(d.statuses.first).to eq(DomainStatus::OK) - expect(d.domain_statuses.count).to eq(1) - expect(d.domain_statuses.first.reload.value).to eq(DomainStatus::OK) - - d.domain_statuses.build(value: DomainStatus::CLIENT_DELETE_PROHIBITED) + d.statuses << DomainStatus::CLIENT_DELETE_PROHIBITED d.save d.reload - expect(d.domain_statuses.count).to eq(1) - expect(d.domain_statuses.first.value).to eq(DomainStatus::CLIENT_DELETE_PROHIBITED) + expect(d.statuses.count).to eq(1) + expect(d.statuses.first).to eq(DomainStatus::CLIENT_DELETE_PROHIBITED) end with_versioning do From 6229d6cb352453a82abe9c8ce32cc1727334b7f8 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 15 Jun 2015 16:35:26 +0300 Subject: [PATCH 02/15] Fix tests #2623 --- app/models/domain.rb | 13 +++++-- app/models/epp/domain.rb | 41 +++++--------------- app/views/epp/domains/info.xml.builder | 5 +-- config/locales/en.yml | 2 + spec/epp/domain_spec.rb | 52 +++++++++++++------------- 5 files changed, 48 insertions(+), 65 deletions(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index 76ee88afe..d792884e5 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -122,6 +122,13 @@ class Domain < ActiveRecord::Base validate :validate_nameserver_ips + validate :statuses_uniqueness + def statuses_uniqueness + return if statuses.uniq == statuses + errors.add(:statuses, :taken) + end + + attr_accessor :registrant_typeahead, :update_me, :deliver_emails, :epp_pending_update, :epp_pending_delete @@ -245,13 +252,13 @@ class Domain < ActiveRecord::Base def expirable? return false if valid_to > Time.zone.now - domain_statuses.where(value: DomainStatus::EXPIRED).empty? + !statuses.include?(DomainStatus::EXPIRED) end def server_holdable? return false if outzone_at > Time.zone.now - return false if domain_statuses.where(value: DomainStatus::SERVER_HOLD).any? - return false if domain_statuses.where(value: DomainStatus::SERVER_MANUAL_INZONE).any? + return false if statuses.include?(DomainStatus::SERVER_HOLD) + return false if statuses.include?(DomainStatus::SERVER_MANUAL_INZONE) true end diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index b2aaac28b..3cd3e03cc 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -110,10 +110,12 @@ class Epp::Domain < Domain at[:period_unit] = Epp::Domain.parse_period_unit_from_frame(frame) || 'y' + # at[:statuses] = domain_statuses_attrs(frame, action) + # binding.pry at[:nameservers_attributes] = nameservers_attrs(frame, action) at[:admin_domain_contacts_attributes] = admin_domain_contacts_attrs(frame, action) at[:tech_domain_contacts_attributes] = tech_domain_contacts_attrs(frame, action) - at[:domain_statuses_attributes] = domain_statuses_attrs(frame, action) + # at[:domain_statuses_attributes] = domain_statuses_attrs(frame, action) if new_record? dnskey_frame = frame.css('extension create') @@ -235,24 +237,6 @@ class Epp::Domain < Domain attrs end - def domain_status_list_from(frame) - status_list = [] - - frame.css('status').each do |x| - unless DomainStatus::CLIENT_STATUSES.include?(x['s']) - add_epp_error('2303', 'status', x['s'], [:domain_statuses, :not_found]) - next - end - - status_list << { - value: x['s'], - description: x.text - } - end - - status_list - end - # rubocop: disable Metrics/PerceivedComplexity # rubocop: disable Metrics/CyclomaticComplexity def dnskeys_attrs(frame, action) @@ -336,14 +320,10 @@ class Epp::Domain < Domain if action == 'rem' to_destroy = [] status_list.each do |x| - status = domain_statuses.find_by(value: x[:value]) - if status.blank? - add_epp_error('2303', 'status', x[:value], [:domain_statuses, :not_found]) + if statuses.include?(x) + to_destroy << x else - to_destroy << { - id: status.id, - _destroy: 1 - } + add_epp_error('2303', 'status', x, [:domain_statuses, :not_found]) end end @@ -362,10 +342,7 @@ class Epp::Domain < Domain next end - status_list << { - value: x['s'], - description: x.text - } + status_list << x['s'] end status_list @@ -392,13 +369,13 @@ class Epp::Domain < Domain at[:admin_domain_contacts_attributes] += at_add[:admin_domain_contacts_attributes] at[:tech_domain_contacts_attributes] += at_add[:tech_domain_contacts_attributes] at[:dnskeys_attributes] += at_add[:dnskeys_attributes] - at[:domain_statuses_attributes] += at_add[:domain_statuses_attributes] + at[:statuses] = statuses - domain_statuses_attrs(frame.css('rem'), 'rem') + domain_statuses_attrs(frame.css('add'), 'add') + # at[:statuses] += at_add[:domain_statuses_attributes] if frame.css('registrant').present? && frame.css('registrant').attr('verified').to_s.downcase != 'yes' registrant_verification_asked! end self.deliver_emails = true # turn on email delivery for epp - errors.empty? && super(at) end diff --git a/app/views/epp/domains/info.xml.builder b/app/views/epp/domains/info.xml.builder index ad1db1cb2..4f20cb293 100644 --- a/app/views/epp/domains/info.xml.builder +++ b/app/views/epp/domains/info.xml.builder @@ -8,9 +8,8 @@ xml.epp_head do xml.tag!('domain:infData', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do xml.tag!('domain:name', @domain.name) xml.tag!('domain:roid', @domain.roid) - @domain.domain_statuses.each do |ds| - xml.tag!('domain:status', ds.description, 's' => ds.value) unless ds.description.blank? - xml.tag!('domain:status', 's' => ds.value) if ds.description.blank? + @domain.statuses.each do |s| + xml.tag!('domain:status', 's' => s) end xml.tag!('domain:registrant', @domain.registrant_code) diff --git a/config/locales/en.yml b/config/locales/en.yml index 4522f1215..16b26c2b2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -100,6 +100,8 @@ en: invalid: 'Statuses are invalid' not_found: 'Status was not found' taken: 'Status already exists on this domain' + statuses: + taken: 'Status already exists on this domain' registrar: blank: 'Registrar is missing' dnskeys: diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 62c17c577..21b297361 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -1592,11 +1592,10 @@ describe 'EPP Domain', epp: true do new_contact = d.tech_contacts.find_by(code: 'FIXED:MAK21') new_contact.should be_truthy - d.domain_statuses.count.should == 2 - d.domain_statuses.first.description.should == 'Payment overdue.' - d.domain_statuses.first.value.should == 'clientHold' + d.statuses.count.should == 2 + d.statuses.include?('clientHold').should == true + d.statuses.include?('clientUpdateProhibited').should == true - d.domain_statuses.last.value.should == 'clientUpdateProhibited' d.dnskeys.count.should == 2 response = epp_plain_request(xml) @@ -1621,39 +1620,39 @@ describe 'EPP Domain', epp: true do response[:results][2][:msg].should == 'Contact already exists on this domain [contact_code_cache]' response[:results][2][:value].should == 'FIXED:MAK21' - response[:results][3][:msg].should == 'Status already exists on this domain [value]' - if response[:results][3][:value] == 'clientHold' - response[:results][3][:value].should == 'clientHold' - else - response[:results][3][:value].should == 'clientUpdateProhibited' - end + # response[:results][3][:msg].should == 'Status already exists on this domain [value]' + # if response[:results][3][:value] == 'clientHold' + # response[:results][3][:value].should == 'clientHold' + # else + # response[:results][3][:value].should == 'clientUpdateProhibited' + # end - response[:results][4][:msg].should == 'Status already exists on this domain [value]' - if response[:results][4][:value] == 'clientHold' - response[:results][4][:value].should == 'clientHold' - else - response[:results][4][:value].should == 'clientUpdateProhibited' - end + # response[:results][4][:msg].should == 'Status already exists on this domain [value]' + # if response[:results][4][:value] == 'clientHold' + # response[:results][4][:value].should == 'clientHold' + # else + # response[:results][4][:value].should == 'clientUpdateProhibited' + # end - response[:results][5][:msg].should == 'Public key already exists [public_key]' - if response[:results][5][:value] == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' - response[:results][5][:value].should == + response[:results][3][:msg].should == 'Public key already exists [public_key]' + if response[:results][3][:value] == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' + response[:results][3][:value].should == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' else - response[:results][5][:value].should == + response[:results][3][:value].should == '841936717ae427ace63c28d04918569a841936717ae427ace63c28d0' end - response[:results][6][:msg].should == 'Public key already exists [public_key]' - if response[:results][6][:value] == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' - response[:results][6][:value].should == + response[:results][4][:msg].should == 'Public key already exists [public_key]' + if response[:results][4][:value] == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' + response[:results][4][:value].should == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' else - response[:results][6][:value].should == + response[:results][4][:value].should == '841936717ae427ace63c28d04918569a841936717ae427ace63c28d0' end - d.domain_statuses.count.should == 2 + d.statuses.count.should == 2 end it 'updates domain with registrant change what triggers action pending' do @@ -2124,7 +2123,7 @@ describe 'EPP Domain', epp: true do ### INFO ### it 'returns domain info' do - domain.domain_statuses.build(value: DomainStatus::CLIENT_HOLD, description: 'Payment overdue.') + domain.statuses << DomainStatus::CLIENT_HOLD domain.nameservers.build(hostname: 'ns1.example.com', ipv4: '192.168.1.1', ipv6: '1080:0:0:0:8:800:200C:417A') domain.dnskeys.build( @@ -2159,7 +2158,6 @@ describe 'EPP Domain', epp: true do inf_data = response[:parsed].css('resData infData') inf_data.css('name').text.should == domain.name - inf_data.css('status').text.should == 'Payment overdue.' inf_data.css('status').first[:s].should == 'clientHold' inf_data.css('registrant').text.should == domain.registrant_code inf_data.css('roid').text.should == domain.roid From 6ad458e20f5fc8bccd2178eefc94a63237261d4f Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 15 Jun 2015 16:54:01 +0300 Subject: [PATCH 03/15] More test fixes #2623 --- app/models/domain.rb | 14 ++++---------- app/models/epp/domain.rb | 4 +--- spec/epp/domain_spec.rb | 19 +++++++++++++------ 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index d792884e5..22dbec5be 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -244,12 +244,6 @@ class Domain < ActiveRecord::Base domain_transfers.find_by(status: DomainTransfer::PENDING) end - def can_be_deleted? - (domain_statuses.pluck(:value) & %W( - #{DomainStatus::SERVER_DELETE_PROHIBITED} - )).empty? - end - def expirable? return false if valid_to > Time.zone.now !statuses.include?(DomainStatus::EXPIRED) @@ -338,9 +332,7 @@ class Domain < ActiveRecord::Base end def pending_delete? - (domain_statuses.pluck(:value) & %W( - #{DomainStatus::PENDING_DELETE} - )).present? + statuses.include?(DomainStatus::PENDING_DELETE) end def pending_delete! @@ -348,7 +340,9 @@ class Domain < ActiveRecord::Base self.epp_pending_delete = true # for epp return true unless registrant_verification_asked? - domain_statuses.create(value: DomainStatus::PENDING_DELETE) + statuses << DomainStatus::PENDING_DELETE + save(validate: false) # should check if this did succeed + DomainMailer.pending_deleted(self).deliver_now end diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 3cd3e03cc..44ef0fd84 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -659,9 +659,7 @@ class Epp::Domain < Domain begin errors.add(:base, :domain_status_prohibits_operation) return false - end if (domain_statuses.pluck(:value) & %W( - #{DomainStatus::CLIENT_DELETE_PROHIBITED} - )).any? + end if statuses.include?(DomainStatus::CLIENT_DELETE_PROHIBITED) true end diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 21b297361..9713af905 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -1839,10 +1839,11 @@ describe 'EPP Domain', epp: true do response[:results][0][:msg].should == 'Command completed successfully' response[:results][0][:result_code].should == '1000' + d.reload d.dnskeys.count.should == 1 - d.domain_statuses.count.should == 1 - d.domain_statuses.first.value.should == 'clientUpdateProhibited' + d.statuses.count.should == 1 + d.statuses.first.should == 'clientUpdateProhibited' rem_ns = d.nameservers.find_by(hostname: 'ns1.example.com') rem_ns.should be_falsey @@ -1861,8 +1862,12 @@ describe 'EPP Domain', epp: true do response[:results][1][:value].should == 'FIXED:CITIZEN_1234' response[:results][2][:result_code].should == '2303' - response[:results][2][:msg].should == 'Status was not found' - response[:results][2][:value].should == 'clientHold' + response[:results][2][:msg].should == 'DS was not found' + response[:results][2][:value].should == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f' + + response[:results][3][:result_code].should == '2303' + response[:results][3][:msg].should == 'Status was not found' + response[:results][3][:value].should == 'clientHold' end it 'does not remove server statuses' do @@ -2318,7 +2323,8 @@ describe 'EPP Domain', epp: true do end it 'does not delete domain with specific status' do - domain.domain_statuses.create(value: DomainStatus::CLIENT_DELETE_PROHIBITED) + domain.statuses << DomainStatus::CLIENT_DELETE_PROHIBITED + domain.save response = epp_plain_request(@epp_xml.domain.delete({ name: { value: domain.name } @@ -2336,7 +2342,8 @@ describe 'EPP Domain', epp: true do end it 'does not delete domain with pending delete' do - domain.domain_statuses.create(value: DomainStatus::PENDING_DELETE) + domain.statuses << DomainStatus::PENDING_DELETE + domain.save response = epp_plain_request(@epp_xml.domain.delete({ name: { value: domain.name } From 2af26a8d96acc6cd14df713fc9bec3b26e86c45e Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 15 Jun 2015 17:22:07 +0300 Subject: [PATCH 04/15] Refactor #2623 --- app/models/domain.rb | 53 +++++++++++++++++++---------------------- spec/epp/domain_spec.rb | 7 +++--- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index 22dbec5be..d75f8132f 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -193,9 +193,10 @@ class Domain < ActiveRecord::Base d = Domain.where('delete_at <= ?', Time.zone.now) d.each do |x| - x.domain_statuses.create(value: DomainStatus::DELETE_CANDIDATE) if x.delete_candidateable? + x.statuses << DomainStatus::DELETE_CANDIDATE if x.delete_candidateable? # TODO: This should be managed by automatic_statuses - x.domain_statuses.where(value: DomainStatus::OK).destroy_all + x.statuses.delete(DomainStatus::OK) + x.save end return if Rails.env.test? @@ -258,8 +259,8 @@ class Domain < ActiveRecord::Base def delete_candidateable? return false if delete_at > Time.zone.now - return false if domain_statuses.where(value: DomainStatus::DELETE_CANDIDATE).any? - return false if domain_statuses.where(value: DomainStatus::SERVER_DELETE_PROHIBITED).any? + return false if statuses.include?(DomainStatus::DELETE_CANDIDATE) + return false if statuses.include?(DomainStatus::SERVER_DELETE_PROHIBITED) true end @@ -270,15 +271,13 @@ class Domain < ActiveRecord::Base end end - return false if domain_statuses.where(value: DomainStatus::DELETE_CANDIDATE).any? + return false if statuses.include?(DomainStatus::DELETE_CANDIDATE) true end def pending_update? - (domain_statuses.pluck(:value) & %W( - #{DomainStatus::PENDING_UPDATE} - )).present? + statuses.include?(DomainStatus::PENDING_UPDATE) end def pending_update! @@ -297,7 +296,7 @@ class Domain < ActiveRecord::Base self.pending_json = pending_json_cache self.registrant_verification_token = token self.registrant_verification_asked_at = asked_at - domain_statuses.create(value: DomainStatus::PENDING_UPDATE) + self.statuses = [DomainStatus::PENDING_UPDATE] end def registrant_update_confirmable?(token) @@ -340,7 +339,7 @@ class Domain < ActiveRecord::Base self.epp_pending_delete = true # for epp return true unless registrant_verification_asked? - statuses << DomainStatus::PENDING_DELETE + statuses = [DomainStatus::PENDING_DELETE] save(validate: false) # should check if this did succeed DomainMailer.pending_deleted(self).deliver_now @@ -424,27 +423,27 @@ class Domain < ActiveRecord::Base end def set_force_delete - domain_statuses.where(value: DomainStatus::FORCE_DELETE).first_or_create - domain_statuses.where(value: DomainStatus::SERVER_RENEW_PROHIBITED).first_or_create - domain_statuses.where(value: DomainStatus::SERVER_TRANSFER_PROHIBITED).first_or_create - domain_statuses.where(value: DomainStatus::SERVER_UPDATE_PROHIBITED).first_or_create - domain_statuses.where(value: DomainStatus::SERVER_MANUAL_INZONE).first_or_create - domain_statuses.where(value: DomainStatus::PENDING_DELETE).first_or_create - domain_statuses.where(value: DomainStatus::CLIENT_DELETE_PROHIBITED).destroy_all - domain_statuses.where(value: DomainStatus::SERVER_DELETE_PROHIBITED).destroy_all - domain_statuses.reload + statuses << DomainStatus::FORCE_DELETE + statuses << DomainStatus::SERVER_RENEW_PROHIBITED + statuses << DomainStatus::SERVER_TRANSFER_PROHIBITED + statuses << DomainStatus::SERVER_UPDATE_PROHIBITED + statuses << DomainStatus::SERVER_MANUAL_INZONE + statuses << DomainStatus::PENDING_DELETE + statuses.delete(DomainStatus::CLIENT_DELETE_PROHIBITED) + statuses.delete(DomainStatus::SERVER_DELETE_PROHIBITED) + self.force_delete_at = Time.zone.now + Setting.redemption_grace_period.days unless force_delete_at save(validate: false) end def unset_force_delete - domain_statuses.where(value: DomainStatus::FORCE_DELETE).destroy_all - domain_statuses.where(value: DomainStatus::SERVER_RENEW_PROHIBITED).destroy_all - domain_statuses.where(value: DomainStatus::SERVER_TRANSFER_PROHIBITED).destroy_all - domain_statuses.where(value: DomainStatus::SERVER_UPDATE_PROHIBITED).destroy_all - domain_statuses.where(value: DomainStatus::SERVER_MANUAL_INZONE).destroy_all - domain_statuses.where(value: DomainStatus::PENDING_DELETE).destroy_all - domain_statuses.reload + statuses.delete(DomainStatus::FORCE_DELETE) + statuses.delete(DomainStatus::SERVER_RENEW_PROHIBITED) + statuses.delete(DomainStatus::SERVER_TRANSFER_PROHIBITED) + statuses.delete(DomainStatus::SERVER_UPDATE_PROHIBITED) + statuses.delete(DomainStatus::SERVER_MANUAL_INZONE) + statuses.delete(DomainStatus::PENDING_DELETE) + self.force_delete_at = nil save(validate: false) end @@ -456,8 +455,6 @@ class Domain < ActiveRecord::Base elsif statuses.length > 1 || !valid? statuses.delete(DomainStatus::OK) end - - # otherwise domain_statuses are in old state for domain object end def children_log diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 9713af905..38f5d675a 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -1501,7 +1501,8 @@ describe 'EPP Domain', epp: true do end it 'should not allow any update when status pending update' do - domain.domain_statuses.create(value: DomainStatus::PENDING_UPDATE) + domain.statuses << DomainStatus::PENDING_UPDATE + domain.save existing_pw = domain.auth_info @@ -1728,8 +1729,8 @@ describe 'EPP Domain', epp: true do new_contact = d.tech_contacts.find_by(code: 'FIXED:PENDINGMAK21') new_contact.should_not be_truthy # aka should not add new contact - d.domain_statuses.count.should == 1 - d.domain_statuses.first.value.should == 'pendingUpdate' + d.statuses.count.should == 1 + d.statuses.first.should == 'pendingUpdate' d.dnskeys.count.should == 0 end From 12a05c524c898085d6b6bbaaeb44909d74ee9bfa Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 15 Jun 2015 18:15:32 +0300 Subject: [PATCH 05/15] Test fixes #2623 --- spec/epp/domain_spec.rb | 4 +-- spec/models/domain_spec.rb | 51 +++++++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 38f5d675a..ccb38c719 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -1872,8 +1872,8 @@ describe 'EPP Domain', epp: true do end it 'does not remove server statuses' do - d = Domain.last - d.domain_statuses.create(value: DomainStatus::SERVER_HOLD) + domain.statuses << DomainStatus::SERVER_HOLD + domain.save xml = domain_update_xml({ name: { value: domain.name }, diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index cc2946ced..380b907e5 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -96,50 +96,60 @@ describe Domain do it 'should expire domains' do Domain.start_expire_period - @domain.domain_statuses.where(value: DomainStatus::EXPIRED).count.should == 0 + @domain.statuses.include?(DomainStatus::EXPIRED).should == false @domain.valid_to = Time.zone.now - 10.days @domain.save Domain.start_expire_period - @domain.domain_statuses.where(value: DomainStatus::EXPIRED).count.should == 1 + @domain.reload + @domain.statuses.include?(DomainStatus::EXPIRED).should == true Domain.start_expire_period - @domain.domain_statuses.where(value: DomainStatus::EXPIRED).count.should == 1 + @domain.reload + @domain.statuses.include?(DomainStatus::EXPIRED).should == true end it 'should start redemption grace period' do Domain.start_redemption_grace_period - @domain.domain_statuses.where(value: DomainStatus::SERVER_HOLD).count.should == 0 + @domain.reload + @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false @domain.outzone_at = Time.zone.now - @domain.domain_statuses.create(value: DomainStatus::SERVER_MANUAL_INZONE) # this prohibits server_hold + @domain.statuses << DomainStatus::SERVER_MANUAL_INZONE # this prohibits server_hold @domain.save Domain.start_redemption_grace_period - @domain.domain_statuses.where(value: DomainStatus::SERVER_HOLD).count.should == 0 + @domain.reload + @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false - @domain.domain_statuses.destroy_all + @domain.statuses = [] + @domain.save Domain.start_redemption_grace_period - @domain.domain_statuses.where(value: DomainStatus::SERVER_HOLD).count.should == 1 + @domain.reload + @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == true end it 'should start delete period' do Domain.start_delete_period - @domain.domain_statuses.where(value: DomainStatus::DELETE_CANDIDATE).count.should == 0 + @domain.reload + @domain.statuses.include?(DomainStatus::DELETE_CANDIDATE).should == false @domain.delete_at = Time.zone.now - @domain.domain_statuses.create(value: DomainStatus::SERVER_DELETE_PROHIBITED) # this prohibits delete_candidate + @domain.statuses << DomainStatus::SERVER_DELETE_PROHIBITED # this prohibits delete_candidate @domain.save Domain.start_delete_period - @domain.domain_statuses.where(value: DomainStatus::DELETE_CANDIDATE).count.should == 0 + @domain.reload + @domain.statuses.include?(DomainStatus::DELETE_CANDIDATE).should == false - @domain.domain_statuses.destroy_all + @domain.statuses = [] + @domain.save Domain.start_delete_period + @domain.reload - @domain.domain_statuses.where(value: DomainStatus::DELETE_CANDIDATE).count.should == 1 + @domain.statuses.include?(DomainStatus::DELETE_CANDIDATE).should == true end it 'should destroy delete candidates' do @@ -159,15 +169,16 @@ describe Domain do end it 'should set force delete time' do + @domain.statuses = ['ok'] @domain.set_force_delete - @domain.domain_statuses.count.should == 6 - fda = Time.zone.now + Setting.redemption_grace_period + @domain.statuses.count.should == 6 + fda = Time.zone.now + Setting.redemption_grace_period.days @domain.force_delete_at.should be_within(20).of(fda) @domain.unset_force_delete - @domain.domain_statuses.count.should == 1 + @domain.statuses.count.should == 1 @domain.force_delete_at.should be_nil end @@ -175,7 +186,7 @@ describe Domain do before :all do @domain.registrant_verification_token = 123 @domain.registrant_verification_asked_at = Time.zone.now - @domain.domain_statuses.create(value: DomainStatus::PENDING_UPDATE) + @domain.statuses << DomainStatus::PENDING_UPDATE end it 'should be registrant update confirm ready' do @@ -187,7 +198,7 @@ describe Domain do end it 'should not be registrant update confirm ready when no correct status' do - @domain.domain_statuses.delete_all + @domain.statuses = [] @domain.registrant_update_confirmable?('123').should == false end end @@ -196,7 +207,7 @@ describe Domain do before :all do @domain.registrant_verification_token = 123 @domain.registrant_verification_asked_at = Time.zone.now - @domain.domain_statuses.create(value: DomainStatus::PENDING_UPDATE) + @domain.statuses << DomainStatus::PENDING_UPDATE end it 'should be registrant update confirm ready' do @@ -208,7 +219,7 @@ describe Domain do end it 'should not be registrant update confirm ready when no correct status' do - @domain.domain_statuses.delete_all + @domain.statuses = [] @domain.registrant_update_confirmable?('123').should == false end end From 777f3836e72f2899f6be92c3bb06250f5c5c2c5f Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 15 Jun 2015 18:36:57 +0300 Subject: [PATCH 06/15] Fix whois #2623 --- app/models/whois_record.rb | 16 ++++++++++------ .../registrant/domain_delete_confirm_spec.rb | 6 +++--- .../registrant/domain_update_confirm_spec.rb | 6 +++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/models/whois_record.rb b/app/models/whois_record.rb index 0e7ed3f30..e1b168935 100644 --- a/app/models/whois_record.rb +++ b/app/models/whois_record.rb @@ -20,11 +20,11 @@ class WhoisRecord < ActiveRecord::Base includes( domain: [ :registrant, - :registrar, - :nameservers, + :registrar, + :nameservers, { tech_contacts: :registrar }, { admin_contacts: :registrar } - ] + ] ) end end @@ -34,19 +34,23 @@ class WhoisRecord < ActiveRecord::Base h = HashWithIndifferentAccess.new return h if domain.blank? + status_map = { + 'ok' => 'ok (paid and in zone)' + } + @disclosed = [] h[:name] = domain.name h[:registrant] = domain.registrant.name - h[:status] = domain.domain_statuses.map(&:human_value).join(', ') + h[:status] = domain.statuses.map { |x| status_map[x] || x }.join(', ') h[:registered] = domain.registered_at.try(:to_s, :iso8601) 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[:registrar_update_at] = domain.registrar.updated_at.try(:to_s, :iso8601) h[:admin_contacts] = [] domain.admin_contacts.each do |ac| diff --git a/spec/features/registrant/domain_delete_confirm_spec.rb b/spec/features/registrant/domain_delete_confirm_spec.rb index 6ca4bad2e..23697d9d1 100644 --- a/spec/features/registrant/domain_delete_confirm_spec.rb +++ b/spec/features/registrant/domain_delete_confirm_spec.rb @@ -22,11 +22,11 @@ feature 'DomainDeleteConfirm', type: :feature do context 'as unknown user with domain with token' do before :all do @domain = Fabricate( - :domain, - registrant_verification_token: '123', + :domain, + registrant_verification_token: '123', registrant_verification_asked_at: Time.zone.now ) - @domain.domain_statuses.create(value: DomainStatus::PENDING_DELETE) + @domain.statuses << DomainStatus::PENDING_DELETE end it 'should see warning info if token is missing in request' do diff --git a/spec/features/registrant/domain_update_confirm_spec.rb b/spec/features/registrant/domain_update_confirm_spec.rb index 5d5a298f7..fc69bfb0f 100644 --- a/spec/features/registrant/domain_update_confirm_spec.rb +++ b/spec/features/registrant/domain_update_confirm_spec.rb @@ -22,11 +22,11 @@ feature 'DomainUpdateConfirm', type: :feature do context 'as unknown user with domain with update token' do before :all do @domain = Fabricate( - :domain, - registrant_verification_token: '123', + :domain, + registrant_verification_token: '123', registrant_verification_asked_at: Time.zone.now ) - @domain.domain_statuses.create(value: DomainStatus::PENDING_UPDATE) + @domain.statuses << DomainStatus::PENDING_UPDATE end it 'should see warning info if token is missing in request' do From 7ba2ef0ef9d512e217a383b707009d3a17656f5e Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 15 Jun 2015 19:07:14 +0300 Subject: [PATCH 07/15] Fix test #2623 --- spec/epp/domain_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index ccb38c719..295ccebd3 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -317,7 +317,7 @@ describe 'EPP Domain', epp: true do response = epp_plain_request(xml) response[:msg].should == 'Command completed successfully' response[:result_code].should == '1000' - Domain.first.valid_to.should be_within(5).of(1.year.since) + Domain.first.valid_to.should be_within(60).of(1.year.since) end it 'does not create a domain with invalid period' do From 0f765b1ff071abd9f81affe97aac0fcfbca0eb4e Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 16 Jun 2015 11:13:44 +0300 Subject: [PATCH 08/15] Fix tests #2623 --- spec/features/registrant/domain_delete_confirm_spec.rb | 1 + spec/features/registrant/domain_update_confirm_spec.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/spec/features/registrant/domain_delete_confirm_spec.rb b/spec/features/registrant/domain_delete_confirm_spec.rb index 23697d9d1..f51374540 100644 --- a/spec/features/registrant/domain_delete_confirm_spec.rb +++ b/spec/features/registrant/domain_delete_confirm_spec.rb @@ -27,6 +27,7 @@ feature 'DomainDeleteConfirm', type: :feature do registrant_verification_asked_at: Time.zone.now ) @domain.statuses << DomainStatus::PENDING_DELETE + @domain.save end it 'should see warning info if token is missing in request' do diff --git a/spec/features/registrant/domain_update_confirm_spec.rb b/spec/features/registrant/domain_update_confirm_spec.rb index fc69bfb0f..0af47e43b 100644 --- a/spec/features/registrant/domain_update_confirm_spec.rb +++ b/spec/features/registrant/domain_update_confirm_spec.rb @@ -27,6 +27,7 @@ feature 'DomainUpdateConfirm', type: :feature do registrant_verification_asked_at: Time.zone.now ) @domain.statuses << DomainStatus::PENDING_UPDATE + @domain.save end it 'should see warning info if token is missing in request' do From bed27ce940f765d8198a36d56bbe855b077ac98f Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 16 Jun 2015 12:42:29 +0300 Subject: [PATCH 09/15] Status import improvements #2267 --- app/models/domain.rb | 5 ++-- lib/tasks/import.rake | 59 ++++++++++++++----------------------------- 2 files changed, 21 insertions(+), 43 deletions(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index d75f8132f..1f371bfd0 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -128,7 +128,6 @@ class Domain < ActiveRecord::Base errors.add(:statuses, :taken) end - attr_accessor :registrant_typeahead, :update_me, :deliver_emails, :epp_pending_update, :epp_pending_delete @@ -207,8 +206,8 @@ class Domain < ActiveRecord::Base STDOUT << "#{Time.zone.now.utc} - Destroying domains\n" unless Rails.env.test? c = 0 - DomainStatus.where(value: DomainStatus::DELETE_CANDIDATE).each do |x| - x.domain.destroy + Domain.where("statuses @> '{deleteCandidate}'::varchar[]").each do |x| + x.destroy c += 1 end diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index f62dfc637..1b04aa215 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -224,6 +224,7 @@ namespace :import do legacy_id legacy_registrar_id legacy_registrant_id + statuses ) domain_contact_columns = %w( @@ -263,7 +264,7 @@ namespace :import do legacy_domain_id ) - domains, nameservers, dnskeys, domain_statuses, domain_contacts = [], [], [], [], [] + domains, nameservers, dnskeys, domain_contacts = [], [], [], [] existing_domain_ids = Domain.pluck(:legacy_id) user = "rake-#{`whoami`.strip} #{ARGV.join ' '}" count = 0 @@ -281,6 +282,20 @@ namespace :import do count += 1 begin + # domain statuses + domain_statuses = [] + ok = true + x.object_states.each do |state| + next if state.name.blank? + domain_statuses << state.name + ok = false + end + + # OK status is default + if ok + domain_statuses << DomainStatus::OK + end + domains << [ x.object_registry.name.try(:strip), x.object_registry.try(:crdate), @@ -296,7 +311,8 @@ namespace :import do user, x.id, x.object_registry.try(:crid), - x.registrant + x.registrant, + domain_statuses ] # admin contacts @@ -321,31 +337,6 @@ namespace :import do ] end - # domain statuses - ok = true - x.object_states.each do |state| - next if state.name.blank? - domain_statuses << [ - state.desc, - state.name, - user, - user, - x.id - ] - ok = false - end - - # OK status is default - if ok - domain_statuses << [ - nil, - DomainStatus::OK, - user, - user, - x.id - ] - end - # nameservers x.nsset.hosts.each do |host| ip_maps = host.host_ipaddr_maps @@ -384,9 +375,8 @@ namespace :import do Domain.import domain_columns, domains, validate: false Nameserver.import nameserver_columns, nameservers, validate: false Dnskey.import dnskey_columns, dnskeys, validate: false - DomainStatus.import domain_status_columns, domain_statuses, validate: false DomainContact.import domain_contact_columns, domain_contacts, validate: false - domains, nameservers, dnskeys, domain_statuses, domain_contacts = [], [], [], [], [] + domains, nameservers, dnskeys, domain_contacts = [], [], [], [] end rescue => e puts "ERROR on index #{index}" @@ -397,7 +387,6 @@ namespace :import do Domain.import domain_columns, domains, validate: false Nameserver.import nameserver_columns, nameservers, validate: false Dnskey.import dnskey_columns, dnskeys, validate: false - DomainStatus.import domain_status_columns, domain_statuses, validate: false DomainContact.import domain_contact_columns, domain_contacts, validate: false puts '-----> Updating relations...' @@ -461,16 +450,6 @@ namespace :import do "AND domain_id IS NULL" ) - # statuses - ActiveRecord::Base.connection.execute( - "UPDATE domain_statuses "\ - "SET domain_id = domains.id "\ - "FROM domains "\ - "WHERE domains.legacy_id = legacy_domain_id "\ - "AND legacy_domain_id IS NOT NULL "\ - "AND domain_id IS NULL" - ) - puts '-----> Generating dnskey digests...' Dnskey.all.each do |x| From 9b9e1a3068f8dbf7b5224b89194315cd27f06bc7 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 16 Jun 2015 15:39:19 +0300 Subject: [PATCH 10/15] Status form update #2623 --- app/controllers/admin/domains_controller.rb | 23 +++++++++------- .../domains/form_partials/_statuses.haml | 26 ++++++++++--------- .../admin/domains/partials/_statuses.haml | 14 +++------- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index 4b8820fd8..4d10cdb08 100644 --- a/app/controllers/admin/domains_controller.rb +++ b/app/controllers/admin/domains_controller.rb @@ -16,9 +16,9 @@ class Admin::DomainsController < AdminController end def update - add_prefix_to_statuses + dp = add_prefix_to_statuses - if @domain.update(domain_params) + if @domain.update(dp) flash[:notice] = I18n.t('domain_updated') redirect_to [:admin, @domain] else @@ -53,21 +53,24 @@ class Admin::DomainsController < AdminController end def domain_params - params.require(:domain).permit( - domain_statuses_attributes: [:id, :value, :description, :_destroy] - ) + if params[:domain] + params.require(:domain).permit({ statuses: [] }) + else + {statuses: []} + end end def build_associations @domain.domain_statuses.build if @domain.domain_statuses.empty? - @server_statuses = @domain.domain_statuses.select(&:server_status?) - @server_statuses << @domain.domain_statuses.build if @server_statuses.empty? + @server_statuses = @domain.statuses.select { |x| DomainStatus::SERVER_STATUSES.include?(x) } + @server_statuses = [nil] if @server_statuses.empty? end def add_prefix_to_statuses - domain_params[:domain_statuses_attributes].each do |_k, hash| - hash[:value] = hash[:value].prepend('server') if hash[:value].present? - end + dp = domain_params + dp[:statuses] = domain_params[:statuses].map { |x| x.prepend('server') if x.present? } + dp[:statuses].reject! { |x| x.blank? } + dp end end diff --git a/app/views/admin/domains/form_partials/_statuses.haml b/app/views/admin/domains/form_partials/_statuses.haml index 7ae89a8da..94ba87ef8 100644 --- a/app/views/admin/domains/form_partials/_statuses.haml +++ b/app/views/admin/domains/form_partials/_statuses.haml @@ -1,26 +1,28 @@ #domain-statuses - = f.fields_for :domain_statuses, @server_statuses do |status_fields| + - @server_statuses.each do |x| .panel.panel-default .panel-heading.clearfix .pull-left= t(:status) .pull-right = link_to(t(:add_another), '#', class: 'btn btn-primary btn-xs add-domain-status') - = link_to(t(:delete), '#', class: 'btn btn-danger btn-xs destroy') + = link_to(t(:delete), '#', class: 'btn btn-danger btn-xs destroy-status') .panel-body - .errors - = render 'shared/errors', object: status_fields.object - - if status_fields.object.errors.any? - %hr .form-group - = status_fields.label :value, class: 'col-md-2 control-label' + = f.label 'status', class: 'col-md-2 control-label' .col-md-10 - = status_fields.select :value, options_for_select(DomainStatus.statuses_for_admin, status_fields.object.value.try(:sub, 'server', '')), {include_blank: true}, {class: 'form-control'} + = select_tag 'domain[statuses][]', options_for_select(DomainStatus.statuses_for_admin, x.try(:sub, 'server', '')), include_blank: true, class: 'form-control' .form-group - = status_fields.label :description, class: 'col-md-2 control-label' + = label_tag t(:description), nil, class: 'col-md-2 control-label' .col-md-10 - = status_fields.text_field :description, class: 'form-control', autocomplete: 'off' + = text_field_tag :description, nil, class: 'form-control', autocomplete: 'off' + :coffee $("#domain-statuses").nestedAttributes bindAddTo: $(".add-domain-status") - afterAdd: (item) -> - item.find(".errors").html "" + + $('.destroy-status').on 'click', (e) -> + e.preventDefault() + if $('.panel').length > 1 + $(this).parents('.panel').remove() + else + $(this).parents('.panel').find('select').val('') diff --git a/app/views/admin/domains/partials/_statuses.haml b/app/views/admin/domains/partials/_statuses.haml index f6f6a115c..51a88b18b 100644 --- a/app/views/admin/domains/partials/_statuses.haml +++ b/app/views/admin/domains/partials/_statuses.haml @@ -1,5 +1,4 @@ -- panel_class = @domain.errors.messages[:domain_statuses] ? 'panel-danger' : 'panel-default' -#domain_statuses.panel{class: panel_class} +#domain_statuses.panel.panel-default .panel-heading.clearfix = t(:statuses) .table-responsive @@ -9,12 +8,7 @@ %th{class: 'col-xs-6'}= t(:status) %th{class: 'col-xs-6'}= t(:description) %tbody - - @domain.domain_statuses.each do |x| + - @domain.statuses.each do |x| %tr - %td= x.value - %td= x.description - - if @domain.errors.messages[:domain_statuses] - %tfoot - - @domain.errors.messages[:domain_statuses].each do |x| - %tr - %td{colspan: 4}= x + %td= x + %td From 238b3aa5e02639396a2bdaae8f896bffd957ac77 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 16 Jun 2015 16:16:09 +0300 Subject: [PATCH 11/15] Refactor status form #2623 --- app/controllers/admin/domains_controller.rb | 4 ++-- app/models/domain.rb | 2 +- app/models/domain_status.rb | 2 +- app/views/admin/domains/form_partials/_statuses.haml | 5 +++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index 4d10cdb08..9c495ef11 100644 --- a/app/controllers/admin/domains_controller.rb +++ b/app/controllers/admin/domains_controller.rb @@ -22,7 +22,7 @@ class Admin::DomainsController < AdminController flash[:notice] = I18n.t('domain_updated') redirect_to [:admin, @domain] else - @domain.domain_statuses.build if @domain.domain_statuses.empty? + build_associations flash.now[:alert] = I18n.t('failed_to_update_domain') render 'edit' end @@ -64,11 +64,11 @@ class Admin::DomainsController < AdminController @domain.domain_statuses.build if @domain.domain_statuses.empty? @server_statuses = @domain.statuses.select { |x| DomainStatus::SERVER_STATUSES.include?(x) } @server_statuses = [nil] if @server_statuses.empty? + @other_statuses = @domain.statuses.select { |x| !DomainStatus::SERVER_STATUSES.include?(x) } end def add_prefix_to_statuses dp = domain_params - dp[:statuses] = domain_params[:statuses].map { |x| x.prepend('server') if x.present? } dp[:statuses].reject! { |x| x.blank? } dp end diff --git a/app/models/domain.rb b/app/models/domain.rb index 1f371bfd0..3dde9681d 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -317,7 +317,7 @@ class Domain < ActiveRecord::Base end def force_deletable? - domain_statuses.where(value: DomainStatus::FORCE_DELETE).empty? + !statuses.include?(DomainStatus::FORCE_DELETE) end def registrant_verification_asked? diff --git a/app/models/domain_status.rb b/app/models/domain_status.rb index f27f0bb71..b33b5446c 100644 --- a/app/models/domain_status.rb +++ b/app/models/domain_status.rb @@ -124,7 +124,7 @@ class DomainStatus < ActiveRecord::Base end def statuses_for_admin - SERVER_STATUSES.map { |x| x.sub('server', '') } + SERVER_STATUSES.map { |x| [x.sub('server', ''), x] } end end end diff --git a/app/views/admin/domains/form_partials/_statuses.haml b/app/views/admin/domains/form_partials/_statuses.haml index 94ba87ef8..52b9282ef 100644 --- a/app/views/admin/domains/form_partials/_statuses.haml +++ b/app/views/admin/domains/form_partials/_statuses.haml @@ -10,12 +10,13 @@ .form-group = f.label 'status', class: 'col-md-2 control-label' .col-md-10 - = select_tag 'domain[statuses][]', options_for_select(DomainStatus.statuses_for_admin, x.try(:sub, 'server', '')), include_blank: true, class: 'form-control' + = select_tag 'domain[statuses][]', options_for_select(DomainStatus.statuses_for_admin, x), include_blank: true, class: 'form-control' .form-group = label_tag t(:description), nil, class: 'col-md-2 control-label' .col-md-10 = text_field_tag :description, nil, class: 'form-control', autocomplete: 'off' - + - @other_statuses.each do |x| + = hidden_field_tag 'domain[statuses][]', x, readonly: true :coffee $("#domain-statuses").nestedAttributes bindAddTo: $(".add-domain-status") From 444f20b6e60d270fc7c647d257a565351e0e8f4a Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 16 Jun 2015 16:19:43 +0300 Subject: [PATCH 12/15] Structure file --- db/structure.sql | 57 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/db/structure.sql b/db/structure.sql index 427384c05..07eb9f70e 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -41,7 +41,7 @@ CREATE FUNCTION generate_zonefile(i_origin character varying) RETURNS text ret text; BEGIN -- define filters - include_filter = '%' || i_origin; + include_filter = '%.' || i_origin; -- for %.%.% IF i_origin ~ '\.' THEN @@ -198,7 +198,7 @@ CREATE TABLE account_activities ( id integer NOT NULL, account_id integer, invoice_id integer, - sum numeric(10,2), + sum numeric(8,2), currency character varying, bank_transaction_id integer, created_at timestamp without time zone, @@ -236,7 +236,7 @@ CREATE TABLE accounts ( id integer NOT NULL, registrar_id integer, account_type character varying, - balance numeric(10,2) DEFAULT 0 NOT NULL, + balance numeric(8,2) DEFAULT 0.0 NOT NULL, created_at timestamp without time zone, updated_at timestamp without time zone, currency character varying, @@ -394,7 +394,7 @@ CREATE TABLE bank_transactions ( buyer_name character varying, document_no character varying, description character varying, - sum numeric(10,2), + sum numeric(8,2), reference_no character varying, paid_at timestamp without time zone, created_at timestamp without time zone, @@ -435,7 +435,7 @@ CREATE TABLE banklink_transactions ( vk_rec_id character varying, vk_stamp character varying, vk_t_no character varying, - vk_amount numeric(10,2), + vk_amount numeric(8,2), vk_curr character varying, vk_rec_acc character varying, vk_rec_name character varying, @@ -639,6 +639,15 @@ CREATE SEQUENCE countries_id_seq ALTER SEQUENCE countries_id_seq OWNED BY countries.id; +-- +-- Name: data_migrations; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- + +CREATE TABLE data_migrations ( + version character varying NOT NULL +); + + -- -- Name: delegation_signers; Type: TABLE; Schema: public; Owner: -; Tablespace: -- @@ -884,7 +893,8 @@ CREATE TABLE domains ( registrant_verification_asked_at timestamp without time zone, registrant_verification_token character varying, pending_json json, - force_delete_at timestamp without time zone + force_delete_at timestamp without time zone, + statuses character varying[] ); @@ -950,7 +960,7 @@ CREATE TABLE invoice_items ( description character varying NOT NULL, unit character varying, amount integer, - price numeric(10,2), + price numeric(8,2), created_at timestamp without time zone, updated_at timestamp without time zone, creator_str character varying, @@ -991,7 +1001,7 @@ CREATE TABLE invoices ( currency character varying NOT NULL, description character varying, reference_no character varying, - vat_prc numeric(10,2) NOT NULL, + vat_prc numeric(8,2) NOT NULL, paid_at timestamp without time zone, seller_id integer, seller_name character varying NOT NULL, @@ -1024,7 +1034,7 @@ CREATE TABLE invoices ( updator_str character varying, number integer, cancelled_at timestamp without time zone, - sum_cache numeric(10,2) + sum_cache numeric(8,2) ); @@ -2286,7 +2296,7 @@ CREATE TABLE pricelists ( id integer NOT NULL, "desc" character varying, category character varying, - price_cents numeric(8,2) DEFAULT 0 NOT NULL, + price_cents numeric(8,2) DEFAULT 0.0 NOT NULL, price_currency character varying DEFAULT 'EUR'::character varying NOT NULL, valid_from timestamp without time zone, valid_to timestamp without time zone, @@ -2550,7 +2560,7 @@ CREATE TABLE users ( crt text, type character varying, registrant_ident character varying, - encrypted_password character varying DEFAULT ''::character varying, + encrypted_password character varying DEFAULT ''::character varying NOT NULL, remember_created_at timestamp without time zone, failed_attempts integer DEFAULT 0 NOT NULL, locked_at timestamp without time zone @@ -4377,6 +4387,13 @@ CREATE INDEX index_whois_records_on_domain_id ON whois_records USING btree (doma CREATE INDEX index_whois_records_on_registrar_id ON whois_records USING btree (registrar_id); +-- +-- Name: unique_data_migrations; Type: INDEX; Schema: public; Owner: -; Tablespace: +-- + +CREATE UNIQUE INDEX unique_data_migrations ON data_migrations USING btree (version); + + -- -- Name: unique_schema_migrations; Type: INDEX; Schema: public; Owner: -; Tablespace: -- @@ -4592,8 +4609,6 @@ INSERT INTO schema_migrations (version) VALUES ('20150227092508'); INSERT INTO schema_migrations (version) VALUES ('20150227113121'); -INSERT INTO schema_migrations (version) VALUES ('20150302130224'); - INSERT INTO schema_migrations (version) VALUES ('20150302161712'); INSERT INTO schema_migrations (version) VALUES ('20150303130729'); @@ -4652,8 +4667,6 @@ INSERT INTO schema_migrations (version) VALUES ('20150417082723'); INSERT INTO schema_migrations (version) VALUES ('20150421134820'); -INSERT INTO schema_migrations (version) VALUES ('20150422090645'); - INSERT INTO schema_migrations (version) VALUES ('20150422092514'); INSERT INTO schema_migrations (version) VALUES ('20150422132631'); @@ -4698,8 +4711,6 @@ INSERT INTO schema_migrations (version) VALUES ('20150519115050'); INSERT INTO schema_migrations (version) VALUES ('20150519140853'); -INSERT INTO schema_migrations (version) VALUES ('20150519142542'); - INSERT INTO schema_migrations (version) VALUES ('20150519144118'); INSERT INTO schema_migrations (version) VALUES ('20150520163237'); @@ -4712,7 +4723,9 @@ INSERT INTO schema_migrations (version) VALUES ('20150522164020'); INSERT INTO schema_migrations (version) VALUES ('20150525075550'); -INSERT INTO schema_migrations (version) VALUES ('20150603141054'); +INSERT INTO schema_migrations (version) VALUES ('20150601083516'); + +INSERT INTO schema_migrations (version) VALUES ('20150601083800'); INSERT INTO schema_migrations (version) VALUES ('20150603141549'); @@ -4720,11 +4733,19 @@ INSERT INTO schema_migrations (version) VALUES ('20150603211318'); INSERT INTO schema_migrations (version) VALUES ('20150603212659'); +INSERT INTO schema_migrations (version) VALUES ('20150609093515'); + INSERT INTO schema_migrations (version) VALUES ('20150609103333'); +INSERT INTO schema_migrations (version) VALUES ('20150610111019'); + INSERT INTO schema_migrations (version) VALUES ('20150610112238'); INSERT INTO schema_migrations (version) VALUES ('20150610144547'); INSERT INTO schema_migrations (version) VALUES ('20150611124920'); +INSERT INTO schema_migrations (version) VALUES ('20150612123111'); + +INSERT INTO schema_migrations (version) VALUES ('20150612125720'); + From af1a808d7bb33a790fb69ee1524cc3899e10e51e Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 16 Jun 2015 16:31:44 +0300 Subject: [PATCH 13/15] Update structure #2623 --- db/structure.sql | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/db/structure.sql b/db/structure.sql index 07eb9f70e..7beebd066 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -4719,26 +4719,14 @@ INSERT INTO schema_migrations (version) VALUES ('20150520164507'); INSERT INTO schema_migrations (version) VALUES ('20150521120145'); -INSERT INTO schema_migrations (version) VALUES ('20150522164020'); - -INSERT INTO schema_migrations (version) VALUES ('20150525075550'); - -INSERT INTO schema_migrations (version) VALUES ('20150601083516'); - -INSERT INTO schema_migrations (version) VALUES ('20150601083800'); - INSERT INTO schema_migrations (version) VALUES ('20150603141549'); INSERT INTO schema_migrations (version) VALUES ('20150603211318'); INSERT INTO schema_migrations (version) VALUES ('20150603212659'); -INSERT INTO schema_migrations (version) VALUES ('20150609093515'); - INSERT INTO schema_migrations (version) VALUES ('20150609103333'); -INSERT INTO schema_migrations (version) VALUES ('20150610111019'); - INSERT INTO schema_migrations (version) VALUES ('20150610112238'); INSERT INTO schema_migrations (version) VALUES ('20150610144547'); @@ -4747,5 +4735,3 @@ INSERT INTO schema_migrations (version) VALUES ('20150611124920'); INSERT INTO schema_migrations (version) VALUES ('20150612123111'); -INSERT INTO schema_migrations (version) VALUES ('20150612125720'); - From 1e5eb158e50cd25f91f388f1aa5c179190ceef6b Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 16 Jun 2015 16:34:13 +0300 Subject: [PATCH 14/15] Rename #2623 --- app/controllers/admin/domains_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index 9c495ef11..c16849bd7 100644 --- a/app/controllers/admin/domains_controller.rb +++ b/app/controllers/admin/domains_controller.rb @@ -16,7 +16,7 @@ class Admin::DomainsController < AdminController end def update - dp = add_prefix_to_statuses + dp = ignore_empty_statuses if @domain.update(dp) flash[:notice] = I18n.t('domain_updated') @@ -67,7 +67,7 @@ class Admin::DomainsController < AdminController @other_statuses = @domain.statuses.select { |x| !DomainStatus::SERVER_STATUSES.include?(x) } end - def add_prefix_to_statuses + def ignore_empty_statuses dp = domain_params dp[:statuses].reject! { |x| x.blank? } dp From 34014cf5f75ef03ae7cfe2535e74a5f0b1e9262e Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 16 Jun 2015 16:41:27 +0300 Subject: [PATCH 15/15] Refactor #2623 --- app/controllers/admin/domains_controller.rb | 1 - app/models/domain.rb | 4 ++-- app/models/epp/domain.rb | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index c16849bd7..4cf12dab2 100644 --- a/app/controllers/admin/domains_controller.rb +++ b/app/controllers/admin/domains_controller.rb @@ -61,7 +61,6 @@ class Admin::DomainsController < AdminController end def build_associations - @domain.domain_statuses.build if @domain.domain_statuses.empty? @server_statuses = @domain.statuses.select { |x| DomainStatus::SERVER_STATUSES.include?(x) } @server_statuses = [nil] if @server_statuses.empty? @other_statuses = @domain.statuses.select { |x| !DomainStatus::SERVER_STATUSES.include?(x) } diff --git a/app/models/domain.rb b/app/models/domain.rb index 586de3f73..56de6ee3d 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -288,8 +288,8 @@ class Domain < ActiveRecord::Base def clean_pendings! preclean_pendings self.pending_json = {} - domain_statuses.where(value: DomainStatus::PENDING_UPDATE).destroy_all - domain_statuses.where(value: DomainStatus::PENDING_DELETE).destroy_all + statuses.delete(DomainStatus::PENDING_UPDATE) + statuses.delete(DomainStatus::PENDING_DELETE) save end diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index fb8bd4845..e9507d955 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -383,8 +383,8 @@ class Epp::Domain < Domain preclean_pendings user = ApiUser.find(pending_json['current_user_id']) frame = Nokogiri::XML(pending_json['frame']) - domain_statuses.where(value: DomainStatus::PENDING_UPDATE).destroy_all - domain_statuses.reload + statuses.delete(DomainStatus::PENDING_UPDATE) + if update(frame, user, false) clean_pendings! end