From 078e67fce56628bd9f183690e3f4f57c3a9da08d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergei=20Ts=C3=B5ganov?= Date: Thu, 3 Nov 2022 16:56:25 +0200 Subject: [PATCH 1/2] Updated REPP domain update endpoint api description --- app/controllers/repp/v1/domains_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/repp/v1/domains_controller.rb b/app/controllers/repp/v1/domains_controller.rb index c72c83882f..49c91e133e 100644 --- a/app/controllers/repp/v1/domains_controller.rb +++ b/app/controllers/repp/v1/domains_controller.rb @@ -94,6 +94,10 @@ def create param :verified, [true, false, 'true', 'false'], required: false, desc: 'Registrant change is already verified' 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' end def update From 936ff18de2a1416666362a44210f28fa917595a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergei=20Ts=C3=B5ganov?= Date: Fri, 4 Nov 2022 12:48:20 +0200 Subject: [PATCH 2/2] Fixed domain add/remove contacts endpoints --- .../repp/v1/domains/contacts_controller.rb | 2 -- app/controllers/repp/v1/domains_controller.rb | 4 ---- app/interactions/actions/domain_update.rb | 21 ++++++++++++++----- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/controllers/repp/v1/domains/contacts_controller.rb b/app/controllers/repp/v1/domains/contacts_controller.rb index a90a2d27a0..53f8559d93 100644 --- a/app/controllers/repp/v1/domains/contacts_controller.rb +++ b/app/controllers/repp/v1/domains/contacts_controller.rb @@ -41,9 +41,7 @@ def destroy def cta(action = 'add') params[:contacts].each { |c| c[:action] = action } action = Actions::DomainUpdate.new(@domain, contact_create_params, false) - # rubocop:disable Style/AndOr handle_errors(@domain) and return unless action.call - # rubocop:enable Style/AndOr render_success(data: { domain: { name: @domain.name } }) end diff --git a/app/controllers/repp/v1/domains_controller.rb b/app/controllers/repp/v1/domains_controller.rb index 49c91e133e..c72c83882f 100644 --- a/app/controllers/repp/v1/domains_controller.rb +++ b/app/controllers/repp/v1/domains_controller.rb @@ -94,10 +94,6 @@ def create param :verified, [true, false, 'true', 'false'], required: false, desc: 'Registrant change is already verified' 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' end def update diff --git a/app/interactions/actions/domain_update.rb b/app/interactions/actions/domain_update.rb index ff6eccce2d..ca2814fdf6 100644 --- a/app/interactions/actions/domain_update.rb +++ b/app/interactions/actions/domain_update.rb @@ -30,7 +30,7 @@ def assign_relational_modifications end 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]) end @@ -194,22 +194,33 @@ def gather_domain_contacts(contacts, admin: true) def contact_for_action(action:, method:, code:) contact = Epp::Contact.find_by(code: code) 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 - 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? domain.add_epp_error('2303', 'contact', code, %i[domain_contacts not_found]) elsif obj.try(:org?) && admin && add domain.add_epp_error('2306', 'contact', code, %i[domain_contacts admin_contact_can_be_only_private_person]) else - add ? { contact_id: obj.id, contact_code: obj.code } : { id: obj.id, _destroy: 1 } + assigned_contact_hash(obj, add, admin) 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 return unless params[:statuses]