diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0bf2bef0db0cfd9ab5d4bb5906df3d179897d8aa..98f024e9e563baa6f696b76acd24b2c8b772d389 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -31,7 +31,7 @@ class ApplicationController < ActionController::Base end def count_requests - @request_count = current_user.pending_requests.count if current_user + @request_count = Request.to(current_user.person).count if current_user end def set_invites diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 35d84bbe0add86668d4ac2c5cf179f3b43b13667..478122e9cb3a1d7a71966d45f971b2cf6fdd6fc2 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -46,6 +46,9 @@ class PeopleController < ApplicationController @post_type = :all if @person + @incoming_request = Request.to(current_user).from(@person).first + @outgoing_request = Request.from(current_user).to(@person).first + @profile = @person.profile @contact = current_user.contact_for(@person) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7a45d186cd7dfe8ff93a51ab13d54825dbd1fad1..5d21795314c37a36993837c0b22fab759f495174 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -71,7 +71,7 @@ class UsersController < ApplicationController @person = @user.person @profile = @user.profile @services = @user.services - @requests = @user.pending_requests + @requests = Request.to(@person).all @step = ((params[:step].to_i>0)&&(params[:step].to_i<5)) ? params[:step].to_i : 1 @step ||= 1 diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rb index 3a042b02281f06b7ac16021da78e8c128171aac4..4711433ed27dbb3da57206af0ba1d34e02ca2007 100644 --- a/app/helpers/people_helper.rb +++ b/app/helpers/people_helper.rb @@ -19,9 +19,4 @@ module PeopleHelper I18n.t "people.helper.people_on_pod_are_aware_of" end end - - def pending_request_for(person) - current_user.request_for(person) - end - end diff --git a/app/models/user.rb b/app/models/user.rb index b5496f47d04889e1cfb023908fcb414eed80b5d3..f5de024c863dd0ef26dc0ecddca11f68e33d524e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -21,7 +21,6 @@ class User key :invites, Integer, :default => 5 key :invitation_token, String key :invitation_sent_at, DateTime - key :pending_request_ids, Array, :typecast => 'ObjectId' key :visible_post_ids, Array, :typecast => 'ObjectId' key :visible_person_ids, Array, :typecast => 'ObjectId' @@ -48,7 +47,6 @@ class User many :invitations_to_me, :class => Invitation, :foreign_key => :to_id many :contacts, :class => Contact, :foreign_key => :user_id many :visible_people, :in => :visible_person_ids, :class => Person # One of these needs to go - many :pending_requests, :in => :pending_request_ids, :class => Request many :raw_visible_posts, :in => :visible_post_ids, :class => Post many :aspects, :class => Aspect, :dependent => :destroy @@ -82,12 +80,6 @@ class User super end - def has_incoming_request_from(person) - self.pending_requests.select do |req| - req.to_id == self.person.id - end.any? { |req| req.from_id == person.id } - end - ######## Making things work ######## key :email, String diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 6a0e4a2bf083d27efa937a22057b4939a1ebc236..ec32a4fdf972f2239226fe1f6bc255978566dd9e 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -23,7 +23,7 @@ .span-15.last - unless @contact || current_user.person == @person - - if current_user.has_incoming_request_from(@person) + - if @incoming_request .floating %h3 = t('.incoming_request') @@ -36,7 +36,7 @@ %h3 = t('.not_connected', :name => @person.name) - - unless pending_request_for(@person) + - unless @outgoing_request %h3 .description = t('.request_people') diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb index 328bdac31d7db3abb10e43c9d94a480faed6d31e..bd1f617d920c6dc2a866446bbd4ca9a4b371912c 100644 --- a/features/step_definitions/custom_web_steps.rb +++ b/features/step_definitions/custom_web_steps.rb @@ -27,7 +27,7 @@ When /^I wait for the aspects page to load$/ do end When /^I wait for the request's profile page to load$/ do - wait_until { current_path == person_path(@me.reload.pending_requests.first.from) } + wait_until { current_path == person_path(Request.to(@me).first.from) } end When /^I wait for the ajax to finish$/ do diff --git a/features/support/paths.rb b/features/support/paths.rb index e5dfce0990ca6c32810386ac485df5b6f763e580..39d4e20baf979a68cf7b9fb05efd1d3531d927be 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -12,7 +12,7 @@ module NavigationHelpers when /^my acceptance form page$/ accept_user_invitation_path(:invitation_token => @me.invitation_token) when /^the requestor's profile page$/ - person_path(@me.reload.pending_requests.first.from) + person_path(Request.to(@me).first.from) when /^"([^\"]*)"'s page$/ person_path(User.find_by_email($1).person) when /^"(\/.*)"/ diff --git a/lib/diaspora/user/connecting.rb b/lib/diaspora/user/connecting.rb index d8ea45f364f4ff3eb62be9d2ea6ba4152a5c82c1..d866f2e0b224678251ae8e2e18643fcf3ce36bdb 100644 --- a/lib/diaspora/user/connecting.rb +++ b/lib/diaspora/user/connecting.rb @@ -20,7 +20,6 @@ module Diaspora end def accept_contact_request(request, aspect) - pending_request_ids.delete(request.id.to_id) activate_contact(request.from, aspect) request.destroy request.reverse_for(self) @@ -32,20 +31,14 @@ module Diaspora end def accept_and_respond(contact_request_id, aspect_id) - request = pending_requests.find!(contact_request_id) + request = Request.to(self.person).find!(contact_request_id) requester = request.from reversed_request = accept_contact_request(request, aspect_by_id(aspect_id)) dispatch_contact_acceptance reversed_request, requester end def ignore_contact_request(contact_request_id) - request = pending_requests.find!(contact_request_id) - person = request.from - - self.pending_request_ids.delete(request.id) - self.save - - person.save + request = Request.to(self.person).find!(contact_request_id) request.destroy end @@ -58,8 +51,6 @@ module Diaspora #this is a new contact request elsif contact_request.from != self.person if contact_request.save! - self.pending_requests << contact_request - self.save! Rails.logger.info("event=contact_request status=received_new_request from=#{contact_request.from.diaspora_handle} to=#{self.diaspora_handle}") self.mail(Jobs::MailRequestReceived, self.id, contact_request.from.id) end @@ -125,10 +116,6 @@ module Diaspora save! aspect.save! end - - def requests_for_me - pending_requests.select { |req| req.to == self.person } - end end end end diff --git a/lib/tasks/migrations.rake b/lib/tasks/migrations.rake index 60f33144c934cbe47d503ce6bfcfc4e2e5f9ba33..c3ec99a4c54b5fa9e4fd36f9cb577e551a068b7a 100644 --- a/lib/tasks/migrations.rake +++ b/lib/tasks/migrations.rake @@ -2,16 +2,15 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. - require File.join(Rails.root, 'lib/rake_helpers') include RakeHelpers -namespace :migrations do +namespace :migrations do + desc 'make old registered services into the new class specific services' task :service_reclassify do require File.join(Rails.root,"config/environment") Service.all.each do |s| - provider = s.provider if provider s._type = "Services::#{provider.camelize}" @@ -28,6 +27,17 @@ namespace :migrations do RakeHelpers::fix_diaspora_handle_spaces(false) end + task :contacts_as_requests do + require File.join(Rails.root,"config/environment") + old_contacts = Contact.all(:pending => nil) + old_contacts.each{|contact| contact.pending = false; contact.save} + puts "all done" + end + + desc 'allow to upgrade old image urls to use rel path' + task :swtich_image_urls do + end + desc 'fix usernames with periods in them' task :fix_periods_in_username do RakeHelpers::fix_periods_in_usernames(false) diff --git a/spec/controllers/invitations_controller_spec.rb b/spec/controllers/invitations_controller_spec.rb index 83901b998a5ceb708f2f213235f815f267560ad1..6c4486d53b830a3bfcd8edc736a69c858cf52bd4 100644 --- a/spec/controllers/invitations_controller_spec.rb +++ b/spec/controllers/invitations_controller_spec.rb @@ -74,19 +74,20 @@ describe InvitationsController do end context 'success' do + let(:invited) {User.find_by_username(@accept_params[:user][:username])} it 'creates user' do put :update, @accept_params - User.find_by_username(@accept_params[:user][:username]).should_not be_nil + invited.should_not be_nil end it 'seeds the aspects' do put :update, @accept_params - User.find_by_username(@accept_params[:user][:username]).aspects.count.should == 2 + invited.aspects.count.should == 2 end it 'adds a pending request' do put :update, @accept_params - User.find_by_username(@accept_params[:user][:username]).pending_requests.count.should == 1 + Request.to(invited.person).count.should == 1 end end context 'failure' do diff --git a/spec/controllers/requests_controller_spec.rb b/spec/controllers/requests_controller_spec.rb index 146843649b6b8f49c23fe1307beace76f22c3954..a1823cb427c4e1dc87c455b21c468d06488376be 100644 --- a/spec/controllers/requests_controller_spec.rb +++ b/spec/controllers/requests_controller_spec.rb @@ -24,7 +24,7 @@ describe RequestsController do before do @other_user.send_contact_request_to(@user.person, @other_user.aspects.first) @user.reload # so it can find its pending requests. - @friend_request = @user.pending_requests.first + @friend_request = Request.to(@user.person).first end describe 'when accepting a contact request' do it "succeeds" do @@ -68,14 +68,14 @@ describe RequestsController do end it 'autoaccepts and when sending a request to someone who sent me a request' do @other_user.send_contact_request_to(@user.person, @other_user.aspects[0]) - @user.reload.pending_requests.count.should == 1 + Request.to(@user).count.should == 1 @user.contact_for(@other_user.person).should be_nil post(:create, :request => { :to => @other_user.diaspora_handle, :into => @user.aspects[0].id} ) - @user.reload.pending_requests.count.should == 0 + Request.to(@user).count.should == 0 @user.contact_for(@other_user.person).should_not be_nil @user.aspects[0].contacts.all(:person_id => @other_user.person.id).should_not be_nil end diff --git a/spec/helper_methods.rb b/spec/helper_methods.rb index 377f278af6450364ae35cfde81ad93af9d897916..018bb1520cfa151b6cbd4ce86dde23ce1c432970 100644 --- a/spec/helper_methods.rb +++ b/spec/helper_methods.rb @@ -25,7 +25,7 @@ module HelperMethods user2.reload aspect2.reload - new_request = user2.pending_requests.find_by_from_id!(user1.person.id) + new_request = Request.from(user1.person).to(user2.person).first user1.reload aspect1.reload diff --git a/spec/lib/diaspora/parser_spec.rb b/spec/lib/diaspora/parser_spec.rb index f8baa96cdd9d8bbb59859943ca949c284d5f132a..b3c86e7e6d19a5054fe520d81e3867f8e8454aa8 100644 --- a/spec/lib/diaspora/parser_spec.rb +++ b/spec/lib/diaspora/parser_spec.rb @@ -59,7 +59,7 @@ describe Diaspora::Parser do it "should activate the Person if I initiated a request to that url" do user.send_contact_request_to(user2.person, aspect) - request = user2.reload.pending_requests.find_by_to_id!(user2.person.id) + request = Request.to(user2).from(user).first fantasy_resque do user2.accept_and_respond(request.id, aspect2.id) end diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index 6a7026cd1d92694cc9b0aa49d198e5993423ffaa..ca3ff5edfda6e4acd5f4fbfb5f5cc3e470f83cc6 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -79,14 +79,6 @@ describe Request do end end - context 'quering request through user' do - it 'finds requests for that user' do - request - user2.reload - user2.requests_for_me.detect{|r| r.from == user.person}.should_not be_nil - end - end - describe '.hashes_for_person' do before do @user = make_user diff --git a/spec/models/user/connecting_spec.rb b/spec/models/user/connecting_spec.rb index 7735898b6b216b0c79315f188e6b55403c6be73d..d34ce3a30d07a3eed05566b8adb7065903a55b73 100644 --- a/spec/models/user/connecting_spec.rb +++ b/spec/models/user/connecting_spec.rb @@ -41,7 +41,7 @@ describe Diaspora::UserModules::Connecting do it 'persists no request for requester' do proc { user.send_contact_request_to(user2.person, aspect1) - }.should_not change{user.reload.pending_requests.count} + }.should_not change{Request.to(user).count} end end @@ -53,7 +53,7 @@ describe Diaspora::UserModules::Connecting do it 'adds a request to pending if it was not sent by user' do user.receive_contact_request(@r) - user.reload.pending_requests.should include @r + Request.to(user).all.should include @r end it 'enqueues a mail job' do @@ -73,12 +73,12 @@ describe Diaspora::UserModules::Connecting do end it 'deletes the original request' do user.receive_request(@acceptance, user2.person) - user.pending_requests.include?(@original_request).should be_false + Request.to(user).all.include?(@original_request).should be_false Request.find(@original_request.id).should be_nil end it 'deletes the acceptance' do user.receive_request(@acceptance, user2.person) - user.pending_requests.include?(@acceptance).should be_false + Request.to(user).all.include?(@original_request).should be_false Request.find(@acceptance.id).should be_nil end it 'enqueues a mail job' do @@ -101,19 +101,14 @@ describe Diaspora::UserModules::Connecting do user.reload end - it "should delete an accepted contact request from pending_requests" do - proc { - user.accept_contact_request(@received_request, aspect) - }.should change(user.reload.pending_requests, :count ).by(-1) - end it "should delete an accepted contact request" do proc { user.accept_contact_request(@received_request, aspect) }.should change(Request, :count ).by(-1) end it 'should be able to ignore a pending contact request' do - proc { user.ignore_contact_request(@received_request.id) }.should change( - user.reload.pending_requests, :count ).by(-1) + proc { user.ignore_contact_request(@received_request.id) + }.should change(Request, :count ).by(-1) end it 'should ignore a contact request from yourself' do @@ -127,9 +122,9 @@ describe Diaspora::UserModules::Connecting do describe 'multiple users accepting/rejecting the same person' do before do - user.pending_requests.empty?.should be true + Request.to(user).count.should == 0 user.contacts.empty?.should be true - user2.pending_requests.empty?.should be true + Request.to(user2).count.should == 0 user2.contacts.empty?.should be true @request = Request.instantiate(:to => user.person, :from => person_one) @@ -190,10 +185,10 @@ describe Diaspora::UserModules::Connecting do it 'should keep the person around if the users ignores them' do - user.ignore_contact_request user.pending_requests.first.id + user.ignore_contact_request Request.to(user).first.id user.contact_for(person_one).should be_nil - user2.ignore_contact_request user2.pending_requests.first.id #@request_two.id + user2.ignore_contact_request Request.to(user2).first.id user2.contact_for(person_one).should be_nil end end @@ -203,9 +198,6 @@ describe Diaspora::UserModules::Connecting do describe 'a user accepting rejecting multiple people' do before do - user.pending_requests.empty?.should be true - user.contacts.empty?.should be true - @request = Request.instantiate(:to => user.person, :from => person_one) @request_two = Request.instantiate(:to => user.person, :from => person_two) end @@ -213,21 +205,21 @@ describe Diaspora::UserModules::Connecting do it "keeps the right counts of contacts" do received_req = user.receive @request.to_diaspora_xml, person_one - user.reload.pending_requests.size.should == 1 - user.contacts.size.should be 0 + Request.to(user).count.should == 1 + user.reload.contacts.size.should be 0 received_req2 = user.receive @request_two.to_diaspora_xml, person_two - user.reload.pending_requests.size.should == 2 - user.contacts.size.should be 0 + Request.to(user).count.should == 2 + user.reload.contacts.size.should be 0 user.accept_contact_request received_req, aspect - user.reload.pending_requests.size.should == 1 - user.contacts.size.should be 1 + Request.to(user).count.should == 1 + user.reload.contacts.size.should be 1 user.contact_for(person_one).should_not be_nil user.ignore_contact_request received_req2.id - user.reload.pending_requests.size.should == 0 - user.contacts.size.should be 1 + Request.to(user).count.should == 0 + user.reload.contacts.size.should be 1 user.contact_for(person_two).should be_nil end end diff --git a/spec/models/user/invite_spec.rb b/spec/models/user/invite_spec.rb index 32de1ad5d28515a4bb3e05b2a1323ed62d428e42..57e294940008a4466f3b2b05afa82a54415c9e91 100644 --- a/spec/models/user/invite_spec.rb +++ b/spec/models/user/invite_spec.rb @@ -74,13 +74,13 @@ describe User do end it 'resolves incoming invitations into contact requests' do - invited_user.reload.pending_requests.count.should == 1 + Request.to(invited_user).count.should == 1 end context 'after request acceptance' do before do fantasy_resque do - invited_user.accept_and_respond(invited_user.pending_requests.first.id, + invited_user.accept_and_respond(Request.to(invited_user).first.id, invited_user.aspects.create( :name => 'first aspect!').id) end @@ -89,12 +89,12 @@ describe User do end it 'successfully connects invited_user to inviter' do invited_user.contact_for(inviter.person).should_not be_nil - invited_user.pending_requests.count.should == 0 + invited_user.contact_for(inviter.person).should_not be_pending + Request.to(invited_user).count.should == 0 end it 'successfully connects inviter to invited_user' do - inviter.contact_for(invited_user.person).should_not be_nil - inviter.pending_requests.size.should == 0 + inviter.contact_for(invited_user.person).should_not be_pending end end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 1af1454ab8e6c3400ad6bfeb888e9fdf89ec6566..e33d004e89afc2b2dfc963208b08466cc87ccb7e 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -14,28 +14,6 @@ describe User do user.encryption_key.should_not be nil end - describe "#has_incoming_request_from" do - it "returns true if the user has an incoming request from the person" do - user2.send_contact_request_to(user.person, aspect2) - - user.reload - user2.reload - - user.has_incoming_request_from(user2.person).should be_true - end - it "returns false if the user does not have an incoming request from the person" do - user.has_incoming_request_from(user2.person).should be_false - end - it "returns false if the user has requested to be contacts with the person" do - user.send_contact_request_to(user2.person, aspect) - - user.reload - user2.reload - - user.has_incoming_request_from(user2.person).should be_false - end - end - describe 'overwriting people' do it 'does not overwrite old users with factory' do pending "Why do you want to set ids directly? MONGOMAPPERRRRR!!!"