mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 18:56:05 +02:00
Transfer refactor
This commit is contained in:
parent
611130addc
commit
ad03165546
13 changed files with 172 additions and 18 deletions
|
@ -63,10 +63,7 @@ module Epp::DomainsHelper
|
|||
@domain = find_domain
|
||||
|
||||
handle_errors(@domain) and return unless @domain
|
||||
|
||||
@domain.transfer_requested_at = Time.now
|
||||
@domain.transferred_at = Time.now
|
||||
@domain.save
|
||||
handle_errors(@domain) and return unless @domain.transfer(@ph[:authInfo][:pw], current_epp_user)
|
||||
|
||||
render '/epp/domains/transfer'
|
||||
end
|
||||
|
|
|
@ -30,6 +30,8 @@ class Domain < ActiveRecord::Base
|
|||
joins(:setting).where(settings: { setting_group_id: SettingGroup.domain_statuses.id })
|
||||
}
|
||||
|
||||
has_many :domain_transfers
|
||||
|
||||
delegate :code, to: :owner_contact, prefix: true
|
||||
delegate :name, to: :registrar, prefix: true
|
||||
|
||||
|
@ -202,6 +204,38 @@ class Domain < ActiveRecord::Base
|
|||
save
|
||||
end
|
||||
|
||||
### TRANSFER ###
|
||||
def transfer(pw, current_user)
|
||||
return false unless authenticate(pw)
|
||||
return true if pending_transfer
|
||||
|
||||
wait_time = SettingGroup.domain_general.setting(:transfer_wait_time).value.to_i
|
||||
|
||||
if wait_time > 0
|
||||
domain_transfers.create(
|
||||
status: DomainTransfer::PENDING,
|
||||
transfer_requested_at: Time.zone.now,
|
||||
transfer_to: current_user.registrar,
|
||||
transfer_from: registrar
|
||||
)
|
||||
else
|
||||
domain_transfers.create(
|
||||
status: DomainTransfer::SERVER_APPROVED,
|
||||
transfer_requested_at: Time.zone.now,
|
||||
transferred_at: Time.zone.now,
|
||||
transfer_to: current_user.registrar,
|
||||
transfer_from: registrar
|
||||
)
|
||||
|
||||
self.registrar = current_user.registrar
|
||||
save
|
||||
end
|
||||
end
|
||||
|
||||
def pending_transfer
|
||||
domain_transfers.find_by(status: DomainTransfer::PENDING)
|
||||
end
|
||||
|
||||
### VALIDATIONS ###
|
||||
|
||||
def validate_nameservers_count
|
||||
|
|
13
app/models/domain_transfer.rb
Normal file
13
app/models/domain_transfer.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
class DomainTransfer < ActiveRecord::Base
|
||||
belongs_to :domain
|
||||
|
||||
belongs_to :transfer_from, class_name: 'Registrar'
|
||||
belongs_to :transfer_to, class_name: 'Registrar'
|
||||
|
||||
PENDING = 'pending'
|
||||
CLIENT_APPROVED = 'clientApproved'
|
||||
CLIENT_CANCELLED = 'clientCancelled'
|
||||
CLIENT_REJECTED = 'clientRejected'
|
||||
SERVER_APPROVED = 'serverApproved'
|
||||
SERVER_CANCELLED = 'serverCancelled'
|
||||
end
|
|
@ -17,5 +17,9 @@ class SettingGroup < ActiveRecord::Base
|
|||
def domain_statuses
|
||||
find_by(code: 'domain_statuses')
|
||||
end
|
||||
|
||||
def domain_general
|
||||
find_by(code: 'domain_general')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,11 +7,12 @@ xml.epp_head do
|
|||
xml.resData do
|
||||
xml.tag!('domain:trnData', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do
|
||||
xml.tag!('domain:name', @domain.name)
|
||||
xml.tag!('domain:trStatus', 'serverApproved')
|
||||
xml.tag!('domain:reID', current_epp_user.username)
|
||||
xml.tag!('domain:reDate', @domain.transfer_requested_at)
|
||||
xml.tag!('domain:acID', current_epp_user.username)
|
||||
xml.tag!('domain:acDate', @domain.transferred_at)
|
||||
ldt = @domain.domain_transfers.last
|
||||
xml.tag!('domain:trStatus', ldt.status)
|
||||
xml.tag!('domain:reID', ldt.transfer_to.reg_no)
|
||||
xml.tag!('domain:reDate', ldt.transfer_requested_at)
|
||||
xml.tag!('domain:acID', ldt.transfer_from.reg_no)
|
||||
xml.tag!('domain:acDate', ldt.transferred_at) if ldt.transferred_at
|
||||
xml.tag!('domain:exDate', @domain.valid_to)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
class PopulateGeneralDomainSettings < ActiveRecord::Migration
|
||||
def change
|
||||
SettingGroup.create(
|
||||
code: 'domain_general',
|
||||
settings: [
|
||||
Setting.create(code: 'transfer_wait_time', value: 0)
|
||||
]
|
||||
)
|
||||
end
|
||||
end
|
14
db/migrate/20140828074404_create_domain_transfer.rb
Normal file
14
db/migrate/20140828074404_create_domain_transfer.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
class CreateDomainTransfer < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :domain_transfers do |t|
|
||||
t.integer :domain_id
|
||||
t.string :status
|
||||
t.datetime :transfer_requested_at
|
||||
t.datetime :transferred_at
|
||||
t.integer :transfer_from_id
|
||||
t.integer :transfer_to_id
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
class RemoveTransferFieldsFromDomain < ActiveRecord::Migration
|
||||
def change
|
||||
remove_column :domains, :transferred_at
|
||||
remove_column :domains, :transfer_requested_at
|
||||
remove_column :domains, :transfer_to
|
||||
end
|
||||
end
|
18
db/schema.rb
18
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: 20140827140759) do
|
||||
ActiveRecord::Schema.define(version: 20140828080320) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -73,6 +73,17 @@ ActiveRecord::Schema.define(version: 20140827140759) do
|
|||
t.string "description"
|
||||
end
|
||||
|
||||
create_table "domain_transfers", force: true do |t|
|
||||
t.integer "domain_id"
|
||||
t.string "status"
|
||||
t.datetime "transfer_requested_at"
|
||||
t.datetime "transferred_at"
|
||||
t.integer "transfer_from_id"
|
||||
t.integer "transfer_to_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "domains", force: true do |t|
|
||||
t.string "name"
|
||||
t.integer "registrar_id"
|
||||
|
@ -90,10 +101,7 @@ ActiveRecord::Schema.define(version: 20140827140759) do
|
|||
t.string "name_dirty"
|
||||
t.string "name_puny"
|
||||
t.integer "period"
|
||||
t.string "period_unit", limit: 1
|
||||
t.datetime "transferred_at"
|
||||
t.datetime "transfer_requested_at"
|
||||
t.integer "transfer_to"
|
||||
t.string "period_unit", limit: 1
|
||||
end
|
||||
|
||||
create_table "epp_sessions", force: true do |t|
|
||||
|
|
|
@ -29,6 +29,61 @@ describe 'EPP Domain', epp: true do
|
|||
expect(response[:clTRID]).to eq('ABC-12345')
|
||||
end
|
||||
|
||||
context 'with two epp users' do
|
||||
before(:each) do
|
||||
elkdata = Fabricate(:registrar,
|
||||
name: 'Elkdata',
|
||||
reg_no: '123'
|
||||
)
|
||||
|
||||
Fabricate(:epp_user, username: 'elkdata_user', registrar: elkdata)
|
||||
Fabricate(:domain_general_setting_group)
|
||||
Fabricate(:domain, name: 'example.ee', registrar: elkdata)
|
||||
end
|
||||
|
||||
it 'transfers a domain' do
|
||||
response = epp_request('domains/transfer.xml')
|
||||
|
||||
d = Domain.first
|
||||
dtl = d.domain_transfers.last
|
||||
|
||||
trn_data = response[:parsed].css('trnData')
|
||||
expect(trn_data.css('name').text).to eq('example.ee')
|
||||
expect(trn_data.css('trStatus').text).to eq('serverApproved')
|
||||
expect(trn_data.css('reID').text).to eq('10577829')
|
||||
expect(trn_data.css('reDate').text).to eq(dtl.transfer_requested_at.to_time.utc.to_s)
|
||||
expect(trn_data.css('acID').text).to eq('123')
|
||||
expect(trn_data.css('acDate').text).to eq(dtl.transferred_at.to_time.utc.to_s)
|
||||
expect(trn_data.css('exDate').text).to eq(d.valid_to.to_time.utc.to_s)
|
||||
|
||||
s = Setting.find_by(code: 'transfer_wait_time')
|
||||
s.update(value: 1)
|
||||
|
||||
response = epp_request('domains/transfer.xml')
|
||||
trn_data = response[:parsed].css('trnData')
|
||||
d = Domain.first
|
||||
|
||||
expect(trn_data.css('name').text).to eq('example.ee')
|
||||
expect(trn_data.css('trStatus').text).to eq('pending')
|
||||
expect(trn_data.css('reID').text).to eq('10577829')
|
||||
expect(trn_data.css('reDate').text).to eq(dtl.transfer_requested_at.to_time.utc.to_s)
|
||||
expect(trn_data.css('acID').text).to eq('10577829')
|
||||
expect(trn_data.css('exDate').text).to eq(d.valid_to.to_time.utc.to_s)
|
||||
|
||||
# should return same data if pending already
|
||||
response = epp_request('domains/transfer.xml')
|
||||
trn_data = response[:parsed].css('trnData')
|
||||
d = Domain.first
|
||||
|
||||
expect(trn_data.css('name').text).to eq('example.ee')
|
||||
expect(trn_data.css('trStatus').text).to eq('pending')
|
||||
expect(trn_data.css('reID').text).to eq('10577829')
|
||||
expect(trn_data.css('reDate').text).to eq(dtl.transfer_requested_at.to_time.utc.to_s)
|
||||
expect(trn_data.css('acID').text).to eq('10577829')
|
||||
expect(trn_data.css('exDate').text).to eq(d.valid_to.to_time.utc.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with citizen as an owner' do
|
||||
before(:each) do
|
||||
Fabricate(:contact, code: 'jd1234')
|
||||
|
@ -349,10 +404,6 @@ describe 'EPP Domain', epp: true do
|
|||
expect(d.owner_contact_code).to eq('mak21')
|
||||
expect(d.auth_info).to eq('2BARfoo')
|
||||
end
|
||||
|
||||
it 'transfers a domain' do
|
||||
response = epp_request('domains/transfer.xml')
|
||||
end
|
||||
end
|
||||
|
||||
it 'checks a domain' do
|
||||
|
|
|
@ -27,3 +27,12 @@ Fabricator(:domain_statuses_setting_group, from: :setting_group) do
|
|||
]
|
||||
end
|
||||
end
|
||||
|
||||
Fabricator(:domain_general_setting_group, from: :setting_group) do
|
||||
code 'domain_general'
|
||||
settings do
|
||||
[
|
||||
Fabricate(:setting, code: 'transfer_wait_time', value: '0')
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,6 +6,7 @@ describe Domain do
|
|||
it { should belong_to(:owner_contact) }
|
||||
it { should have_many(:tech_contacts) }
|
||||
it { should have_many(:admin_contacts) }
|
||||
it { should have_many(:domain_transfers) }
|
||||
|
||||
context 'with sufficient settings' do
|
||||
before(:each) { Fabricate(:domain_validation_setting_group) }
|
||||
|
|
5
spec/models/domain_transfer_spec.rb
Normal file
5
spec/models/domain_transfer_spec.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe DomainTransfer do
|
||||
it { should belong_to(:domain) }
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue