From 51a044979964e2e6fdfb327bc5619013d3d12a45 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Tue, 15 Mar 2016 14:55:51 +0200 Subject: [PATCH] Story#105842700 - registrant cannot see other contact domains (legacy from FRED) --- app/controllers/registrant/contacts_controller.rb | 15 +++++++++++---- app/models/contact.rb | 5 ++++- .../registrant/contacts/partials/_domains.haml | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/controllers/registrant/contacts_controller.rb b/app/controllers/registrant/contacts_controller.rb index fd4d32a37..e79add8e9 100644 --- a/app/controllers/registrant/contacts_controller.rb +++ b/app/controllers/registrant/contacts_controller.rb @@ -1,19 +1,26 @@ class Registrant::ContactsController < RegistrantController - + helper_method :domain_ids def show - @contact = Contact.where(id: contacts).find_by(id: params[:id]) + @contact = Contact.where(id: contacts).find_by(id: params[:id]) @current_user = current_user + authorize! :read, @contact end def contacts - ident_cc, ident = @current_user.registrant_ident.to_s.split '-' begin - DomainContact.where(domain_id: BusinessRegistryCache.fetch_by_ident_and_cc(ident, ident_cc).associated_domain_ids).pluck(:contact_id) + DomainContact.where(domain_id: domain_ids).pluck(:contact_id) rescue Soap::Arireg::NotAvailableError => error flash[:notice] = I18n.t(error.json[:message]) Rails.logger.fatal("[EXCEPTION] #{error.to_s}") [] end end + + def domain_ids + @domain_ids ||= begin + ident_cc, ident = @current_user.registrant_ident.to_s.split '-' + BusinessRegistryCache.fetch_by_ident_and_cc(ident, ident_cc).associated_domain_ids + end + end end \ No newline at end of file diff --git a/app/models/contact.rb b/app/models/contact.rb index b7ff9ab1b..ca6eacd94 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -415,7 +415,10 @@ class Contact < ActiveRecord::Base # fetch domains - domains = Domain.where("domains.id IN (#{filter_sql})").includes(:registrar).page(page).per(per) + domains = Domain.where("domains.id IN (#{filter_sql})") + domains = domains.where("domains.id" => params[:leave_domains]) if params[:leave_domains] + domains = domains.includes(:registrar).page(page).per(per) + if sorts.first == "registrar_name".freeze # using small rails hack to generate outer join domains = domains.includes(:registrar).where.not(registrars: {id: nil}).order("registrars.name #{order} NULLS LAST") diff --git a/app/views/registrant/contacts/partials/_domains.haml b/app/views/registrant/contacts/partials/_domains.haml index 01b52c415..eb893053d 100644 --- a/app/views/registrant/contacts/partials/_domains.haml +++ b/app/views/registrant/contacts/partials/_domains.haml @@ -1,4 +1,4 @@ -- domains = contact.all_domains(page: params[:domain_page], per: 20, params: params) +- domains = contact.all_domains(page: params[:domain_page], per: 20, params: params.merge(leave_domains: domain_ids)) #contacts.panel.panel-default .panel-heading .pull-left