mirror of
https://github.com/internetee/registry.git
synced 2025-07-02 01:03:35 +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
|
@ -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' }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
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
|
44
db/schema.rb
44
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"
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue