mirror of
https://github.com/internetee/registry.git
synced 2025-07-03 01:33:36 +02:00
Move statuses to domain #2623
This commit is contained in:
parent
0d0fd3407d
commit
50346c80c8
8 changed files with 78 additions and 45 deletions
|
@ -63,13 +63,16 @@ class Domain < ActiveRecord::Base
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
before_save :manage_automatic_statuses
|
||||||
|
|
||||||
before_save :touch_always_version
|
before_save :touch_always_version
|
||||||
def touch_always_version
|
def touch_always_version
|
||||||
self.updated_at = Time.zone.now
|
self.updated_at = Time.zone.now
|
||||||
end
|
end
|
||||||
after_save :manage_automatic_statuses
|
|
||||||
after_save :update_whois_record
|
after_save :update_whois_record
|
||||||
|
|
||||||
|
after_initialize -> { self.statuses = [] if statuses.nil? }
|
||||||
|
|
||||||
validates :name_dirty, domain_name: true, uniqueness: true
|
validates :name_dirty, domain_name: true, uniqueness: true
|
||||||
validates :puny_label, length: { maximum: 63 }
|
validates :puny_label, length: { maximum: 63 }
|
||||||
validates :period, numericality: { only_integer: true }
|
validates :period, numericality: { only_integer: true }
|
||||||
|
@ -154,9 +157,10 @@ class Domain < ActiveRecord::Base
|
||||||
d = Domain.where('valid_to <= ?', Time.zone.now)
|
d = Domain.where('valid_to <= ?', Time.zone.now)
|
||||||
d.each do |x|
|
d.each do |x|
|
||||||
next unless x.expirable?
|
next unless x.expirable?
|
||||||
x.domain_statuses.create(value: DomainStatus::EXPIRED)
|
x.statuses << DomainStatus::EXPIRED
|
||||||
# TODO: This should be managed by automatic_statuses
|
# 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
|
end
|
||||||
|
|
||||||
STDOUT << "#{Time.zone.now.utc} - Successfully expired #{d.count} domains\n" unless Rails.env.test?
|
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 = Domain.where('outzone_at <= ?', Time.zone.now)
|
||||||
d.each do |x|
|
d.each do |x|
|
||||||
next unless x.server_holdable?
|
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
|
# 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
|
end
|
||||||
|
|
||||||
STDOUT << "#{Time.zone.now.utc} - Successfully set server_hold to #{d.count} domains\n" unless Rails.env.test?
|
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
|
def manage_automatic_statuses
|
||||||
# domain_statuses.create(value: DomainStatus::DELETE_CANDIDATE) if delete_candidateable?
|
# domain_statuses.create(value: DomainStatus::DELETE_CANDIDATE) if delete_candidateable?
|
||||||
if domain_statuses.empty? && valid?
|
if statuses.empty? && valid?
|
||||||
domain_statuses.create(value: DomainStatus::OK)
|
statuses << DomainStatus::OK
|
||||||
elsif domain_statuses.length > 1 || !valid?
|
elsif statuses.length > 1 || !valid?
|
||||||
domain_statuses.find_by(value: DomainStatus::OK).try(:destroy)
|
statuses.delete(DomainStatus::OK)
|
||||||
end
|
end
|
||||||
|
|
||||||
# otherwise domain_statuses are in old state for domain object
|
# otherwise domain_statuses are in old state for domain object
|
||||||
domain_statuses.reload
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def children_log
|
def children_log
|
||||||
|
|
|
@ -439,8 +439,8 @@ class Epp::Domain < Domain
|
||||||
self.period = period
|
self.period = period
|
||||||
self.period_unit = unit
|
self.period_unit = unit
|
||||||
|
|
||||||
domain_statuses.where(value: DomainStatus::SERVER_HOLD).destroy_all
|
statuses.delete(DomainStatus::SERVER_HOLD)
|
||||||
domain_statuses.where(value: DomainStatus::EXPIRED).destroy_all
|
statuses.delete(DomainStatus::EXPIRED)
|
||||||
|
|
||||||
save
|
save
|
||||||
end
|
end
|
||||||
|
|
15
db/data/20150612125720_refactor_domain_statuses.rb
Normal file
15
db/data/20150612125720_refactor_domain_statuses.rb
Normal file
|
@ -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
|
5
db/migrate/20150612123111_add_statuses_to_domain.rb
Normal file
5
db/migrate/20150612123111_add_statuses_to_domain.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddStatusesToDomain < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :domains, :statuses, :string, array: true
|
||||||
|
end
|
||||||
|
end
|
26
db/schema.rb
26
db/schema.rb
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -19,7 +19,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do
|
||||||
create_table "account_activities", force: :cascade do |t|
|
create_table "account_activities", force: :cascade do |t|
|
||||||
t.integer "account_id"
|
t.integer "account_id"
|
||||||
t.integer "invoice_id"
|
t.integer "invoice_id"
|
||||||
t.decimal "sum", precision: 10, scale: 2
|
t.decimal "sum", precision: 8, scale: 2
|
||||||
t.string "currency"
|
t.string "currency"
|
||||||
t.integer "bank_transaction_id"
|
t.integer "bank_transaction_id"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
|
@ -36,7 +36,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do
|
||||||
create_table "accounts", force: :cascade do |t|
|
create_table "accounts", force: :cascade do |t|
|
||||||
t.integer "registrar_id"
|
t.integer "registrar_id"
|
||||||
t.string "account_type"
|
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 "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "currency"
|
t.string "currency"
|
||||||
|
@ -98,7 +98,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do
|
||||||
t.string "buyer_name"
|
t.string "buyer_name"
|
||||||
t.string "document_no"
|
t.string "document_no"
|
||||||
t.string "description"
|
t.string "description"
|
||||||
t.decimal "sum", precision: 10, scale: 2
|
t.decimal "sum", precision: 8, scale: 2
|
||||||
t.string "reference_no"
|
t.string "reference_no"
|
||||||
t.datetime "paid_at"
|
t.datetime "paid_at"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
|
@ -114,7 +114,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do
|
||||||
t.string "vk_rec_id"
|
t.string "vk_rec_id"
|
||||||
t.string "vk_stamp"
|
t.string "vk_stamp"
|
||||||
t.string "vk_t_no"
|
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_curr"
|
||||||
t.string "vk_rec_acc"
|
t.string "vk_rec_acc"
|
||||||
t.string "vk_rec_name"
|
t.string "vk_rec_name"
|
||||||
|
@ -203,6 +203,12 @@ ActiveRecord::Schema.define(version: 20150609103333) do
|
||||||
t.string "updator_str"
|
t.string "updator_str"
|
||||||
end
|
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|
|
create_table "delegation_signers", force: :cascade do |t|
|
||||||
t.integer "domain_id"
|
t.integer "domain_id"
|
||||||
t.string "key_tag"
|
t.string "key_tag"
|
||||||
|
@ -306,6 +312,8 @@ ActiveRecord::Schema.define(version: 20150609103333) do
|
||||||
t.datetime "registrant_verification_asked_at"
|
t.datetime "registrant_verification_asked_at"
|
||||||
t.string "registrant_verification_token"
|
t.string "registrant_verification_token"
|
||||||
t.json "pending_json"
|
t.json "pending_json"
|
||||||
|
t.datetime "force_delete_at"
|
||||||
|
t.string "statuses", array: true
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "domains", ["delete_at"], name: "index_domains_on_delete_at", using: :btree
|
add_index "domains", ["delete_at"], name: "index_domains_on_delete_at", using: :btree
|
||||||
|
@ -331,7 +339,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do
|
||||||
t.string "description", null: false
|
t.string "description", null: false
|
||||||
t.string "unit"
|
t.string "unit"
|
||||||
t.integer "amount"
|
t.integer "amount"
|
||||||
t.decimal "price", precision: 10, scale: 2
|
t.decimal "price", precision: 8, scale: 2
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "creator_str"
|
t.string "creator_str"
|
||||||
|
@ -349,7 +357,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do
|
||||||
t.string "currency", null: false
|
t.string "currency", null: false
|
||||||
t.string "description"
|
t.string "description"
|
||||||
t.string "reference_no"
|
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.datetime "paid_at"
|
||||||
t.integer "seller_id"
|
t.integer "seller_id"
|
||||||
t.string "seller_name", null: false
|
t.string "seller_name", null: false
|
||||||
|
@ -382,7 +390,7 @@ ActiveRecord::Schema.define(version: 20150609103333) do
|
||||||
t.string "updator_str"
|
t.string "updator_str"
|
||||||
t.integer "number"
|
t.integer "number"
|
||||||
t.datetime "cancelled_at"
|
t.datetime "cancelled_at"
|
||||||
t.decimal "sum_cache", precision: 10, scale: 2
|
t.decimal "sum_cache", precision: 8, scale: 2
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "invoices", ["buyer_id"], name: "index_invoices_on_buyer_id", using: :btree
|
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.text "crt"
|
||||||
t.string "type"
|
t.string "type"
|
||||||
t.string "registrant_ident"
|
t.string "registrant_ident"
|
||||||
t.string "encrypted_password", default: ""
|
t.string "encrypted_password", default: "", null: false
|
||||||
t.datetime "remember_created_at"
|
t.datetime "remember_created_at"
|
||||||
t.integer "failed_attempts", default: 0, null: false
|
t.integer "failed_attempts", default: 0, null: false
|
||||||
t.datetime "locked_at"
|
t.datetime "locked_at"
|
||||||
|
|
|
@ -2079,9 +2079,10 @@ describe 'EPP Domain', epp: true do
|
||||||
Domain.start_expire_period
|
Domain.start_expire_period
|
||||||
Domain.start_redemption_grace_period
|
Domain.start_redemption_grace_period
|
||||||
|
|
||||||
domain.domain_statuses.where(value: DomainStatus::EXPIRED).count.should == 1
|
domain.reload
|
||||||
domain.domain_statuses.where(value: DomainStatus::SERVER_HOLD).count.should == 1
|
domain.statuses.include?(DomainStatus::EXPIRED).should == true
|
||||||
domain.domain_statuses.where(value: DomainStatus::OK).count.should == 0
|
domain.statuses.include?(DomainStatus::SERVER_HOLD).should == true
|
||||||
|
domain.statuses.include?(DomainStatus::OK).should == false
|
||||||
|
|
||||||
exp_date = domain.valid_to.to_date
|
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][:msg].should == 'Command completed successfully'
|
||||||
response[:results][0][:result_code].should == '1000'
|
response[:results][0][:result_code].should == '1000'
|
||||||
|
|
||||||
domain.domain_statuses.where(value: DomainStatus::EXPIRED).count.should == 0
|
domain.reload
|
||||||
domain.domain_statuses.where(value: DomainStatus::SERVER_HOLD).count.should == 0
|
domain.statuses.include?(DomainStatus::EXPIRED).should == false
|
||||||
domain.domain_statuses.where(value: DomainStatus::OK).count.should == 1
|
domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false
|
||||||
|
domain.statuses.include?(DomainStatus::OK).should == true
|
||||||
|
|
||||||
domain.reload
|
domain.reload
|
||||||
domain.valid_to.should be_within(5).of(new_valid_to)
|
domain.valid_to.should be_within(5).of(new_valid_to)
|
||||||
|
|
|
@ -441,24 +441,23 @@ describe Domain do
|
||||||
|
|
||||||
it 'manages statuses automatically' do
|
it 'manages statuses automatically' do
|
||||||
d = Fabricate(:domain)
|
d = Fabricate(:domain)
|
||||||
expect(d.domain_statuses.count).to eq(1)
|
expect(d.statuses.count).to eq(1)
|
||||||
expect(d.domain_statuses.first.value).to eq(DomainStatus::OK)
|
expect(d.statuses.first).to eq(DomainStatus::OK)
|
||||||
|
|
||||||
d.period = 2
|
d.period = 2
|
||||||
d.save
|
d.save
|
||||||
|
|
||||||
d.reload
|
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)
|
d.statuses << DomainStatus::CLIENT_DELETE_PROHIBITED
|
||||||
expect(d.domain_statuses.first.reload.value).to eq(DomainStatus::OK)
|
|
||||||
|
|
||||||
d.domain_statuses.build(value: DomainStatus::CLIENT_DELETE_PROHIBITED)
|
|
||||||
d.save
|
d.save
|
||||||
|
|
||||||
d.reload
|
d.reload
|
||||||
|
|
||||||
expect(d.domain_statuses.count).to eq(1)
|
expect(d.statuses.count).to eq(1)
|
||||||
expect(d.domain_statuses.first.value).to eq(DomainStatus::CLIENT_DELETE_PROHIBITED)
|
expect(d.statuses.first).to eq(DomainStatus::CLIENT_DELETE_PROHIBITED)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_versioning do
|
with_versioning do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue