From 7e838fc7783b4f6050f4da0a974ed1b7e7e2f6ff Mon Sep 17 00:00:00 2001
From: danielgrippi <daniel@joindiaspora.com>
Date: Wed, 4 May 2011 18:05:49 -0700
Subject: [PATCH] only display contacts you are sharing with in aspect edit
 panes

---
 app/controllers/aspects_controller.rb |  4 ++--
 app/models/contact.rb                 |  4 ++++
 spec/models/contact_spec.rb           | 11 +++++++++++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb
index 3e4ac1f11f..5f94e07f90 100644
--- a/app/controllers/aspects_controller.rb
+++ b/app/controllers/aspects_controller.rb
@@ -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 }
     c = Contact.arel_table
     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
-      @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
 
     @contacts = @contacts_in_aspect + @contacts_not_in_aspect
diff --git a/app/models/contact.rb b/app/models/contact.rb
index 87242f8a20..0a59eb215e 100644
--- a/app/models/contact.rb
+++ b/app/models/contact.rb
@@ -23,6 +23,10 @@ class Contact < ActiveRecord::Base
     where(:sharing => true)
   }
 
+  scope :receiving, lambda {
+    where(:receiving => true)
+  }
+
   def dispatch_request
     request = self.generate_request
     Postzord::Dispatch.new(self.user, request).post
diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb
index f7a32b7ad3..5f89c84c3b 100644
--- a/spec/models/contact_spec.rb
+++ b/spec/models/contact_spec.rb
@@ -57,6 +57,17 @@ describe Contact do
         }.by(1)
       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
 
   describe '#contacts' do
-- 
GitLab