Basic poll implementation

This commit is contained in:
Martin Lensment 2014-11-06 13:51:28 +02:00
parent c0edfd4b5b
commit 6888cd15a4
13 changed files with 82 additions and 21 deletions

View file

@ -9,6 +9,14 @@ class Epp::CommandsController < ApplicationController
private
def poll
@message = current_epp_user.registrar.messages.last
if @message.attached_obj_type && @message.attached_obj_id
@object = Object.const_get(@message.attached_obj_type).find(@message.attached_obj_id)
end
render 'epp/poll'
end
def create
send("create_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
end

View file

@ -80,7 +80,9 @@ module Epp::DomainsHelper
@domain = find_domain(secure: false)
handle_errors(@domain) and return unless @domain
handle_errors(@domain) and return unless @domain.transfer(domain_transfer_params)
@domain_transfer = @domain.transfer(domain_transfer_params)
handle_errors(@domain) and return unless @domain_transfer
render '/epp/domains/transfer'
end

View file

@ -13,6 +13,8 @@ class DomainTransfer < ActiveRecord::Base
before_create :set_wait_until
delegate :name, :valid_to, to: :domain, prefix: true
def set_wait_until
wait_time = Setting.transfer_wait_time
return if wait_time == 0

View file

@ -285,7 +285,12 @@ class Epp::EppDomain < Domain
pt = pending_transfer
if pt && params[:action] == 'approve'
return approve_pending_transfer(params[:current_user])
if approve_pending_transfer(params[:current_user])
return pt.reload
else
return false
end
end
if !pt && params[:action] != 'query'
@ -297,17 +302,24 @@ class Epp::EppDomain < Domain
return false unless can_be_transferred_to?(params[:current_user].registrar)
end
return true if pt
return pt if pt
if Setting.transfer_wait_time > 0
domain_transfers.create(
dt = domain_transfers.create(
status: DomainTransfer::PENDING,
transfer_requested_at: Time.zone.now,
transfer_to: params[:current_user].registrar,
transfer_from: registrar
)
registrar.messages.create(
body: I18n.t('transfer_requested'),
attached_obj_id: dt.id,
attached_obj_type: dt.class.to_s
)
else
domain_transfers.create(
dt = domain_transfers.create(
status: DomainTransfer::SERVER_APPROVED,
transfer_requested_at: Time.zone.now,
transferred_at: Time.zone.now,
@ -320,6 +332,8 @@ class Epp::EppDomain < Domain
self.registrar = params[:current_user].registrar
save(validate: false)
end
dt
end
# rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/MethodLength

View file

@ -16,5 +16,9 @@ class EppUser < ActiveRecord::Base
def to_s
username
end
def queued_messages
registrar.messages.queued
end
end
# rubocop: enable Metrics/ClassLength

View file

@ -1,3 +1,7 @@
class Message < ActiveRecord::Base
belongs_to :registrar
before_create -> { self.queued = true }
scope :queued, -> { where(queued: true) }
end

View file

@ -0,0 +1,9 @@
builder.tag!('domain:trnData', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do
builder.tag!('domain:name', dt.domain_name)
builder.tag!('domain:trStatus', dt.status)
builder.tag!('domain:reID', dt.transfer_to.reg_no)
builder.tag!('domain:reDate', dt.transfer_requested_at)
builder.tag!('domain:acID', dt.transfer_from.reg_no)
builder.tag!('domain:acDate', dt.transferred_at || dt.wait_until)
builder.tag!('domain:exDate', dt.domain_valid_to)
end

View file

@ -5,16 +5,7 @@ xml.epp_head do
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)
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 || ldt.wait_until)
xml.tag!('domain:exDate', @domain.valid_to)
end
xml << render('epp/domains/partials/transfer', builder: xml, dt: @domain_transfer)
end
end

View file

@ -0,0 +1,20 @@
xml.epp_head do
xml.response do
xml.result('code' => '1301') do
xml.msg 'Command completed successfully; ack to dequeue'
end
xml.tag!('msgQ', 'count' => current_epp_user.queued_messages.count, 'id' => @message.id) do
xml.qDate @message.created_at
xml.msg @message.body
end
xml.resData do
if @message.attached_obj_type == 'DomainTransfer'
xml << render('epp/domains/partials/transfer', builder: xml, dt: @object)
end
end if @object
xml << render('/epp/shared/trID')
end
end

View file

@ -419,5 +419,5 @@ en:
ds_algorithm: 'DS algorithm'
setting: 'Setting'
registrar: Registrar
registrar: 'Registrar'
transfer_requested: 'Transfer requested.'

View file

@ -3,8 +3,8 @@ class CreateMessages < ActiveRecord::Migration
create_table :messages do |t|
t.integer :registrar_id
t.string :body
t.string :object_type
t.string :object
t.string :attached_obj_type
t.string :attached_obj_id
t.boolean :queued
t.timestamps

View file

@ -202,8 +202,8 @@ ActiveRecord::Schema.define(version: 20141105150721) do
create_table "messages", force: true do |t|
t.integer "registrar_id"
t.string "body"
t.string "object_type"
t.string "object"
t.string "attached_obj_type"
t.string "attached_obj_id"
t.boolean "queued"
t.datetime "created_at"
t.datetime "updated_at"

View file

@ -100,6 +100,13 @@ describe 'EPP Domain', epp: true do
expect(trn_data.css('exDate').text).to eq(domain.valid_to.to_time.utc.to_s)
expect(domain.registrar).to eq(elkdata)
# should show up in other registrar's poll
response = epp_request(EppXml::Session.poll, :xml, :elkdata)
msg_q = response[:parsed].css('msgQ')
expect(msg_q.css('qDate').text).to_not be_blank
expect(msg_q.css('msg').text).to eq('Transfer requested.')
end
it 'prohibits wrong registrar from approving transfer' do