Fixed domain add/remove contacts endpoints

This commit is contained in:
Sergei Tsõganov 2022-11-04 12:48:20 +02:00
parent 078e67fce5
commit 936ff18de2
3 changed files with 16 additions and 11 deletions

View file

@ -41,9 +41,7 @@ module Repp
def cta(action = 'add') def cta(action = 'add')
params[:contacts].each { |c| c[:action] = action } params[:contacts].each { |c| c[:action] = action }
action = Actions::DomainUpdate.new(@domain, contact_create_params, false) action = Actions::DomainUpdate.new(@domain, contact_create_params, false)
# rubocop:disable Style/AndOr
handle_errors(@domain) and return unless action.call handle_errors(@domain) and return unless action.call
# rubocop:enable Style/AndOr
render_success(data: { domain: { name: @domain.name } }) render_success(data: { domain: { name: @domain.name } })
end end

View file

@ -94,10 +94,6 @@ module Repp
param :verified, [true, false, 'true', 'false'], required: false, param :verified, [true, false, 'true', 'false'], required: false,
desc: 'Registrant change is already verified' desc: 'Registrant change is already verified'
end end
param :contacts, Array, required: false, desc: 'Array of linked contacts' do
param :code, String, required: true, desc: 'Contact code'
param :type, String, required: true, desc: 'Role of contact (admin/tech)'
end
param :transfer_code, String, required: false, desc: 'New authorization code' param :transfer_code, String, required: false, desc: 'New authorization code'
end end
def update def update

View file

@ -30,7 +30,7 @@ module Actions
end end
def check_for_same_contacts(contacts, contact_type) def check_for_same_contacts(contacts, contact_type)
return unless contacts.uniq.count != contacts.count return if contacts.uniq.count == contacts.count
domain.add_epp_error('2306', contact_type, nil, %i[domain_contacts invalid]) domain.add_epp_error('2306', contact_type, nil, %i[domain_contacts invalid])
end end
@ -194,22 +194,33 @@ module Actions
def contact_for_action(action:, method:, code:) def contact_for_action(action:, method:, code:)
contact = Epp::Contact.find_by(code: code) contact = Epp::Contact.find_by(code: code)
return contact if action == 'add' || !contact return contact if action == 'add' || !contact
return domain.admin_domain_contacts.find_by(contact_id: contact.id) if method == 'admin'
domain.tech_domain_contacts.find_by(contact_id: contact.id) existing_contact(id: contact.id, admin: method == 'admin')
end end
def assign_contact(obj, add: false, admin: true, code:) def existing_contact(id:, admin: true)
return domain.admin_domain_contacts.find_by(contact_id: id) if admin
domain.tech_domain_contacts.find_by(contact_id: id)
end
def assign_contact(obj, code:, add: false, admin: true)
if obj.blank? if obj.blank?
domain.add_epp_error('2303', 'contact', code, %i[domain_contacts not_found]) domain.add_epp_error('2303', 'contact', code, %i[domain_contacts not_found])
elsif obj.try(:org?) && admin && add elsif obj.try(:org?) && admin && add
domain.add_epp_error('2306', 'contact', code, domain.add_epp_error('2306', 'contact', code,
%i[domain_contacts admin_contact_can_be_only_private_person]) %i[domain_contacts admin_contact_can_be_only_private_person])
else else
add ? { contact_id: obj.id, contact_code: obj.code } : { id: obj.id, _destroy: 1 } assigned_contact_hash(obj, add, admin)
end end
end end
def assigned_contact_hash(obj, add, admin)
return if !existing_contact(id: obj.id, admin: admin).nil? && add
add ? { contact_id: obj.id, contact_code: obj.code } : { id: obj.id, _destroy: 1 }
end
def assign_requested_statuses def assign_requested_statuses
return unless params[:statuses] return unless params[:statuses]