diff --git a/app/controllers/api/v1/registrant/domains_controller.rb b/app/controllers/api/v1/registrant/domains_controller.rb index 73b5345980..c10789d76f 100644 --- a/app/controllers/api/v1/registrant/domains_controller.rb +++ b/app/controllers/api/v1/registrant/domains_controller.rb @@ -42,7 +42,7 @@ def show private def current_user_domains - current_registrant_user.domains + current_registrant_user.domains(admin: params[:tech] != 'true') rescue CompanyRegister::NotAvailableError current_registrant_user.direct_domains end diff --git a/app/models/domain.rb b/app/models/domain.rb index 53f0fa5b6a..6837e69058 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -198,6 +198,15 @@ def nameserver_required? Setting.nameserver_required end + def registrant_user_admin_registrant_domains(registrant_user) + companies = Contact.registrant_user_company_contacts(registrant_user) + from( + "(#{registrant_user_administered_domains(registrant_user).to_sql} UNION " \ + "#{registrant_user_company_registrant(registrant_user).to_sql} UNION " \ + "#{registrant_user_domains_company(companies, except_tech: true).to_sql}) AS domains" + ) + end + def registrant_user_domains(registrant_user) from( "(#{registrant_user_domains_by_registrant(registrant_user).to_sql} UNION " \ @@ -255,8 +264,10 @@ def registrant_user_company_registrant(companies) where(registrant: companies) end - def registrant_user_domains_company(companies) - joins(:domain_contacts).where(domain_contacts: { contact: companies }) + def registrant_user_domains_company(companies, except_tech: false) + request = { contact: companies } + request[:type] = [AdminDomainContact.name] if except_tech + joins(:domain_contacts).where(domain_contacts: request) end end diff --git a/app/models/registrant_user.rb b/app/models/registrant_user.rb index aa41ccff83..92a9c61ef6 100644 --- a/app/models/registrant_user.rb +++ b/app/models/registrant_user.rb @@ -30,7 +30,9 @@ def direct_contacts Contact.registrant_user_direct_contacts(self) end - def domains + def domains(admin: false) + return Domain.registrant_user_admin_registrant_domains(self) if admin + Domain.registrant_user_domains(self) end