From 707c60b36e50f770553de9041109ad6ee3044da8 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Wed, 27 Aug 2014 17:25:39 +0300 Subject: [PATCH] Basic transfer command for domain --- app/controllers/concerns/epp/common.rb | 2 ++ app/controllers/epp/commands_controller.rb | 4 ++++ app/helpers/epp/domains_helper.rb | 18 ++++++++++++++++ app/views/epp/domains/transfer.xml.builder | 21 +++++++++++++++++++ ...827140759_add_transfer_fields_to_domain.rb | 7 +++++++ db/schema.rb | 7 +++++-- spec/epp/domain_spec.rb | 4 ++++ spec/epp/requests/domains/transfer.xml | 15 +++++++++++++ 8 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 app/views/epp/domains/transfer.xml.builder create mode 100644 db/migrate/20140827140759_add_transfer_fields_to_domain.rb create mode 100644 spec/epp/requests/domains/transfer.xml diff --git a/app/controllers/concerns/epp/common.rb b/app/controllers/concerns/epp/common.rb index 21288d4f1..b91a2ffc8 100644 --- a/app/controllers/concerns/epp/common.rb +++ b/app/controllers/concerns/epp/common.rb @@ -9,6 +9,8 @@ module Epp::Common included do protect_from_forgery with: :null_session before_action :validate_request, only: [:proxy] + + helper_method :current_epp_user end def proxy diff --git a/app/controllers/epp/commands_controller.rb b/app/controllers/epp/commands_controller.rb index 587394e5e..49820e468 100644 --- a/app/controllers/epp/commands_controller.rb +++ b/app/controllers/epp/commands_controller.rb @@ -14,6 +14,10 @@ class Epp::CommandsController < ApplicationController send("renew_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}") end + def transfer + send("transfer_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}") + end + def check send("check_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}") end diff --git a/app/helpers/epp/domains_helper.rb b/app/helpers/epp/domains_helper.rb index 4ef04679a..95845c61c 100644 --- a/app/helpers/epp/domains_helper.rb +++ b/app/helpers/epp/domains_helper.rb @@ -59,6 +59,18 @@ module Epp::DomainsHelper end end + def transfer_domain + @domain = find_domain + + handle_errors(@domain) and return unless @domain + + @domain.transfer_requested_at = Time.now + @domain.transferred_at = Time.now + @domain.save + + render '/epp/domains/transfer' + end + ### HELPER METHODS ### private @@ -104,6 +116,12 @@ module Epp::DomainsHelper xml_attrs_present?(@ph, [['name']]) end + ## TRANSFER + def validate_domain_transfer_request + @ph = params_hash['epp']['command']['transfer']['transfer'] + xml_attrs_present?(@ph, [['name']]) + end + ## SHARED def find_domain domain = Domain.find_by(name: @ph[:name]) diff --git a/app/views/epp/domains/transfer.xml.builder b/app/views/epp/domains/transfer.xml.builder new file mode 100644 index 000000000..60e5c745f --- /dev/null +++ b/app/views/epp/domains/transfer.xml.builder @@ -0,0 +1,21 @@ +xml.epp_head do + xml.response do + xml.result('code' => '1000') do + xml.msg 'Command completed successfully' + end + + 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) + xml.tag!('domain:exDate', @domain.valid_to) + end + end + end + + xml << render('/epp/shared/trID') +end diff --git a/db/migrate/20140827140759_add_transfer_fields_to_domain.rb b/db/migrate/20140827140759_add_transfer_fields_to_domain.rb new file mode 100644 index 000000000..03e8d79d5 --- /dev/null +++ b/db/migrate/20140827140759_add_transfer_fields_to_domain.rb @@ -0,0 +1,7 @@ +class AddTransferFieldsToDomain < ActiveRecord::Migration + def change + add_column :domains, :transferred_at, :datetime + add_column :domains, :transfer_requested_at, :datetime + add_column :domains, :transfer_to, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index f72c9b6c0..8c08c938c 100644 --- a/db/schema.rb +++ b/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: 20140826103454) do +ActiveRecord::Schema.define(version: 20140827140759) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -90,7 +90,10 @@ ActiveRecord::Schema.define(version: 20140826103454) do t.string "name_dirty" t.string "name_puny" t.integer "period" - t.string "period_unit", limit: 1 + t.string "period_unit", limit: 1 + t.datetime "transferred_at" + t.datetime "transfer_requested_at" + t.integer "transfer_to" end create_table "epp_sessions", force: true do |t| diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 7f82a7b36..bb97dee67 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -349,6 +349,10 @@ 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 diff --git a/spec/epp/requests/domains/transfer.xml b/spec/epp/requests/domains/transfer.xml new file mode 100644 index 000000000..45453f4e7 --- /dev/null +++ b/spec/epp/requests/domains/transfer.xml @@ -0,0 +1,15 @@ + + + + + + example.ee + + 98oiewslkfkd + + + + ABC-12345 + +