only display contacts you are sharing with in aspect edit panes

This commit is contained in:
danielgrippi 2011-05-04 18:05:49 -07:00
parent 0db8541f6e
commit 7e838fc778
3 changed files with 17 additions and 2 deletions

View file

@ -108,9 +108,9 @@ class AspectsController < ApplicationController
@contacts_in_aspect = @aspect.contacts.includes(:person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name } @contacts_in_aspect = @aspect.contacts.includes(:person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name }
c = Contact.arel_table c = Contact.arel_table
if @contacts_in_aspect.empty? if @contacts_in_aspect.empty?
@contacts_not_in_aspect = current_user.contacts.includes(:person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name } @contacts_not_in_aspect = current_user.contacts.receiving.includes(:person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name }
else else
@contacts_not_in_aspect = current_user.contacts.where(c[:id].not_in(@contacts_in_aspect.map(&:id))).includes(:person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name } @contacts_not_in_aspect = current_user.contacts.receiving.where(c[:id].not_in(@contacts_in_aspect.map(&:id))).includes(:person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name }
end end
@contacts = @contacts_in_aspect + @contacts_not_in_aspect @contacts = @contacts_in_aspect + @contacts_not_in_aspect

View file

@ -23,6 +23,10 @@ class Contact < ActiveRecord::Base
where(:sharing => true) where(:sharing => true)
} }
scope :receiving, lambda {
where(:receiving => true)
}
def dispatch_request def dispatch_request
request = self.generate_request request = self.generate_request
Postzord::Dispatch.new(self.user, request).post Postzord::Dispatch.new(self.user, request).post

View file

@ -57,6 +57,17 @@ describe Contact do
}.by(1) }.by(1)
end end
end end
describe 'receiving' do
it 'returns contacts with sharing true' do
lambda {
alice.contacts.create!(:receiving => true, :person => Factory(:person))
alice.contacts.create!(:receiving => false, :person => Factory(:person))
}.should change{
Contact.receiving.count
}.by(1)
end
end
end end
describe '#contacts' do describe '#contacts' do