Merge branch 'master' into registry-693

# Conflicts:
#	app/api/repp/domain_transfers_v1.rb
This commit is contained in:
Artur Beljajev 2018-02-24 06:24:49 +02:00
commit 1fad07963f
41 changed files with 524 additions and 285 deletions

View file

@ -25,7 +25,7 @@ module Repp
if domain
if domain.transfer_code == transfer_code
domain.transfer(new_registrar)
DomainTransfer.request(domain, new_registrar)
successful_domain_transfers << { type: 'domain_transfer', attributes: { domain_name: domain.name } }
else
errors << { title: "#{domain_name} transfer code is wrong" }

View file

@ -142,6 +142,13 @@ class Epp::DomainsController < EppController
authorize! :transfer, @domain, @password
action = params[:parsed_frame].css('transfer').first[:op]
if @domain.non_transferable?
throw :epp_error, {
code: '2304',
msg: I18n.t(:object_status_prohibits_operation)
}
end
@domain_transfer = @domain.transfer(params[:parsed_frame], action, current_user)
if @domain_transfer

View file

@ -6,6 +6,8 @@ class Epp::PollsController < EppController
ack_poll if params[:parsed_frame].css('poll').first['op'] == 'ack'
end
private
def req_poll
@message = current_user.queued_messages.last
@ -49,8 +51,6 @@ class Epp::PollsController < EppController
render_epp_response 'epp/poll/poll_ack'
end
private
def validate_poll
requires_attribute 'poll', 'op', values: %(ack req), allow_blank: true
end

View file

@ -335,7 +335,6 @@ class EppController < ApplicationController
# rubocop: disable Metrics/CyclomaticComplexity
# rubocop: disable Metrics/PerceivedComplexity
def write_to_epp_log
# return nil if EPP_LOG_ENABLED
request_command = params[:command] || params[:action] # error receives :command, other methods receive :action
frame = params[:raw_frame] || params[:frame]

View file

@ -2,31 +2,18 @@ module Concerns::Domain::Transferable
extend ActiveSupport::Concern
included do
after_initialize :generate_transfer_code, if: 'new_record? && transfer_code.blank?'
after_initialize :generate_transfer_code, if: :generate_transfer_code?
end
def non_transferable?
!transferable?
end
def transfer(new_registrar)
old_registrar = registrar
self.registrar = new_registrar
regenerate_transfer_code
contact_codes = contacts.pluck(:code).sort.uniq
registrant_code = registrant.code
transaction do
old_registrar.messages.create!(
body: I18n.t('domain_transfer_was_approved', contacts: contact_codes, registrant: registrant_code),
attached_obj_id: id,
attached_obj_type: self.class.name
)
domain_transfers.create!(
transfer_requested_at: Time.zone.now,
old_registrar: old_registrar,
new_registrar: new_registrar
)
transfer_contacts(new_registrar)
save!
end
@ -34,6 +21,24 @@ module Concerns::Domain::Transferable
private
def transferable?
(statuses & [
DomainStatus::PENDING_DELETE_CONFIRMATION,
DomainStatus::PENDING_CREATE,
DomainStatus::PENDING_UPDATE,
DomainStatus::PENDING_DELETE,
DomainStatus::PENDING_RENEW,
DomainStatus::PENDING_TRANSFER,
DomainStatus::FORCE_DELETE,
DomainStatus::SERVER_TRANSFER_PROHIBITED,
DomainStatus::CLIENT_TRANSFER_PROHIBITED
]).empty?
end
def generate_transfer_code?
new_record? && transfer_code.blank?
end
def generate_transfer_code
self.transfer_code = SecureRandom.hex
end

View file

@ -49,7 +49,7 @@ class Domain < ActiveRecord::Base
accepts_nested_attributes_for :domain_statuses, allow_destroy: true,
reject_if: proc { |attrs| attrs[:value].blank? }
has_many :domain_transfers, dependent: :destroy
has_many :transfers, class_name: 'DomainTransfer', dependent: :destroy
has_many :dnskeys, dependent: :destroy
@ -280,7 +280,7 @@ class Domain < ActiveRecord::Base
end
def pending_transfer
domain_transfers.find_by(status: DomainTransfer::PENDING)
transfers.find_by(status: DomainTransfer::PENDING)
end
def server_holdable?

View file

@ -10,6 +10,26 @@ class DomainTransfer < ActiveRecord::Base
SERVER_APPROVED = 'serverApproved'
before_create :set_wait_until
class << self
def request(domain, new_registrar)
domain_transfer = create!(
transfer_requested_at: Time.zone.now,
domain: domain,
old_registrar: domain.registrar,
new_registrar: new_registrar
)
domain_transfer.approve if approve_automatically?
end
private
def approve_automatically?
Setting.transfer_wait_time.zero?
end
end
def set_wait_until
wait_time = Setting.transfer_wait_time
return if wait_time == 0
@ -17,6 +37,7 @@ class DomainTransfer < ActiveRecord::Base
end
before_create :set_status
def set_status
if Setting.transfer_wait_time > 0
self.status = PENDING unless status
@ -36,11 +57,29 @@ class DomainTransfer < ActiveRecord::Base
status == PENDING
end
def notify_losing_registrar(contacts, registrant)
def approve
transaction do
self.status = SERVER_APPROVED
save!
notify_old_registrar
domain.transfer(new_registrar)
end
end
private
def notify_old_registrar
old_contacts_codes = domain.contacts.pluck(:code).sort.uniq.join(', ')
old_registrant_code = domain.registrant.code
old_registrar.messages.create!(
body: I18n.t('domain_transfer_was_approved', contacts: contacts, registrant: registrant),
body: I18n.t('messages.texts.domain_transfer',
domain_name: domain.name,
old_contacts_codes: old_contacts_codes,
old_registrant_code: old_registrant_code),
attached_obj_id: id,
attached_obj_type: self.class.to_s
attached_obj_type: self.class.name
)
end
end

View file

@ -628,7 +628,7 @@ class Epp::Domain < Domain
case action
when 'query'
return domain_transfers.last if domain_transfers.any?
return transfers.last if transfers.any?
when 'request'
return pending_transfer if pending_transfer
return query_transfer(frame, current_user)
@ -644,13 +644,6 @@ class Epp::Domain < Domain
# rubocop: disable Metrics/MethodLength
# rubocop: disable Metrics/AbcSize
def query_transfer(frame, current_user)
unless transferrable?
throw :epp_error, {
code: '2304',
msg: I18n.t(:object_status_prohibits_operation)
}
end
if current_user.registrar == registrar
throw :epp_error, {
code: '2002',
@ -658,11 +651,8 @@ class Epp::Domain < Domain
}
end
old_contact_codes = contacts.pluck(:code).sort.uniq
old_registrant_code = registrant.code
transaction do
dt = domain_transfers.create!(
dt = transfers.create!(
transfer_requested_at: Time.zone.now,
old_registrar: registrar,
new_registrar: current_user.registrar
@ -677,8 +667,8 @@ class Epp::Domain < Domain
end
if dt.approved?
dt.send(:notify_old_registrar)
transfer_contacts(current_user.registrar)
dt.notify_losing_registrar(old_contact_codes, old_registrant_code)
regenerate_transfer_code
self.registrar = current_user.registrar
end
@ -811,20 +801,6 @@ class Epp::Domain < Domain
true
end
def transferrable?
(statuses & [
DomainStatus::PENDING_DELETE_CONFIRMATION,
DomainStatus::PENDING_CREATE,
DomainStatus::PENDING_UPDATE,
DomainStatus::PENDING_DELETE,
DomainStatus::PENDING_RENEW,
DomainStatus::PENDING_TRANSFER,
DomainStatus::FORCE_DELETE,
DomainStatus::SERVER_TRANSFER_PROHIBITED,
DomainStatus::CLIENT_TRANSFER_PROHIBITED
]).empty?
end
## SHARED
# For domain transfer

View file

@ -1,6 +1,6 @@
class Message < ActiveRecord::Base
include Versions # version/message_version.rb
belongs_to :registrar
belongs_to :registrar, required: true
before_create -> { self.queued = true }

View file

@ -137,15 +137,6 @@ class Registrar < ActiveRecord::Base
cash_account.account_activities.create!(args)
end
def domain_transfers
at = DomainTransfer.arel_table
DomainTransfer.where(
at[:new_registrar_id].eq(id).or(
at[:old_registrar_id].eq(id)
)
)
end
def address
[street, city, state, zip].reject(&:blank?).compact.join(', ')
end

View file

@ -2,7 +2,7 @@
- msg_q = @data.css('msgQ').first
.row
.col-sm-12
%h2= t('messages', count: msg_q['count'])
%h2= t '.header', count: msg_q['count']
%hr
.row
.col-md-12
@ -75,7 +75,7 @@
- else
.row
.col-sm-12
%h2= t('messages', count: 0)
%h2= t '.header', count: 0
%hr
.row
.col-md-12