Merge branch 'master' of https://github.com/internetee/registry into 1804-upgrade-ui-tests-for-admin-portal-users

This commit is contained in:
Oleg Hasjanov 2021-01-25 16:28:56 +02:00
commit db5022ebaf
4 changed files with 36 additions and 3 deletions

View file

@ -24,7 +24,7 @@ module Api
end
def show
contact = current_user_contacts.find_by(uuid: params[:uuid])
contact = representable_contact(params[:uuid])
links = params[:links] == 'true'
if contact
@ -91,6 +91,22 @@ module Api
private
def representable_contact(uuid)
country = current_registrant_user.country.alpha2
contact = Contact.find_by(uuid: uuid, ident: current_registrant_user.ident,
ident_type: 'priv', ident_country_code: country)
return contact if contact
Contact.find_by(uuid: uuid, ident_type: 'org', ident: company_codes,
ident_country_code: country)
rescue CompanyRegister::NotAvailableError
nil
end
def company_codes
current_registrant_user.companies.collect(&:registration_number)
end
def current_user_contacts
current_registrant_user.contacts(representable: false)
rescue CompanyRegister::NotAvailableError

View file

@ -360,9 +360,11 @@ class Contact < ApplicationRecord
@desc
end
# Limits returned objects to 11
def related_domains
a = related_domain_descriptions
a.keys.map { |d| { name: d, id: a[d][:id], roles: a[d][:roles] } }
ids = DomainContact.select(:domain_id).where(contact_id: id).limit(11).map(&:domain_id).uniq
res = Domain.where(id: ids).or(Domain.where(registrant_id: id)).select(:name, :uuid).limit(11)
res.pluck(:name, :uuid).map { |name, id| { name: name, id: id } }
end
def status_notes_array=(notes)