Skip to content

Commit

Permalink
Get admin/registrant domains when company registry is down
Browse files Browse the repository at this point in the history
  • Loading branch information
karlerikounapuu committed Feb 4, 2021
1 parent 1bb975c commit 419396f
Show file tree
Hide file tree
Showing 3 changed files with 16 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 @@ -44,7 +44,7 @@ def show
def current_user_domains
current_registrant_user.domains(admin: params[:tech] != 'true')
rescue CompanyRegister::NotAvailableError
current_registrant_user.direct_domains
current_registrant_user.direct_domains(admin: params[:tech] != 'true')
end
end
end
Expand Down
14 changes: 12 additions & 2 deletions app/models/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ def registrant_user_admin_registrant_domains(registrant_user)
)
end

def registrant_user_direct_admin_registrant_domains(registrant_user)
from(
"(#{registrant_user_direct_domains_by_registrant(registrant_user).to_sql} UNION " \
"#{registrant_user_direct_domains_by_contact(registrant_user,
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 @@ -256,8 +264,10 @@ def registrant_user_direct_domains_by_registrant(registrant_user)
where(registrant: registrant_user.direct_contacts)
end

def registrant_user_direct_domains_by_contact(registrant_user)
joins(:domain_contacts).where(domain_contacts: { contact_id: registrant_user.direct_contacts })
def registrant_user_direct_domains_by_contact(registrant_user, except_tech: false)
request = { contact_id: registrant_user.direct_contacts }
request[:type] = [AdminDomainContact.name] if except_tech
joins(:domain_contacts).where(domain_contacts: request)
end

def registrant_user_company_registrant(companies)
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 @@ -36,7 +36,9 @@ def domains(admin: false)
Domain.registrant_user_domains(self)
end

def direct_domains
def direct_domains(admin: false)
return Domain.registrant_user_direct_admin_registrant_domains(self) if admin

Domain.registrant_user_direct_domains(self)
end

Expand Down

0 comments on commit 419396f

Please sign in to comment.