Skip to content

Commit

Permalink
Exclude tech from default domain query
Browse files Browse the repository at this point in the history
  • Loading branch information
karlerikounapuu committed Feb 4, 2021
1 parent d07b6a9 commit 1bb975c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/registrant/domains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions app/models/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 " \
Expand Down Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion app/models/registrant_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1bb975c

Please sign in to comment.