diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 57e0cb8a3..7ad6ce1de 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -38,7 +38,7 @@ class ApplicationController < ActionController::Base if current_user str << "uid=#{current_user.id} " str << "user_created_at='#{current_user.created_at.to_date.to_s}' user_created_at_unix=#{current_user.created_at.to_i} " if current_user.created_at - str << "user_contact_count=#{current_user.contacts.size} " + str << "user_non_pending_contact_count=#{current_user.contacts.size} user_contact_count=#{Contact.unscoped.where(:user_id => current_user.id).size} " else str << 'uid=nil' end diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 7d44c70ec..698afe8f7 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -31,7 +31,7 @@ class AspectsController < ApplicationController :page => params[:page], :per_page => 15, :order => sort_order + ' DESC') @fakes = PostsFake.new(@posts) - @contacts = current_user.contacts.includes(:person => :profile).where(:pending => false) + @contacts = current_user.contacts.includes(:person => :profile) @aspect = :all unless params[:a_ids] @aspect ||= @aspects.first #used in mobile @@ -100,7 +100,7 @@ class AspectsController < ApplicationController def edit @aspect = current_user.aspects.where(:id => params[:id]).includes(:contacts => {:person => :profile}).first - @contacts = current_user.contacts.includes(:person => :profile).where(:pending => false) + @contacts = current_user.contacts.includes(:person => :profile) unless @aspect render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 else @@ -112,7 +112,7 @@ class AspectsController < ApplicationController def manage @aspect = :manage - @contacts = current_user.contacts.includes(:person => :profile).where(:pending => false) + @contacts = current_user.contacts.includes(:person => :profile) @remote_requests = Request.where(:recipient_id => current_user.person.id).includes(:sender => :profile) @aspects = @all_aspects.includes(:contacts => {:person => :profile}) end diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb index c64d51a37..e165c3e65 100644 --- a/app/controllers/contacts_controller.rb +++ b/app/controllers/contacts_controller.rb @@ -40,7 +40,7 @@ class ContactsController < ApplicationController end def edit - @contact = current_user.contacts.find(params[:id]) + @contact = Contact.unscoped.where(:id => params[:id], :user_id => current_user.id).first @person = @contact.person @aspects_with_person = [] @@ -55,7 +55,7 @@ class ContactsController < ApplicationController end def destroy - contact = current_user.contacts.where(:id => params[:id]).first + contact = Contact.unscoped.where(:id => params[:id], :user_id => current_user.id).first if current_user.disconnect(contact) flash[:notice] = I18n.t('contacts.destroy.success', :name => contact.person.name) else diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 84d521d5d..f4965373a 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -30,7 +30,7 @@ class PeopleController < ApplicationController requests[r.id] = r end contacts = {} - Contact.where(:user_id => current_user.id, :person_id => ids).each do |contact| + Contact.unscoped.where(:user_id => current_user.id, :person_id => ids).each do |contact| contacts[contact.person_id] = contact end diff --git a/app/models/contact.rb b/app/models/contact.rb index a8014f1b8..6c7c16ef6 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -3,6 +3,8 @@ # the COPYRIGHT file. class Contact < ActiveRecord::Base + default_scope where(:pending => false) + belongs_to :user validates_presence_of :user diff --git a/app/models/profile.rb b/app/models/profile.rb index 551d16acf..e1b029e7c 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -32,7 +32,7 @@ class Profile < ActiveRecord::Base belongs_to :person def subscribers(user) - Person.joins(:contacts).where(:contacts => {:user_id => user.id, :pending => false}) + Person.joins(:contacts).where(:contacts => {:user_id => user.id}) end def receive(user, person) diff --git a/app/models/services/facebook.rb b/app/models/services/facebook.rb index a8f6def73..189b4de90 100644 --- a/app/models/services/facebook.rb +++ b/app/models/services/facebook.rb @@ -49,7 +49,7 @@ class Services::Facebook < Service requests.each{|r| data_h[person_ids_and_uids[r.sender_id]][:request] = r} - contact_objects = self.user.contacts.where(:person_id => person_ids_and_uids.keys) + contact_objects = Contact.unscoped.where(:user_id => self.user.id, :person_id => person_ids_and_uids.keys) contact_objects.each{|c| data_h[person_ids_and_uids[c.person_id]][:contact] = c} if opts[:local] diff --git a/app/models/user.rb b/app/models/user.rb index bd2a68563..32944adab 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -284,7 +284,7 @@ class User < ActiveRecord::Base end def disconnect_everyone - contacts.each { |contact| + Contact.unscoped.where(:user_id => self.id).each { |contact| if contact.person.owner_id contact.person.owner.disconnected_by self.person else diff --git a/app/views/aspects/_aspect.haml b/app/views/aspects/_aspect.haml index 12dfea2f6..f8af70117 100644 --- a/app/views/aspects/_aspect.haml +++ b/app/views/aspects/_aspect.haml @@ -1,7 +1,7 @@ -%li{:data=>{:guid=>aspect.id}, :class => ("dull" if contacts.length == 0)} +%li{:data=>{:guid=>aspect.id}, :class => ("dull" if contacts.size == 0)} .right %b - = link_to t('contacts', :count => contacts.count), edit_aspect_path(aspect), :rel => 'facebox' + = link_to t('contacts', :count => contacts.size), edit_aspect_path(aspect), :rel => 'facebox' %b = link_to aspect.name, edit_aspect_path(aspect), :rel => 'facebox' %br diff --git a/false b/false new file mode 100644 index 000000000..3ce0b1cf9 --- /dev/null +++ b/false @@ -0,0 +1 @@ +ack: =: No such file or directory diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 173c334e6..3a23a31c4 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -42,7 +42,7 @@ module Diaspora end def contact_for_person_id(person_id) - Contact.where(:user_id => self.id, :person_id => person_id).first if person_id + Contact.unscoped.where(:user_id => self.id, :person_id => person_id).first if person_id end def people_in_aspects(aspects, opts={}) diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 10ebf23fc..397767352 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -198,9 +198,9 @@ describe AspectsController do assigns(:remote_requests).should be_empty end it "assigns contacts to only non-pending" do - @user.contacts.count.should == 1 + Contact.unscoped.where(:user_id => @user.id).count.should == 1 @user.send_contact_request_to(Factory(:user).person, @aspect0) - @user.contacts.count.should == 2 + Contact.unscoped.where(:user_id => @user.id).count.should == 2 get :manage contacts = assigns(:contacts) diff --git a/spec/controllers/requests_controller_spec.rb b/spec/controllers/requests_controller_spec.rb index ed53162c7..81c706860 100644 --- a/spec/controllers/requests_controller_spec.rb +++ b/spec/controllers/requests_controller_spec.rb @@ -75,7 +75,7 @@ describe RequestsController do @user.contact_for(@other_user).should be_nil lambda { post :create, @params - }.should change(Contact,:count).by(1) + }.should change(Contact.unscoped,:count).by(1) new_contact = @user.reload.contact_for(@other_user.person) new_contact.should_not be_nil new_contact.should be_pending diff --git a/spec/models/invitation_spec.rb b/spec/models/invitation_spec.rb index 0438bc754..69b2828ab 100644 --- a/spec/models/invitation_spec.rb +++ b/spec/models/invitation_spec.rb @@ -338,7 +338,7 @@ describe Invitation do it 'creates a pending contact for the inviter' do lambda { @invitation.to_request! - }.should change(Contact, :count).by(1) + }.should change(Contact.unscoped, :count).by(1) @invitation.sender.contact_for(@new_user.person).should be_pending end describe 'return values' do diff --git a/spec/models/user/connecting_spec.rb b/spec/models/user/connecting_spec.rb index 4bd35dafa..d5547cf67 100644 --- a/spec/models/user/connecting_spec.rb +++ b/spec/models/user/connecting_spec.rb @@ -34,7 +34,7 @@ describe Diaspora::UserModules::Connecting do it 'creates a pending contact' do proc { user.send_contact_request_to(user2.person, aspect1) - }.should change(Contact, :count).by(1) + }.should change(Contact.unscoped, :count).by(1) user.contact_for(user2.person).pending.should == true user.contact_for(user2.person).should be_pending end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 563cadb5c..c5b48f2b0 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -268,7 +268,7 @@ describe User do connect_users(user, aspect, user2, aspect2) lambda { user.send_contact_request_to(Factory(:user).person, aspect) - }.should change(user.contacts, :count).by(1) + }.should change(Contact.unscoped.where(:user_id => user.id), :count).by(1) m = mock() m.should_receive(:post)