mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 12:08:27 +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
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue