default scope on contact
This commit is contained in:
parent
43f17b3ed8
commit
61dd5a835a
16 changed files with 22 additions and 19 deletions
|
|
@ -38,7 +38,7 @@ class ApplicationController < ActionController::Base
|
||||||
if current_user
|
if current_user
|
||||||
str << "uid=#{current_user.id} "
|
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_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
|
else
|
||||||
str << 'uid=nil'
|
str << 'uid=nil'
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class AspectsController < ApplicationController
|
||||||
:page => params[:page], :per_page => 15, :order => sort_order + ' DESC')
|
:page => params[:page], :per_page => 15, :order => sort_order + ' DESC')
|
||||||
@fakes = PostsFake.new(@posts)
|
@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 = :all unless params[:a_ids]
|
||||||
@aspect ||= @aspects.first #used in mobile
|
@aspect ||= @aspects.first #used in mobile
|
||||||
|
|
@ -100,7 +100,7 @@ class AspectsController < ApplicationController
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@aspect = current_user.aspects.where(:id => params[:id]).includes(:contacts => {:person => :profile}).first
|
@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
|
unless @aspect
|
||||||
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
|
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
|
||||||
else
|
else
|
||||||
|
|
@ -112,7 +112,7 @@ class AspectsController < ApplicationController
|
||||||
|
|
||||||
def manage
|
def manage
|
||||||
@aspect = :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)
|
@remote_requests = Request.where(:recipient_id => current_user.person.id).includes(:sender => :profile)
|
||||||
@aspects = @all_aspects.includes(:contacts => {:person => :profile})
|
@aspects = @all_aspects.includes(:contacts => {:person => :profile})
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ class ContactsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
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
|
@person = @contact.person
|
||||||
@aspects_with_person = []
|
@aspects_with_person = []
|
||||||
|
|
@ -55,7 +55,7 @@ class ContactsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
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)
|
if current_user.disconnect(contact)
|
||||||
flash[:notice] = I18n.t('contacts.destroy.success', :name => contact.person.name)
|
flash[:notice] = I18n.t('contacts.destroy.success', :name => contact.person.name)
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ class PeopleController < ApplicationController
|
||||||
requests[r.id] = r
|
requests[r.id] = r
|
||||||
end
|
end
|
||||||
contacts = {}
|
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
|
contacts[contact.person_id] = contact
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
class Contact < ActiveRecord::Base
|
class Contact < ActiveRecord::Base
|
||||||
|
default_scope where(:pending => false)
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
validates_presence_of :user
|
validates_presence_of :user
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ class Profile < ActiveRecord::Base
|
||||||
belongs_to :person
|
belongs_to :person
|
||||||
|
|
||||||
def subscribers(user)
|
def subscribers(user)
|
||||||
Person.joins(:contacts).where(:contacts => {:user_id => user.id, :pending => false})
|
Person.joins(:contacts).where(:contacts => {:user_id => user.id})
|
||||||
end
|
end
|
||||||
|
|
||||||
def receive(user, person)
|
def receive(user, person)
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ class Services::Facebook < Service
|
||||||
requests.each{|r| data_h[person_ids_and_uids[r.sender_id]][:request] = r}
|
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}
|
contact_objects.each{|c| data_h[person_ids_and_uids[c.person_id]][:contact] = c}
|
||||||
|
|
||||||
if opts[:local]
|
if opts[:local]
|
||||||
|
|
|
||||||
|
|
@ -284,7 +284,7 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def disconnect_everyone
|
def disconnect_everyone
|
||||||
contacts.each { |contact|
|
Contact.unscoped.where(:user_id => self.id).each { |contact|
|
||||||
if contact.person.owner_id
|
if contact.person.owner_id
|
||||||
contact.person.owner.disconnected_by self.person
|
contact.person.owner.disconnected_by self.person
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -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
|
.right
|
||||||
%b
|
%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
|
%b
|
||||||
= link_to aspect.name, edit_aspect_path(aspect), :rel => 'facebox'
|
= link_to aspect.name, edit_aspect_path(aspect), :rel => 'facebox'
|
||||||
%br
|
%br
|
||||||
|
|
|
||||||
1
false
Normal file
1
false
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
ack: =: No such file or directory
|
||||||
|
|
@ -42,7 +42,7 @@ module Diaspora
|
||||||
end
|
end
|
||||||
|
|
||||||
def contact_for_person_id(person_id)
|
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
|
end
|
||||||
|
|
||||||
def people_in_aspects(aspects, opts={})
|
def people_in_aspects(aspects, opts={})
|
||||||
|
|
|
||||||
|
|
@ -198,9 +198,9 @@ describe AspectsController do
|
||||||
assigns(:remote_requests).should be_empty
|
assigns(:remote_requests).should be_empty
|
||||||
end
|
end
|
||||||
it "assigns contacts to only non-pending" do
|
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.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
|
get :manage
|
||||||
contacts = assigns(:contacts)
|
contacts = assigns(:contacts)
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ describe RequestsController do
|
||||||
@user.contact_for(@other_user).should be_nil
|
@user.contact_for(@other_user).should be_nil
|
||||||
lambda {
|
lambda {
|
||||||
post :create, @params
|
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 = @user.reload.contact_for(@other_user.person)
|
||||||
new_contact.should_not be_nil
|
new_contact.should_not be_nil
|
||||||
new_contact.should be_pending
|
new_contact.should be_pending
|
||||||
|
|
|
||||||
|
|
@ -338,7 +338,7 @@ describe Invitation do
|
||||||
it 'creates a pending contact for the inviter' do
|
it 'creates a pending contact for the inviter' do
|
||||||
lambda {
|
lambda {
|
||||||
@invitation.to_request!
|
@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
|
@invitation.sender.contact_for(@new_user.person).should be_pending
|
||||||
end
|
end
|
||||||
describe 'return values' do
|
describe 'return values' do
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ describe Diaspora::UserModules::Connecting do
|
||||||
it 'creates a pending contact' do
|
it 'creates a pending contact' do
|
||||||
proc {
|
proc {
|
||||||
user.send_contact_request_to(user2.person, aspect1)
|
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).pending.should == true
|
||||||
user.contact_for(user2.person).should be_pending
|
user.contact_for(user2.person).should be_pending
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -268,7 +268,7 @@ describe User do
|
||||||
connect_users(user, aspect, user2, aspect2)
|
connect_users(user, aspect, user2, aspect2)
|
||||||
lambda {
|
lambda {
|
||||||
user.send_contact_request_to(Factory(:user).person, aspect)
|
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 = mock()
|
||||||
m.should_receive(:post)
|
m.should_receive(:post)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue