mirror of
https://github.com/internetee/registry.git
synced 2025-07-03 01:33:36 +02:00
Basic poll implementation
This commit is contained in:
parent
c0edfd4b5b
commit
6888cd15a4
13 changed files with 82 additions and 21 deletions
|
@ -9,6 +9,14 @@ class Epp::CommandsController < ApplicationController
|
||||||
|
|
||||||
private
|
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
|
def create
|
||||||
send("create_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
|
send("create_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
|
||||||
end
|
end
|
||||||
|
|
|
@ -80,7 +80,9 @@ module Epp::DomainsHelper
|
||||||
@domain = find_domain(secure: false)
|
@domain = find_domain(secure: false)
|
||||||
|
|
||||||
handle_errors(@domain) and return unless @domain
|
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'
|
render '/epp/domains/transfer'
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,6 +13,8 @@ class DomainTransfer < ActiveRecord::Base
|
||||||
|
|
||||||
before_create :set_wait_until
|
before_create :set_wait_until
|
||||||
|
|
||||||
|
delegate :name, :valid_to, to: :domain, prefix: true
|
||||||
|
|
||||||
def set_wait_until
|
def set_wait_until
|
||||||
wait_time = Setting.transfer_wait_time
|
wait_time = Setting.transfer_wait_time
|
||||||
return if wait_time == 0
|
return if wait_time == 0
|
||||||
|
|
|
@ -285,7 +285,12 @@ class Epp::EppDomain < Domain
|
||||||
|
|
||||||
pt = pending_transfer
|
pt = pending_transfer
|
||||||
if pt && params[:action] == 'approve'
|
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
|
end
|
||||||
|
|
||||||
if !pt && params[:action] != 'query'
|
if !pt && params[:action] != 'query'
|
||||||
|
@ -297,17 +302,24 @@ class Epp::EppDomain < Domain
|
||||||
return false unless can_be_transferred_to?(params[:current_user].registrar)
|
return false unless can_be_transferred_to?(params[:current_user].registrar)
|
||||||
end
|
end
|
||||||
|
|
||||||
return true if pt
|
return pt if pt
|
||||||
|
|
||||||
if Setting.transfer_wait_time > 0
|
if Setting.transfer_wait_time > 0
|
||||||
domain_transfers.create(
|
dt = domain_transfers.create(
|
||||||
status: DomainTransfer::PENDING,
|
status: DomainTransfer::PENDING,
|
||||||
transfer_requested_at: Time.zone.now,
|
transfer_requested_at: Time.zone.now,
|
||||||
transfer_to: params[:current_user].registrar,
|
transfer_to: params[:current_user].registrar,
|
||||||
transfer_from: 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
|
else
|
||||||
domain_transfers.create(
|
dt = domain_transfers.create(
|
||||||
status: DomainTransfer::SERVER_APPROVED,
|
status: DomainTransfer::SERVER_APPROVED,
|
||||||
transfer_requested_at: Time.zone.now,
|
transfer_requested_at: Time.zone.now,
|
||||||
transferred_at: Time.zone.now,
|
transferred_at: Time.zone.now,
|
||||||
|
@ -320,6 +332,8 @@ class Epp::EppDomain < Domain
|
||||||
self.registrar = params[:current_user].registrar
|
self.registrar = params[:current_user].registrar
|
||||||
save(validate: false)
|
save(validate: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
dt
|
||||||
end
|
end
|
||||||
# rubocop: enable Metrics/PerceivedComplexity
|
# rubocop: enable Metrics/PerceivedComplexity
|
||||||
# rubocop: enable Metrics/MethodLength
|
# rubocop: enable Metrics/MethodLength
|
||||||
|
|
|
@ -16,5 +16,9 @@ class EppUser < ActiveRecord::Base
|
||||||
def to_s
|
def to_s
|
||||||
username
|
username
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def queued_messages
|
||||||
|
registrar.messages.queued
|
||||||
|
end
|
||||||
end
|
end
|
||||||
# rubocop: enable Metrics/ClassLength
|
# rubocop: enable Metrics/ClassLength
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
class Message < ActiveRecord::Base
|
class Message < ActiveRecord::Base
|
||||||
belongs_to :registrar
|
belongs_to :registrar
|
||||||
|
|
||||||
|
before_create -> { self.queued = true }
|
||||||
|
|
||||||
|
scope :queued, -> { where(queued: true) }
|
||||||
end
|
end
|
||||||
|
|
9
app/views/epp/domains/partials/_transfer.xml.builder
Normal file
9
app/views/epp/domains/partials/_transfer.xml.builder
Normal 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
|
|
@ -5,16 +5,7 @@ xml.epp_head do
|
||||||
end
|
end
|
||||||
|
|
||||||
xml.resData do
|
xml.resData do
|
||||||
xml.tag!('domain:trnData', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do
|
xml << render('epp/domains/partials/transfer', builder: xml, dt: @domain_transfer)
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
20
app/views/epp/poll.xml.builder
Normal file
20
app/views/epp/poll.xml.builder
Normal 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
|
|
@ -419,5 +419,5 @@ en:
|
||||||
ds_algorithm: 'DS algorithm'
|
ds_algorithm: 'DS algorithm'
|
||||||
setting: 'Setting'
|
setting: 'Setting'
|
||||||
|
|
||||||
registrar: Registrar
|
registrar: 'Registrar'
|
||||||
|
transfer_requested: 'Transfer requested.'
|
||||||
|
|
|
@ -3,8 +3,8 @@ class CreateMessages < ActiveRecord::Migration
|
||||||
create_table :messages do |t|
|
create_table :messages do |t|
|
||||||
t.integer :registrar_id
|
t.integer :registrar_id
|
||||||
t.string :body
|
t.string :body
|
||||||
t.string :object_type
|
t.string :attached_obj_type
|
||||||
t.string :object
|
t.string :attached_obj_id
|
||||||
t.boolean :queued
|
t.boolean :queued
|
||||||
|
|
||||||
t.timestamps
|
t.timestamps
|
||||||
|
|
|
@ -202,8 +202,8 @@ ActiveRecord::Schema.define(version: 20141105150721) do
|
||||||
create_table "messages", force: true do |t|
|
create_table "messages", force: true do |t|
|
||||||
t.integer "registrar_id"
|
t.integer "registrar_id"
|
||||||
t.string "body"
|
t.string "body"
|
||||||
t.string "object_type"
|
t.string "attached_obj_type"
|
||||||
t.string "object"
|
t.string "attached_obj_id"
|
||||||
t.boolean "queued"
|
t.boolean "queued"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
|
|
|
@ -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(trn_data.css('exDate').text).to eq(domain.valid_to.to_time.utc.to_s)
|
||||||
|
|
||||||
expect(domain.registrar).to eq(elkdata)
|
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
|
end
|
||||||
|
|
||||||
it 'prohibits wrong registrar from approving transfer' do
|
it 'prohibits wrong registrar from approving transfer' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue