mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 08:22:05 +02:00
Merge branch 'master' of github.com:internetee/registry
This commit is contained in:
commit
a0c9c303db
25 changed files with 440 additions and 174 deletions
|
@ -2,6 +2,7 @@ class Epp::CommandsController < ApplicationController
|
|||
include Epp::Common
|
||||
include Epp::DomainsHelper
|
||||
include Epp::ContactsHelper
|
||||
include Epp::PollHelper
|
||||
include Shared::UserStamper
|
||||
helper WhodunnitHelper
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
41
app/helpers/epp/poll_helper.rb
Normal file
41
app/helpers/epp/poll_helper.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
module Epp::PollHelper
|
||||
def poll
|
||||
req_poll if parsed_frame.css('poll').first['op'] == 'req'
|
||||
ack_poll if parsed_frame.css('poll').first['op'] == 'ack'
|
||||
end
|
||||
|
||||
def req_poll
|
||||
@message = current_epp_user.queued_messages.last
|
||||
render 'epp/poll/poll_no_messages' and return unless @message
|
||||
|
||||
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/poll_req'
|
||||
end
|
||||
|
||||
def ack_poll
|
||||
@message = current_epp_user.queued_messages.find_by(id: parsed_frame.css('poll').first['msgID'])
|
||||
|
||||
unless @message
|
||||
epp_errors << {
|
||||
code: '2303',
|
||||
msg: I18n.t('message_was_not_found'),
|
||||
value: { obj: 'msgID', val: parsed_frame.css('poll').first['msgID'] }
|
||||
}
|
||||
handle_errors and return
|
||||
end
|
||||
|
||||
handle_errors(@message) and return unless @message.dequeue
|
||||
render 'epp/poll/poll_ack'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def validate__poll_request
|
||||
op = parsed_frame.css('poll').first[:op]
|
||||
return true if %w(ack req).include?(op)
|
||||
epp_errors << { code: '2306', msg: I18n.t('errors.messages.attribute_op_is_invalid') }
|
||||
false
|
||||
end
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
12
app/models/message.rb
Normal file
12
app/models/message.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
class Message < ActiveRecord::Base
|
||||
belongs_to :registrar
|
||||
|
||||
before_create -> { self.queued = true }
|
||||
|
||||
scope :queued, -> { where(queued: true) }
|
||||
|
||||
def dequeue
|
||||
self.queued = false
|
||||
save
|
||||
end
|
||||
end
|
|
@ -4,6 +4,7 @@ class Registrar < ActiveRecord::Base
|
|||
has_many :contacts, dependent: :restrict_with_error
|
||||
has_many :epp_users, dependent: :restrict_with_error
|
||||
has_many :users, dependent: :restrict_with_error
|
||||
has_many :messages
|
||||
|
||||
validates :name, :reg_no, :address, :country, presence: true
|
||||
validates :name, :reg_no, uniqueness: true
|
||||
|
|
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
|
||||
|
||||
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
|
||||
|
||||
|
|
11
app/views/epp/poll/poll_ack.xml.builder
Normal file
11
app/views/epp/poll/poll_ack.xml.builder
Normal file
|
@ -0,0 +1,11 @@
|
|||
xml.epp_head do
|
||||
xml.response do
|
||||
xml.result('code' => '1000') do
|
||||
xml.msg 'Command completed successfully'
|
||||
end
|
||||
|
||||
xml.tag!('msgQ', 'count' => current_epp_user.queued_messages.count, 'id' => @message.id)
|
||||
|
||||
xml << render('/epp/shared/trID')
|
||||
end
|
||||
end
|
9
app/views/epp/poll/poll_no_messages.xml.builder
Normal file
9
app/views/epp/poll/poll_no_messages.xml.builder
Normal file
|
@ -0,0 +1,9 @@
|
|||
xml.epp_head do
|
||||
xml.response do
|
||||
xml.result('code' => '1300') do
|
||||
xml.msg 'Command completed successfully; no messages'
|
||||
end
|
||||
|
||||
xml << render('/epp/shared/trID')
|
||||
end
|
||||
end
|
20
app/views/epp/poll/poll_req.xml.builder
Normal file
20
app/views/epp/poll/poll_req.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
|
Loading…
Add table
Add a link
Reference in a new issue