Fix bug in domains not returning those where a contact was only a registrant

This commit is contained in:
Maciej Szlosarczyk 2018-08-27 14:34:12 +03:00
parent 1684c5dd34
commit ba01bb3dfc
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
3 changed files with 31 additions and 11 deletions

View file

@ -17,29 +17,37 @@ class RegistrantUser < User
registrant_ident.to_s.split('-').first
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
Domain.uniq
.joins(:contacts)
.where(contacts: { ident_type: 'priv', ident: ident, ident_country_code: country_code })
domains_where_is_contact = begin
Domain.joins(:domain_contacts)
.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
def contacts
Contact.where(ident_type: 'priv', ident: ident, ident_country_code: country_code)
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
domains_where_is_administrative_contact = begin
Domain.joins(:domain_contacts)
.where(domain_contacts: { contact_id: contacts, type: [AdminDomainContact] })
end
domains_where_is_registrar = Domain.where(registrant_id: contacts)
domains_where_is_registrant = Domain.where(registrant_id: contacts)
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"
)
end