diff --git a/app/controllers/dev_utilities_controller.rb b/app/controllers/dev_utilities_controller.rb index a16c1fd56a3948243e1e22761ea86131dae17b05..e633d402148d605057e35ed0f6e5f70aea30969d 100644 --- a/app/controllers/dev_utilities_controller.rb +++ b/app/controllers/dev_utilities_controller.rb @@ -30,7 +30,7 @@ def warzombie backer_email = "#{backer['username']}@#{backer['username']}.joindiaspora.com" rel_hash = relationship_flow(backer_email) logger.info "Zombefriending #{backer['given_name']} #{backer['family_name']}" - current_user.send_request(rel_hash, current_user.groups.first.id) + current_user.send_friend_request_to(rel_hash[:friend], current_user.groups.first.id) end end end diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb index d1255f3366fa6515d5a363eee81c93897e4635a1..bf9a61e2164249feecb15a609fcf1c5103aaea49 100644 --- a/app/controllers/publics_controller.rb +++ b/app/controllers/publics_controller.rb @@ -31,7 +31,6 @@ class PublicsController < ApplicationController Rails.logger.error("Received post #{params[:xml]} for nonexistent person #{params[:id]}") return end - puts params[:xml] if params[:xml].include? "xml version='1.0'" @user.receive_salmon params[:xml] else diff --git a/app/controllers/requests_controller.rb b/app/controllers/requests_controller.rb index b62eb630ebfad9b871ab6ad794811ae2e4433229..59e58ba3cd1e20a231fb80dcd4ec68895b3bd1ee 100644 --- a/app/controllers/requests_controller.rb +++ b/app/controllers/requests_controller.rb @@ -45,7 +45,7 @@ class RequestsController < ApplicationController Rails.logger.debug("Sending request: #{rel_hash}") begin - @request = current_user.send_request(rel_hash, params[:request][:group_id]) + @request = current_user.send_friend_request_to(rel_hash[:friend], group) rescue Exception => e raise e unless e.message.include? "already friends" message = "You are already friends with #{params[:request][:destination_url]}!" diff --git a/app/helpers/requests_helper.rb b/app/helpers/requests_helper.rb index 37a5485c4aa3d5992b4bd9e085810107a6fa42a1..e40f6bde823338de64c516aba56cf971c0d5a933 100644 --- a/app/helpers/requests_helper.rb +++ b/app/helpers/requests_helper.rb @@ -27,17 +27,12 @@ module RequestsHelper def relationship_flow(identifier) action = :none - url = nil - local_person = Person.by_webfinger identifier - if local_person - action = (local_person == current_user.person ? :none : :friend) - url = local_person.receive_url - elsif !(identifier.include?(request.host) || identifier.include?("localhost")) - f = Redfinger.finger(identifier) - action = subscription_mode(f) - url = subscription_url(action, f) + person = nil + person = Person.by_webfinger identifier + if person + action = (person == current_user.person ? :none : :friend) end - { action => url } + { action => person } end end diff --git a/db/seeds/dev.rb b/db/seeds/dev.rb index c449790572a5a75ecf9c1b414986a8201bb4fa70..92653b8d9a403ea2595f8083267110fced38cbfd 100644 --- a/db/seeds/dev.rb +++ b/db/seeds/dev.rb @@ -25,6 +25,6 @@ user2.person.save! # friending users group = user.group(:name => "other dudes") -request = user.send_friend_request_to(user2.receive_url, group.id) +request = user.send_friend_request_to(user2, group) reversed_request = user2.accept_friend_request( request.id, user2.group(:name => "presidents").id ) user.receive reversed_request.to_diaspora_xml diff --git a/db/seeds/tom.rb b/db/seeds/tom.rb index 864caa6f2d6623ecb4be7048102ca858969c5a14..7a4a52f3a6ff22215f2bb4f79faeae9781164a9d 100644 --- a/db/seeds/tom.rb +++ b/db/seeds/tom.rb @@ -26,7 +26,7 @@ user2.person.save! # friending users group = user.group(:name => "other dudes") -request = user.send_friend_request_to(user2.receive_url, group.id) +request = user.send_friend_request_to(user2, group) reversed_request = user2.accept_friend_request( request.id, user2.group(:name => "presidents").id ) user.receive reversed_request.to_diaspora_xml user.group(:name => "Presidents") diff --git a/lib/diaspora/user/friending.rb b/lib/diaspora/user/friending.rb index e80ee5aa596f8a3cfcf8deec43dfad055d878000..b249347ddb19ce65fd8423058f2c5ad04b95b353 100644 --- a/lib/diaspora/user/friending.rb +++ b/lib/diaspora/user/friending.rb @@ -1,19 +1,17 @@ module Diaspora module UserModules module Friending - def send_friend_request_to(friend_url, group_id) - raise "You are already friends with that person!" if self.friends.detect{ |x| x.receive_url == friend_url} - request = Request.instantiate(:to => friend_url, :from => self.person, :into => group_id) + def send_friend_request_to(friend, group) + raise "You are already friends with that person!" if self.friends.detect{ |x| x.receive_url == friend.receive_url} + request = Request.instantiate(:to => friend.receive_url, :from => self.person, :into => group.id) if request.save self.pending_requests << request self.save - group = self.group_by_id(group_id) - group.requests << request group.save - request.push_to_url friend_url + request.push_to_url friend.receive_url end request end @@ -101,14 +99,6 @@ module Diaspora remove_friend bad_friend end - def send_request(rel_hash, group) - if rel_hash[:friend] - self.send_friend_request_to(rel_hash[:friend], group) - else - raise "you can't do anything to that url" - end - end - def activate_friend(person, group) person.user_refs += 1 group.people << person diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index 63d615363302ebddf70986fb6cb327c73b14d15d..d574b28f13267996f21f3e6084dbd888ad6168a7 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -37,7 +37,7 @@ describe PublicsController do @user3 = Factory.create(:user) - req = @user2.send_friend_request_to(@user.person.url, group.id) + req = @user2.send_friend_request_to(@user.person, group) @xml = req.to_diaspora_xml diff --git a/spec/lib/diaspora_parser_spec.rb b/spec/lib/diaspora_parser_spec.rb index 5197080dc3b58f877606e937562d085f3d973160..b0b8f6a978ccd8d8e31c9694b674d5be64ffacd9 100644 --- a/spec/lib/diaspora_parser_spec.rb +++ b/spec/lib/diaspora_parser_spec.rb @@ -96,7 +96,7 @@ describe Diaspora::Parser do end it "should activate the Person if I initiated a request to that url" do - request = @user.send_friend_request_to( @user2.receive_url, @group.id) + request = @user.send_friend_request_to( @user2.person, @group) request.reverse_for @user2 @@ -118,7 +118,7 @@ describe Diaspora::Parser do it 'should process retraction for a person' do person_count = Person.all.count - request = @user.send_friend_request_to( @user2.receive_url, @group.id) + request = @user.send_friend_request_to( @user2.person, @group) request.reverse_for @user2 xml = request.to_diaspora_xml diff --git a/spec/models/comments_spec.rb b/spec/models/comments_spec.rb index 95d2c977c122b1c67289a99c73311fa0516a6d38..bdf85884d72c67f28cb347f129b69b554c4d3f3f 100644 --- a/spec/models/comments_spec.rb +++ b/spec/models/comments_spec.rb @@ -36,7 +36,7 @@ describe Comment do before do - request = @user.send_friend_request_to(@user2.receive_url, @group.id) + request = @user.send_friend_request_to(@user2, @group) reversed_request = @user2.accept_friend_request( request.id, @group2.id ) @user.receive reversed_request.to_diaspora_xml diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 8f0e21ef99f5f120766c04c7be7dac5f08febbb5..fc203d593f1995404bc5c528f0a667ca9bcace14 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -60,7 +60,7 @@ describe Person do describe "unfriending" do it 'should delete an orphaned friend' do - request = @user.send_friend_request_to @person.receive_url, @group.id + request = @user.send_friend_request_to @person, @group @user.activate_friend(@person, @group) @user.reload @@ -74,8 +74,8 @@ describe Person do end it 'should not delete an un-orphaned friend' do - request = @user.send_friend_request_to @person.receive_url, @group.id - request2 = @user2.send_friend_request_to @person.receive_url, @group2.id + request = @user.send_friend_request_to @person, @group + request2 = @user2.send_friend_request_to @person, @group2 @user.activate_friend(@person, @group) @user2.activate_friend(@person, @group2) diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index c5b49cc64290a04c02750e249852bbfa9fcfe056..b02d6e68283f6812ce02df0c3a55393f3eece37e 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -15,7 +15,7 @@ describe Request do it 'should generate xml for the User as a Person' do - request = @user.send_friend_request_to "http://www.google.com/", @group.id + request = @user.send_friend_request_to Factory.create(:person), @group xml = request.to_xml.to_s diff --git a/spec/models/user/user_friending_spec.rb b/spec/models/user/user_friending_spec.rb index 6bf4c11173dc9c35b186c02160ad237cd19626f8..50e5817fc03d49039a892a56aee4c2e7f8a7c016 100644 --- a/spec/models/user/user_friending_spec.rb +++ b/spec/models/user/user_friending_spec.rb @@ -12,7 +12,7 @@ describe User do group = @user.group(:name => "Dudes") group.requests.size.should == 0 - @user.send_friend_request_to(friend.receive_url, group.id) + @user.send_friend_request_to(friend, group) group.reload group.requests.size.should == 1 @@ -48,7 +48,7 @@ describe User do @user.save - proc {@user.send_friend_request_to( friend.receive_url, @group.id )}.should raise_error + proc {@user.send_friend_request_to( friend, @group)}.should raise_error end @@ -183,7 +183,7 @@ describe User do @user2 = Factory.create :user @group2 = @user2.group(:name => "Gross people") - request = @user.send_friend_request_to( @user2.receive_url, @group.id) + request = @user.send_friend_request_to( @user2, @group) request.reverse_for @user2 @user2.activate_friend(@user.person, @group2) @user.receive request.to_diaspora_xml diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ff5cb46f33ccd14f2856b63dbd5730a4b4260251..3c5526e0d5b560dd0a6f56ea022b338f898aabae 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -62,7 +62,7 @@ end end def friend_users(user1, group1, user2, group2) - request = user1.send_friend_request_to(user2.receive_url, group1.id) + request = user1.send_friend_request_to(user2.person, group1) reversed_request = user2.accept_friend_request( request.id, group2.id) user1.receive reversed_request.to_diaspora_xml end diff --git a/spec/user_encryption_spec.rb b/spec/user_encryption_spec.rb index 6efafed4e31ddd5224230c2dfed181dcc6191d71..73b9db0b933c158653a3cc1dc3fc152f55dadf15 100644 --- a/spec/user_encryption_spec.rb +++ b/spec/user_encryption_spec.rb @@ -32,7 +32,7 @@ describe 'user encryption' do describe 'key exchange on friending' do it 'should send over a public key' do message_queue.stub!(:add_post_request) - request = @user.send_friend_request_to("http://example.com/", @group.id) + request = @user.send_friend_request_to(Factory.create(:person), @group) request.to_diaspora_xml.include?( @user.exported_key).should be true end @@ -44,7 +44,7 @@ describe 'user encryption' do original_key = remote_user.exported_key request = remote_user.send_friend_request_to( - @user.receive_url, remote_user.group(:name => "temp").id) + @user.person, remote_user.group(:name => "temp")) xml = request.to_diaspora_xml