requests are almost there
This commit is contained in:
parent
1acc206fa4
commit
f6b4be97a3
6 changed files with 66 additions and 62 deletions
|
|
@ -9,18 +9,18 @@ class Request
|
|||
include Diaspora::Webhooks
|
||||
include ROXML
|
||||
|
||||
xml_accessor :_id
|
||||
xml_accessor :person, :as => Person
|
||||
xml_accessor :destination_url
|
||||
xml_accessor :callback_url
|
||||
xml_accessor :exported_key, :cdata => true
|
||||
xml_reader :_id
|
||||
xml_reader :diaspora_handle
|
||||
xml_reader :destination_url
|
||||
xml_reader :callback_url
|
||||
|
||||
key :person_id, ObjectId
|
||||
key :aspect_id, ObjectId
|
||||
key :destination_url, String
|
||||
key :callback_url, String
|
||||
key :exported_key, String
|
||||
|
||||
key :diaspora_handle, String
|
||||
|
||||
belongs_to :person
|
||||
|
||||
validates_presence_of :destination_url, :callback_url
|
||||
|
|
@ -30,14 +30,12 @@ class Request
|
|||
person = options[:from]
|
||||
self.new(:destination_url => options[:to],
|
||||
:callback_url => person.receive_url,
|
||||
:person => person,
|
||||
:exported_key => person.exported_key,
|
||||
:diaspora_handle => person.diaspora_handle,
|
||||
:aspect_id => options[:into])
|
||||
end
|
||||
|
||||
def reverse_for accepting_user
|
||||
self.person = accepting_user.person
|
||||
self.exported_key = accepting_user.exported_key
|
||||
self.diaspora_handle = accepting_user.diaspora_handle
|
||||
self.destination_url = self.callback_url
|
||||
self.save
|
||||
end
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ module Diaspora
|
|||
Rails.logger.debug("From: #{object.person.inspect}") if object.person
|
||||
|
||||
|
||||
if object.is_a?(Comment) || object.is_a?(Post)
|
||||
if object.is_a?(Comment) || object.is_a?(Post)|| object.is_a?(Request)
|
||||
e = EMWebfinger.new(object.diaspora_handle)
|
||||
|
||||
e.on_person { |person|
|
||||
|
|
@ -32,6 +32,10 @@ module Diaspora
|
|||
raise "Malicious Post, #{salmon_author.real_name} with id #{salmon_author.id} is sending a #{object.class} as #{sender_in_xml.real_name} with id #{sender_in_xml.id} "
|
||||
end
|
||||
|
||||
if object.is_a? Request
|
||||
return receive_request object, sender_in_xml
|
||||
end
|
||||
|
||||
raise "Not friends with that person" unless self.contact_for(salmon_author)
|
||||
|
||||
if object.is_a?(Comment)
|
||||
|
|
@ -50,17 +54,12 @@ module Diaspora
|
|||
raise "Malicious Post, #{salmon_author.real_name} with id #{salmon_author.id} is sending a #{object.class} as #{sender_in_xml.real_name} with id #{sender_in_xml.id} "
|
||||
end
|
||||
|
||||
if object.is_a? Request
|
||||
return receive_request object, sender_in_xml
|
||||
end
|
||||
raise "Not friends with that person" unless self.contact_for(salmon_author)
|
||||
|
||||
if object.is_a? Retraction
|
||||
receive_retraction object, xml
|
||||
elsif object.is_a? Profile
|
||||
receive_profile object, xml
|
||||
else
|
||||
receive_post object, xml
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -68,8 +67,6 @@ module Diaspora
|
|||
def sender(object, xml, webfingered_person = nil)
|
||||
if object.is_a? Retraction
|
||||
sender = object.person
|
||||
elsif object.is_a? Request
|
||||
sender = object.person
|
||||
elsif object.is_a? Profile
|
||||
sender = Diaspora::Parser.owner_id_from_xml xml
|
||||
|
||||
|
|
@ -98,10 +95,9 @@ module Diaspora
|
|||
end
|
||||
|
||||
def receive_request request, person
|
||||
person.serialized_public_key ||= request.exported_key
|
||||
request.person = person
|
||||
request.person.save
|
||||
old_request = Request.first(:id => request.id)
|
||||
old_request = Request.find(request.id)
|
||||
Rails.logger.info("I got a reqest_id #{request.id} with old request #{old_request.inspect}")
|
||||
request.aspect_id = old_request.aspect_id if old_request
|
||||
request.save
|
||||
|
|
|
|||
|
|
@ -28,9 +28,12 @@ module HelperMethods
|
|||
|
||||
def friend_users(user1, aspect1, user2, aspect2)
|
||||
request = user1.send_friend_request_to(user2.person, aspect1)
|
||||
user2.receive_friend_request(request)
|
||||
|
||||
user2.receive request.to_diaspora_xml, user1.person
|
||||
|
||||
reversed_request = user2.accept_friend_request( request.id, aspect2.id)
|
||||
user1.reload
|
||||
|
||||
user1.receive reversed_request.to_diaspora_xml, user2.person
|
||||
user1.reload
|
||||
aspect1.reload
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ describe Diaspora::Parser do
|
|||
end
|
||||
|
||||
context "friending" do
|
||||
|
||||
let(:good_request) { FakeHttpRequest.new(:success)}
|
||||
before do
|
||||
deliverable = Object.new
|
||||
deliverable.stub!(:deliver)
|
||||
|
|
@ -42,30 +44,24 @@ describe Diaspora::Parser do
|
|||
end
|
||||
|
||||
it "should create a new person upon getting a person request" do
|
||||
webfinger_mock = EMWebfinger.new(person.diaspora_handle)
|
||||
webfinger_mock.should_receive(:on_person)
|
||||
|
||||
EMWebfinger.should_receive(:new).and_return(webfinger_mock)
|
||||
|
||||
|
||||
request = Request.instantiate(:to =>"http://www.google.com/", :from => person)
|
||||
|
||||
xml = request.to_diaspora_xml
|
||||
|
||||
user3.destroy
|
||||
person.destroy
|
||||
user3.delete
|
||||
person.delete
|
||||
Person.should_receive(:by_account_identifier).exactly(2).times.and_return(person)
|
||||
user
|
||||
lambda { user.receive xml, person }.should change(Person, :count).by(1)
|
||||
end
|
||||
|
||||
it "should not create a new person if the person is already here" do
|
||||
request = Request.instantiate(:to =>"http://www.google.com/", :from => user2.person)
|
||||
original_person_id = user2.person.id
|
||||
xml = request.to_diaspora_xml
|
||||
user
|
||||
lambda { user.receive xml, user2.person }.should_not change(Person, :count)
|
||||
|
||||
user2.reload
|
||||
user2.person.reload
|
||||
user2.serialized_private_key.include?("PRIVATE").should be true
|
||||
|
||||
url = "http://" + request.callback_url.split("/")[2] + "/"
|
||||
Person.where(:url => url).first.id.should == original_person_id
|
||||
end
|
||||
end
|
||||
|
||||
it "should activate the Person if I initiated a request to that url" do
|
||||
|
|
@ -73,13 +69,12 @@ describe Diaspora::Parser do
|
|||
user.reload
|
||||
request.reverse_for user3
|
||||
|
||||
xml = request.to_diaspora_xml
|
||||
xml = user3.salmon(request).xml_for(user.person)
|
||||
|
||||
user3.person.destroy
|
||||
user3.destroy
|
||||
user3.delete
|
||||
|
||||
user.receive xml, user3.person
|
||||
new_person = Person.first(:url => user3.person.url)
|
||||
user.receive_salmon(xml)
|
||||
new_person = Person.find_by_url(user3.person.url)
|
||||
new_person.nil?.should be false
|
||||
|
||||
user.reload
|
||||
|
|
|
|||
|
|
@ -19,17 +19,6 @@ describe Request do
|
|||
person_request.valid?.should be true
|
||||
end
|
||||
|
||||
it 'should generate xml for the User as a Person' do
|
||||
|
||||
request = user.send_friend_request_to person, aspect
|
||||
xml = request.to_xml.to_s
|
||||
|
||||
xml.should include user.person.diaspora_handle
|
||||
xml.should include user.person.url
|
||||
xml.should include user.profile.first_name
|
||||
xml.should include user.profile.last_name
|
||||
xml.should include user.exported_key
|
||||
end
|
||||
|
||||
it 'should strip the destination url' do
|
||||
person_request = Request.new
|
||||
|
|
@ -68,4 +57,28 @@ describe Request do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'serialization' do
|
||||
it 'should not generate xml for the User as a Person' do
|
||||
request = user.send_friend_request_to person, aspect
|
||||
xml = request.to_xml.to_s
|
||||
|
||||
xml.should_not include user.person.profile.first_name
|
||||
end
|
||||
|
||||
it 'should serialize the handle and not the sender' do
|
||||
request = user.send_friend_request_to person, aspect
|
||||
xml = request.to_xml.to_s
|
||||
|
||||
xml.should include user.person.diaspora_handle
|
||||
end
|
||||
|
||||
it 'should not serialize the exported key' do
|
||||
request = user.send_friend_request_to person, aspect
|
||||
xml = request.to_xml.to_s
|
||||
|
||||
xml.should_not include user.person.exported_key
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -233,23 +233,22 @@ describe Diaspora::UserModules::Friending do
|
|||
end
|
||||
|
||||
it "keeps the right counts of friends" do
|
||||
user.receive_friend_request @request
|
||||
user.receive @request.to_diaspora_xml, person_one
|
||||
|
||||
person_two.destroy
|
||||
user.reload.pending_requests.size.should be 1
|
||||
user.reload.pending_requests.size.should == 1
|
||||
user.friends.size.should be 0
|
||||
|
||||
user.receive_friend_request @request_two
|
||||
user.reload.pending_requests.size.should be 2
|
||||
user.receive @request_two.to_diaspora_xml, person_two
|
||||
user.reload.pending_requests.size.should == 2
|
||||
user.friends.size.should be 0
|
||||
|
||||
user.accept_friend_request @request.id, aspect.id
|
||||
user.reload.pending_requests.size.should be 1
|
||||
user.reload.pending_requests.size.should == 1
|
||||
user.friends.size.should be 1
|
||||
user.contact_for(person_one).should_not be_nil
|
||||
|
||||
user.ignore_friend_request @request_two.id
|
||||
user.reload.pending_requests.size.should be 0
|
||||
user.reload.pending_requests.size.should == 0
|
||||
user.friends.size.should be 1
|
||||
user.contact_for(person_two).should be_nil
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue