mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +02:00
Domain statuses improvements
This commit is contained in:
parent
f43662e8b0
commit
e20944151e
10 changed files with 54 additions and 10 deletions
|
@ -25,11 +25,9 @@ class Domain < ActiveRecord::Base
|
||||||
|
|
||||||
has_and_belongs_to_many :nameservers
|
has_and_belongs_to_many :nameservers
|
||||||
|
|
||||||
has_many :domain_statuses
|
has_many :domain_statuses, -> {
|
||||||
|
joins(:setting).where(settings: {setting_group_id: SettingGroup.domain_statuses.id})
|
||||||
has_many :statuses, -> {
|
}
|
||||||
where(setting_group: SettingGroup.domain_statuses).uniq
|
|
||||||
}, through: :domain_statuses, source: :setting
|
|
||||||
|
|
||||||
delegate :code, to: :owner_contact, prefix: true
|
delegate :code, to: :owner_contact, prefix: true
|
||||||
delegate :name, to: :registrar, prefix: true
|
delegate :name, to: :registrar, prefix: true
|
||||||
|
@ -110,7 +108,11 @@ class Domain < ActiveRecord::Base
|
||||||
|
|
||||||
def attach_statuses(status_list)
|
def attach_statuses(status_list)
|
||||||
status_list.each do |x|
|
status_list.each do |x|
|
||||||
statuses << SettingGroup.domain_statuses.settings.find_by(value: x[:value])
|
setting = SettingGroup.domain_statuses.settings.find_by(value: x[:value])
|
||||||
|
self.domain_statuses.build(
|
||||||
|
setting: setting,
|
||||||
|
description: x[:description]
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,25 @@
|
||||||
class DomainStatus < ActiveRecord::Base
|
class DomainStatus < ActiveRecord::Base
|
||||||
|
# Domain statuses are stored as settings
|
||||||
|
include EppErrors
|
||||||
|
|
||||||
|
EPP_ATTR_MAP = {
|
||||||
|
setting: 'status'
|
||||||
|
}
|
||||||
|
|
||||||
belongs_to :domain
|
belongs_to :domain
|
||||||
belongs_to :setting
|
belongs_to :setting
|
||||||
|
|
||||||
|
delegate :value, :code, to: :setting
|
||||||
|
|
||||||
|
validates :setting, uniqueness: { scope: :domain_id }
|
||||||
|
|
||||||
|
def setting_uniqueness
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def epp_code_map
|
||||||
|
{
|
||||||
|
'2302' => [[:setting, :taken]]
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
class Setting < ActiveRecord::Base
|
class Setting < ActiveRecord::Base
|
||||||
belongs_to :setting_group
|
belongs_to :setting_group
|
||||||
|
has_many :domain_statuses
|
||||||
|
has_many :domains, through: :domain_statuses
|
||||||
validates :code, uniqueness: { scope: :setting_group_id }
|
validates :code, uniqueness: { scope: :setting_group_id }
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,6 +3,8 @@ class SettingGroup < ActiveRecord::Base
|
||||||
|
|
||||||
accepts_nested_attributes_for :settings
|
accepts_nested_attributes_for :settings
|
||||||
|
|
||||||
|
validates :code, uniqueness: true
|
||||||
|
|
||||||
def setting(key)
|
def setting(key)
|
||||||
settings.find_by(code: key.to_s)
|
settings.find_by(code: key.to_s)
|
||||||
end
|
end
|
||||||
|
|
|
@ -66,6 +66,10 @@ en:
|
||||||
attributes:
|
attributes:
|
||||||
code:
|
code:
|
||||||
taken: 'Code already exists'
|
taken: 'Code already exists'
|
||||||
|
domain_status:
|
||||||
|
attributes:
|
||||||
|
setting:
|
||||||
|
taken: 'Status already exists on this domain'
|
||||||
attributes:
|
attributes:
|
||||||
domain:
|
domain:
|
||||||
name: 'Domain name'
|
name: 'Domain name'
|
||||||
|
|
|
@ -3,6 +3,7 @@ class CreateDomainsStatuses < ActiveRecord::Migration
|
||||||
create_table :domain_statuses do |t|
|
create_table :domain_statuses do |t|
|
||||||
t.integer :domain_id
|
t.integer :domain_id
|
||||||
t.integer :setting_id
|
t.integer :setting_id
|
||||||
|
t.string :description
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
class PopulateDomainStatuses < ActiveRecord::Migration
|
class PopulateDomainStatuses < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
SettingGroup.create(code: 'domain_statuses', settings: [
|
sg = SettingGroup.create(code: 'domain_statuses')
|
||||||
|
sg.settings = [
|
||||||
Setting.create(code: 'clientDeleteProhibited'.underscore, value: 'clientDeleteProhibited'),
|
Setting.create(code: 'clientDeleteProhibited'.underscore, value: 'clientDeleteProhibited'),
|
||||||
Setting.create(code: 'serverDeleteProhibited'.underscore, value: 'serverDeleteProhibited'),
|
Setting.create(code: 'serverDeleteProhibited'.underscore, value: 'serverDeleteProhibited'),
|
||||||
Setting.create(code: 'clientHold'.underscore, value: 'clientHold'),
|
Setting.create(code: 'clientHold'.underscore, value: 'clientHold'),
|
||||||
|
@ -18,6 +19,7 @@ class PopulateDomainStatuses < ActiveRecord::Migration
|
||||||
Setting.create(code: 'pendingRenew'.underscore, value: 'pendingRenew'),
|
Setting.create(code: 'pendingRenew'.underscore, value: 'pendingRenew'),
|
||||||
Setting.create(code: 'pendingTransfer'.underscore, value: 'pendingTransfer'),
|
Setting.create(code: 'pendingTransfer'.underscore, value: 'pendingTransfer'),
|
||||||
Setting.create(code: 'pendingUpdate'.underscore, value: 'pendingUpdate')
|
Setting.create(code: 'pendingUpdate'.underscore, value: 'pendingUpdate')
|
||||||
])
|
]
|
||||||
|
sg.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -64,6 +64,7 @@ ActiveRecord::Schema.define(version: 20140819103517) do
|
||||||
create_table "domain_statuses", force: true do |t|
|
create_table "domain_statuses", force: true do |t|
|
||||||
t.integer "domain_id"
|
t.integer "domain_id"
|
||||||
t.integer "setting_id"
|
t.integer "setting_id"
|
||||||
|
t.string "description"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "domains", force: true do |t|
|
create_table "domains", force: true do |t|
|
||||||
|
|
|
@ -262,6 +262,15 @@ describe 'EPP Domain', epp: true do
|
||||||
|
|
||||||
new_contact = d.tech_contacts.find_by(code: 'mak21')
|
new_contact = d.tech_contacts.find_by(code: 'mak21')
|
||||||
expect(new_contact).to be_truthy
|
expect(new_contact).to be_truthy
|
||||||
|
|
||||||
|
expect(d.domain_statuses.count).to eq(1)
|
||||||
|
expect(d.domain_statuses.first.description).to eq('Payment overdue.')
|
||||||
|
expect(d.domain_statuses.first.value).to eq('clientHold')
|
||||||
|
expect(d.domain_statuses.first.code).to eq('client_hold')
|
||||||
|
|
||||||
|
response = epp_request('domains/update.xml')
|
||||||
|
|
||||||
|
expect(d.domain_statuses.count).to eq(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -283,7 +292,7 @@ describe 'EPP Domain', epp: true do
|
||||||
|
|
||||||
expect(name.text).to eq('example.ee')
|
expect(name.text).to eq('example.ee')
|
||||||
expect(name[:avail]).to eq('0')
|
expect(name[:avail]).to eq('0')
|
||||||
expect(reason.text).to eq('in use') #confirm this with current API
|
expect(reason.text).to eq('in use')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'checks multiple domains' do
|
it 'checks multiple domains' do
|
||||||
|
|
|
@ -13,7 +13,7 @@ describe Setting do
|
||||||
err = sg.settings.last.errors[:code].first
|
err = sg.settings.last.errors[:code].first
|
||||||
expect(err).to eq('Code already exists')
|
expect(err).to eq('Code already exists')
|
||||||
|
|
||||||
sg_2 = Fabricate(:setting_group)
|
sg_2 = Fabricate(:setting_group, code: 'domain_statuses')
|
||||||
|
|
||||||
sg_2.settings.build(code: 'this_is_code')
|
sg_2.settings.build(code: 'this_is_code')
|
||||||
expect(sg_2.save).to be true
|
expect(sg_2.save).to be true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue