From 715a4eff719820941508ec70f6287638dc683bce Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Thu, 28 Aug 2014 15:37:40 +0300 Subject: [PATCH] Transfer request approval implementation --- app/helpers/epp/domains_helper.rb | 10 +++++++++- app/models/contact.rb | 3 +-- app/models/domain.rb | 26 ++++++++++++++++++++------ spec/epp/domain_spec.rb | 7 ++++--- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/app/helpers/epp/domains_helper.rb b/app/helpers/epp/domains_helper.rb index 167fddad7..c30960f9a 100644 --- a/app/helpers/epp/domains_helper.rb +++ b/app/helpers/epp/domains_helper.rb @@ -63,7 +63,7 @@ module Epp::DomainsHelper @domain = find_domain handle_errors(@domain) and return unless @domain - handle_errors(@domain) and return unless @domain.transfer(@ph[:authInfo][:pw], current_epp_user) + handle_errors(@domain) and return unless @domain.transfer(domain_transfer_params) render '/epp/domains/transfer' end @@ -95,6 +95,14 @@ module Epp::DomainsHelper } end + def domain_transfer_params + res = {} + res[:pw] = parsed_frame.css('pw').first.try(:text) + res[:action] = parsed_frame.css('transfer').first[:op] + res[:current_user] = current_epp_user + res + end + ## RENEW def validate_domain_renew_request @ph = params_hash['epp']['command']['renew']['renew'] diff --git a/app/models/contact.rb b/app/models/contact.rb index e0d808c1b..9ab55b33c 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -73,8 +73,7 @@ class Contact < ActiveRecord::Base end def auth_info_matches(pw) - return true if auth_info == pw - false + auth_info == pw end # Find a way to use self.domains with contact diff --git a/app/models/domain.rb b/app/models/domain.rb index 92429e403..48f35c728 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -205,9 +205,12 @@ class Domain < ActiveRecord::Base end ### TRANSFER ### - def transfer(pw, current_user) - return false unless authenticate(pw) - return true if pending_transfer + def transfer(params) + return false unless authenticate(params[:pw]) + + if pending_transfer && params[:action] == 'approve' + approve_pending_transfer and return true + end wait_time = SettingGroup.domain_general.setting(:transfer_wait_time).value.to_i @@ -215,7 +218,7 @@ class Domain < ActiveRecord::Base domain_transfers.create( status: DomainTransfer::PENDING, transfer_requested_at: Time.zone.now, - transfer_to: current_user.registrar, + transfer_to: params[:current_user].registrar, transfer_from: registrar ) else @@ -223,15 +226,26 @@ class Domain < ActiveRecord::Base status: DomainTransfer::SERVER_APPROVED, transfer_requested_at: Time.zone.now, transferred_at: Time.zone.now, - transfer_to: current_user.registrar, + transfer_to: params[:current_user].registrar, transfer_from: registrar ) - self.registrar = current_user.registrar + self.registrar = params[:current_user].registrar save end end + def approve_pending_transfer + p = pending_transfer + p.update( + status: DomainTransfer::CLIENT_APPROVED, + transferred_at: Time.zone.now + ) + + self.registrar = p.transfer_to + save + end + def pending_transfer domain_transfers.find_by(status: DomainTransfer::PENDING) end diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index e04d7a30d..3077c35bf 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -84,7 +84,7 @@ describe 'EPP Domain', epp: true do expect(trn_data.css('exDate').text).to eq(d.valid_to.to_time.utc.to_s) end - it 'approves the transfer request', pending: true do + it 'approves the transfer request' do s = Setting.find_by(code: 'transfer_wait_time') s.update(value: 1) @@ -93,12 +93,13 @@ describe 'EPP Domain', epp: true do response = epp_request(xml, :xml) trn_data = response[:parsed].css('trnData') d = Domain.first + dtl = d.domain_transfers.last expect(trn_data.css('name').text).to eq('example.ee') - expect(trn_data.css('trStatus').text).to eq('serverApproved') + expect(trn_data.css('trStatus').text).to eq('clientApproved') 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('acID').text).to eq('123') expect(trn_data.css('exDate').text).to eq(d.valid_to.to_time.utc.to_s) end