mirror of
https://github.com/internetee/registry.git
synced 2025-06-08 21:54:48 +02:00
Merge pull request #1692 from internetee/1690-registrant-portal-returns-domains-with-no-access
Registrant: Query representable and other related contacts conditionally
This commit is contained in:
commit
a561394e00
7 changed files with 40 additions and 11 deletions
|
@ -91,7 +91,7 @@ module Api
|
||||||
private
|
private
|
||||||
|
|
||||||
def current_user_contacts
|
def current_user_contacts
|
||||||
current_registrant_user.contacts
|
current_registrant_user.contacts(representable: false)
|
||||||
rescue CompanyRegister::NotAvailableError
|
rescue CompanyRegister::NotAvailableError
|
||||||
current_registrant_user.direct_contacts
|
current_registrant_user.direct_contacts
|
||||||
end
|
end
|
||||||
|
|
|
@ -210,10 +210,13 @@ class Contact < ApplicationRecord
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def registrant_user_contacts(registrant_user)
|
def registrant_user_contacts(registrant_user, representable: true)
|
||||||
registrant_user_direct_contacts(registrant_user)
|
represented_contacts = registrant_user_direct_contacts(registrant_user)
|
||||||
.or(registrant_user_company_contacts(registrant_user))
|
.or(registrant_user_company_contacts(registrant_user))
|
||||||
.or(registrant_user_indirect_contacts(registrant_user))
|
|
||||||
|
return represented_contacts if representable
|
||||||
|
|
||||||
|
represented_contacts.or(registrant_user_indirect_contacts(registrant_user))
|
||||||
end
|
end
|
||||||
|
|
||||||
def registrant_user_direct_contacts(registrant_user)
|
def registrant_user_direct_contacts(registrant_user)
|
||||||
|
|
|
@ -22,8 +22,8 @@ class RegistrantUser < User
|
||||||
citizen_country_code: country.alpha3)
|
citizen_country_code: country.alpha3)
|
||||||
end
|
end
|
||||||
|
|
||||||
def contacts
|
def contacts(representable: true)
|
||||||
Contact.registrant_user_contacts(self)
|
Contact.registrant_user_contacts(self, representable: representable)
|
||||||
end
|
end
|
||||||
|
|
||||||
def direct_contacts
|
def direct_contacts
|
||||||
|
|
12
test/fixtures/contacts.yml
vendored
12
test/fixtures/contacts.yml
vendored
|
@ -78,6 +78,18 @@ identical_to_william:
|
||||||
auth_info: 5ab865
|
auth_info: 5ab865
|
||||||
uuid: c0a191d5-3793-4f0b-8f85-491612d0293e
|
uuid: c0a191d5-3793-4f0b-8f85-491612d0293e
|
||||||
|
|
||||||
|
registrar_ltd:
|
||||||
|
name: Registrar Ltd
|
||||||
|
email: registrar@inbox.test
|
||||||
|
phone: '+555.555'
|
||||||
|
ident: 1234567890
|
||||||
|
ident_type: org
|
||||||
|
registrar: goodnames
|
||||||
|
ident_country_code: US
|
||||||
|
code: registrarltd-001
|
||||||
|
auth_info: e2c441
|
||||||
|
uuid: 28b65455-6f1a-49fd-961c-0758886dbd76
|
||||||
|
|
||||||
invalid:
|
invalid:
|
||||||
name: any
|
name: any
|
||||||
code: invalid
|
code: invalid
|
||||||
|
|
|
@ -12,7 +12,7 @@ class RegistrantApiContactsTest < ApplicationIntegrationTest
|
||||||
|
|
||||||
def test_root_accepts_limit_and_offset_parameters
|
def test_root_accepts_limit_and_offset_parameters
|
||||||
contacts(:william).update!(ident: '1234', ident_type: 'priv', ident_country_code: 'US')
|
contacts(:william).update!(ident: '1234', ident_type: 'priv', ident_country_code: 'US')
|
||||||
assert_equal 4, @user.contacts.size
|
assert_equal 4, @user.contacts(representable: false).size
|
||||||
|
|
||||||
get '/api/v1/registrant/contacts', params: { 'limit' => 1, 'offset' => 0 },
|
get '/api/v1/registrant/contacts', params: { 'limit' => 1, 'offset' => 0 },
|
||||||
headers: @auth_headers
|
headers: @auth_headers
|
||||||
|
@ -22,7 +22,7 @@ class RegistrantApiContactsTest < ApplicationIntegrationTest
|
||||||
|
|
||||||
get '/api/v1/registrant/contacts', headers: @auth_headers
|
get '/api/v1/registrant/contacts', headers: @auth_headers
|
||||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||||
assert_equal(@user.contacts.size, response_json.count)
|
assert_equal(@user.contacts(representable: false).size, response_json.count)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_get_contact_details_by_uuid
|
def test_get_contact_details_by_uuid
|
||||||
|
|
|
@ -35,7 +35,7 @@ class RegistrantApiV1ContactListTest < ActionDispatch::IntegrationTest
|
||||||
get api_v1_registrant_contacts_path, as: :json, headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
get api_v1_registrant_contacts_path, as: :json, headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||||
|
|
||||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||||
assert_equal @user.contacts.count, response_json.size
|
assert_equal @user.contacts(representable: false).count, response_json.size
|
||||||
assert_includes response_json.map{ |hash| hash[:code] }, @contact.code
|
assert_includes response_json.map{ |hash| hash[:code] }, @contact.code
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,20 @@ class RegistrantAreaDomainListTest < ApplicationSystemTestCase
|
||||||
assert_no_text 'metro.test'
|
assert_no_text 'metro.test'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_only_shows_direct_relation_and_or_company_domains
|
||||||
|
# case https://github.com/internetee/registry/issues/1690
|
||||||
|
tech_contact = contacts(:registrar_ltd)
|
||||||
|
|
||||||
|
# All domains share the same tech contact object
|
||||||
|
Domain.all.each do |domain|
|
||||||
|
DomainContact.create(domain: domain, contact: tech_contact, type: TechDomainContact)
|
||||||
|
end
|
||||||
|
|
||||||
|
visit registrant_domains_url
|
||||||
|
assert_no_text 'Company register is unavailable.'
|
||||||
|
assert_no_text 'metro.test'
|
||||||
|
end
|
||||||
|
|
||||||
def test_notification_when_company_register_is_unavailable
|
def test_notification_when_company_register_is_unavailable
|
||||||
CompanyRegister::Client.stub(:new, CompanyRegisterClientStub.new) do
|
CompanyRegister::Client.stub(:new, CompanyRegisterClientStub.new) do
|
||||||
visit registrant_domains_url
|
visit registrant_domains_url
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue