mirror of
https://github.com/internetee/registry.git
synced 2025-05-18 02:09:39 +02:00
105842700-contact_and_domain_query_change
This commit is contained in:
parent
81a19983a7
commit
e077ba7ee8
4 changed files with 37 additions and 7 deletions
|
@ -1,14 +1,15 @@
|
||||||
class Registrant::ContactsController < RegistrantController
|
class Registrant::ContactsController < RegistrantController
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@contact = Contact.where(id: contacts).find(params[:id])
|
@contact = Contact.where(id: contacts).find_by(id: params[:id])
|
||||||
|
@current_user = current_user
|
||||||
authorize! :read, @contact
|
authorize! :read, @contact
|
||||||
end
|
end
|
||||||
|
|
||||||
def contacts
|
def contacts
|
||||||
ident_cc, ident = @current_user.registrant_ident.to_s.split '-'
|
ident_cc, ident = @current_user.registrant_ident.to_s.split '-'
|
||||||
begin
|
begin
|
||||||
BusinessRegistryCache.fetch_by_ident_and_cc(ident, ident_cc).associated_contacts
|
DomainContact.where(domain_id: BusinessRegistryCache.fetch_by_ident_and_cc(ident, ident_cc).associated_domain_ids).pluck(:contact_id)
|
||||||
rescue Soap::Arireg::NotAvailableError => error
|
rescue Soap::Arireg::NotAvailableError => error
|
||||||
flash[:notice] = I18n.t(error.json[:message])
|
flash[:notice] = I18n.t(error.json[:message])
|
||||||
Rails.logger.fatal("[EXCEPTION] #{error.to_s}")
|
Rails.logger.fatal("[EXCEPTION] #{error.to_s}")
|
||||||
|
|
|
@ -28,16 +28,20 @@ class BusinessRegistryCache < ActiveRecord::Base
|
||||||
contact_ids
|
contact_ids
|
||||||
end
|
end
|
||||||
|
|
||||||
def associated_domains
|
def associated_domain_ids
|
||||||
domains = []
|
domain_ids = []
|
||||||
|
|
||||||
contact_ids = associated_contacts
|
contact_ids = associated_contacts
|
||||||
|
|
||||||
unless contact_ids.blank?
|
unless contact_ids.blank?
|
||||||
domains = DomainContact.distinct.where(contact_id: contact_ids).pluck(:domain_id)
|
domain_ids = DomainContact.distinct.where(contact_id: contact_ids).pluck(:domain_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
Domain.includes(:registrar, :registrant).where(id: domains)
|
domain_ids
|
||||||
|
end
|
||||||
|
|
||||||
|
def associated_domains
|
||||||
|
Domain.includes(:registrar, :registrant).where(id: associated_domain_ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
|
@ -407,6 +407,31 @@ class Contact < ActiveRecord::Base
|
||||||
domains
|
domains
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def all_registrant_domains(page: nil, per: nil, params: {}, registrant: nil)
|
||||||
|
|
||||||
|
if registrant
|
||||||
|
sorts = params.fetch(:sort, {}).first || []
|
||||||
|
sort = Domain.column_names.include?(sorts.first) ? sorts.first : "valid_to"
|
||||||
|
order = {"asc"=>"desc", "desc"=>"asc"}[sorts.second] || "desc"
|
||||||
|
|
||||||
|
domain_ids = DomainContact.distinct.where(contact_id: registrant.id).pluck(:domain_id)
|
||||||
|
|
||||||
|
domains = Domain.where(id: domain_ids).includes(:registrar).page(page).per(per)
|
||||||
|
if sorts.first == "registrar_name".freeze
|
||||||
|
domains = domains.includes(:registrar).where.not(registrars: {id: nil}).order("registrars.name #{order} NULLS LAST")
|
||||||
|
else
|
||||||
|
domains = domains.order("#{sort} #{order} NULLS LAST")
|
||||||
|
end
|
||||||
|
|
||||||
|
domain_c = Hash.new([])
|
||||||
|
registrant_domains.where(id: domains.map(&:id)).each{|d| domain_c[d.id] |= ["Registrant".freeze] }
|
||||||
|
DomainContact.where(contact_id: id, domain_id: domains.map(&:id)).each{|d| domain_c[d.domain_id] |= [d.type] }
|
||||||
|
domains.each{|d| d.roles = domain_c[d.id].uniq}
|
||||||
|
domains
|
||||||
|
end
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
|
||||||
def set_linked
|
def set_linked
|
||||||
statuses << LINKED if statuses.detect { |s| s == LINKED }.blank?
|
statuses << LINKED if statuses.detect { |s| s == LINKED }.blank?
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
- domains = contact.all_domains(page: params[:domain_page], per: 20, params: params)
|
- domains = contact.all_registrant_domains(page: params[:domain_page], per: 20, params: params, current_user: current_user)
|
||||||
#contacts.panel.panel-default
|
#contacts.panel.panel-default
|
||||||
.panel-heading
|
.panel-heading
|
||||||
.pull-left
|
.pull-left
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue