mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 07:04:47 +02:00
Fix bug in domains not returning those where a contact was only a registrant
This commit is contained in:
parent
1684c5dd34
commit
ba01bb3dfc
3 changed files with 31 additions and 11 deletions
|
@ -17,29 +17,37 @@ class RegistrantUser < User
|
||||||
registrant_ident.to_s.split('-').first
|
registrant_ident.to_s.split('-').first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# In Rails 5, can be replaced with a much simpler `or` query method and the raw SQL parts can be
|
||||||
|
# removed.
|
||||||
|
# https://guides.rubyonrails.org/active_record_querying.html#or-conditions
|
||||||
def domains
|
def domains
|
||||||
Domain.uniq
|
domains_where_is_contact = begin
|
||||||
.joins(:contacts)
|
Domain.joins(:domain_contacts)
|
||||||
.where(contacts: { ident_type: 'priv', ident: ident, ident_country_code: country_code })
|
.where(domain_contacts: { contact_id: contacts })
|
||||||
|
end
|
||||||
|
|
||||||
|
domains_where_is_registrant = Domain.where(registrant_id: contacts)
|
||||||
|
|
||||||
|
Domain.from(
|
||||||
|
"(#{domains_where_is_registrant.to_sql} UNION " \
|
||||||
|
"#{domains_where_is_contact.to_sql}) AS domains"
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def contacts
|
def contacts
|
||||||
Contact.where(ident_type: 'priv', ident: ident, ident_country_code: country_code)
|
Contact.where(ident_type: 'priv', ident: ident, ident_country_code: country_code)
|
||||||
end
|
end
|
||||||
|
|
||||||
# In Rails 5, can be replaced with a much simpler `or` query method and the raw SQL parts can be
|
|
||||||
# removed.
|
|
||||||
# https://guides.rubyonrails.org/active_record_querying.html#or-conditions
|
|
||||||
def administered_domains
|
def administered_domains
|
||||||
domains_where_is_administrative_contact = begin
|
domains_where_is_administrative_contact = begin
|
||||||
Domain.joins(:domain_contacts)
|
Domain.joins(:domain_contacts)
|
||||||
.where(domain_contacts: { contact_id: contacts, type: [AdminDomainContact] })
|
.where(domain_contacts: { contact_id: contacts, type: [AdminDomainContact] })
|
||||||
end
|
end
|
||||||
|
|
||||||
domains_where_is_registrar = Domain.where(registrant_id: contacts)
|
domains_where_is_registrant = Domain.where(registrant_id: contacts)
|
||||||
|
|
||||||
Domain.from(
|
Domain.from(
|
||||||
"(#{domains_where_is_registrar.to_sql} UNION " \
|
"(#{domains_where_is_registrant.to_sql} UNION " \
|
||||||
"#{domains_where_is_administrative_contact.to_sql}) AS domains"
|
"#{domains_where_is_administrative_contact.to_sql}) AS domains"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -109,6 +109,18 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest
|
||||||
response_json)
|
response_json)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_registrant_can_lock_a_domain
|
||||||
|
post '/api/v1/registrant/domains/1b3ee442-e8fe-4922-9492-8fcb9dccc69c/registry_lock',
|
||||||
|
{}, @auth_headers
|
||||||
|
|
||||||
|
assert_equal(200, response.status)
|
||||||
|
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||||
|
|
||||||
|
assert(response_json[:statuses].include?(DomainStatus::SERVER_DELETE_PROHIBITED))
|
||||||
|
assert(response_json[:statuses].include?(DomainStatus::SERVER_TRANSFER_PROHIBITED))
|
||||||
|
assert(response_json[:statuses].include?(DomainStatus::SERVER_UPDATE_PROHIBITED))
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def auth_token
|
def auth_token
|
||||||
|
|
|
@ -13,10 +13,10 @@ class RegistrantUserTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
def test_domains_returns_an_list_of_distinct_domains_associated_with_a_specific_id_code
|
def test_domains_returns_an_list_of_distinct_domains_associated_with_a_specific_id_code
|
||||||
domain_names = @user.domains.pluck(:name)
|
domain_names = @user.domains.pluck(:name)
|
||||||
assert_equal(3, domain_names.length)
|
assert_equal(4, domain_names.length)
|
||||||
|
|
||||||
# User is a registrant, but not a contact for the domain.
|
# User is a registrant, but not a contact for the domain. Should be included in the list.
|
||||||
refute(domain_names.include?('shop.test'))
|
assert(domain_names.include?('shop.test'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_administered_domains_returns_a_list_of_domains
|
def test_administered_domains_returns_a_list_of_domains
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue