From 70a5d9f27ad20c8e0eea3fd7a6fc921f58c67f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Wed, 20 Jan 2021 14:05:11 +0200 Subject: [PATCH 1/6] Registrant API: Optimize contact link(s) query --- app/models/contact.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index e30312b4a..35425629b 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -361,8 +361,9 @@ class Contact < ApplicationRecord end def related_domains - a = related_domain_descriptions - a.keys.map { |d| { name: d, id: a[d][:id], roles: a[d][:roles] } } + dom_id = DomainContact.select(:domain_id).where(contact_id: id).map(&:domain_id).uniq + res = Domain.where(id: dom_id).or(Domain.where(registrant_id: id)).select(:name, :uuid) + res.pluck(:name, :uuid).map { |name, id| { name: name, id: id } } end def status_notes_array=(notes) From 434509f15015c539d9711a5e193a08342c6d4823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Wed, 20 Jan 2021 14:42:14 +0200 Subject: [PATCH 2/6] Registrant API: Limit contact links to 11 --- app/models/contact.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index 35425629b..7ae51992d 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -360,9 +360,10 @@ class Contact < ApplicationRecord @desc end + # Limits returned objects to 11 def related_domains - dom_id = DomainContact.select(:domain_id).where(contact_id: id).map(&:domain_id).uniq - res = Domain.where(id: dom_id).or(Domain.where(registrant_id: id)).select(:name, :uuid) + ids = DomainContact.select(:domain_id).where(contact_id: id).limit(11).map(&:domain_id).uniq + res = Domain.where(id: ids).or(Domain.where(registrant_id: id)).select(:name, :uuid).limit(11) res.pluck(:name, :uuid).map { |name, id| { name: name, id: id } } end From 1d1c336117cd5f3f16f959ed5af70d0076c97ec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 21 Jan 2021 13:18:47 +0200 Subject: [PATCH 3/6] Registrant API: Verify new contact link(s) structure --- .../api/registrant/registrant_api_contacts_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/integration/api/registrant/registrant_api_contacts_test.rb b/test/integration/api/registrant/registrant_api_contacts_test.rb index 191222764..f3998a2e9 100644 --- a/test/integration/api/registrant/registrant_api_contacts_test.rb +++ b/test/integration/api/registrant/registrant_api_contacts_test.rb @@ -57,6 +57,15 @@ class RegistrantApiContactsTest < ApplicationIntegrationTest assert_equal({ errors: [base: ['Not authorized']] }, json_body) end + def test_gets_contact_domain_links_when_requested + get "/api/v1/registrant/contacts/#{@contact.uuid}?links=true", headers: @auth_headers + + expected_links = @contact.domains.uniq.map { |d| { name: d.name, id: d.uuid }} + assert_response :ok + response_json = JSON.parse(response.body, symbolize_names: true) + + assert_empty expected_links - response_json[:links] + end private def auth_token From f07f03f0f9f0c07ebf690aeb7a9c0091d0e94591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 21 Jan 2021 15:39:21 +0200 Subject: [PATCH 4/6] Registrant API: Simplify authorized contact search query --- .../api/v1/registrant/contacts_controller.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index e11458ff8..ec59ed83f 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -24,7 +24,7 @@ module Api end def show - contact = current_user_contacts.find_by(uuid: params[:uuid]) + contact = representable_contact(params[:uuid]) links = params[:links] == 'true' if contact @@ -91,6 +91,22 @@ module Api private + def representable_contact(uuid) + country = current_registrant_user.country.alpha2 + contact = Contact.find_by(uuid: uuid, ident: current_registrant_user.ident, + ident_type: 'priv', ident_country_code: country) + return contact if contact + + Contact.find_by(uuid: uuid, ident_type: 'org', ident: company_codes, + ident_country_code: country) + rescue CompanyRegister::NotAvailableError + nil + end + + def company_codes + current_registrant_user.companies.collect(&:registration_number) + end + def current_user_contacts current_registrant_user.contacts(representable: false) rescue CompanyRegister::NotAvailableError From 5cc04d255f4639b2c043a4e5253317e4791c4f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Thu, 21 Jan 2021 21:23:18 +0200 Subject: [PATCH 5/6] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50e8560d6..aa12fbd39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +21.01.2021 +* Registrant API: optimised contact linking [#1807](https://github.com/internetee/registry/pull/1807) + 14.01.2021 * Fixed IDN and punycode support for REPP domain transfer_info request [#1801](https://github.com/internetee/registry/issues/1801) From b6df415fb9659678b708a38a93316fed9d96f039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Thu, 21 Jan 2021 21:26:23 +0200 Subject: [PATCH 6/6] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa12fbd39..08f68a169 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ 21.01.2021 * Registrant API: optimised contact linking [#1807](https://github.com/internetee/registry/pull/1807) +20.01.2021 +* Fixed legaldoc assignment issue on registrant confirmation [#1806](https://github.com/internetee/registry/pull/1806) + 14.01.2021 * Fixed IDN and punycode support for REPP domain transfer_info request [#1801](https://github.com/internetee/registry/issues/1801)