Going toward pending requests
This commit is contained in:
parent
82578ad80c
commit
56d7c67bbb
9 changed files with 56 additions and 25 deletions
|
|
@ -18,8 +18,9 @@ class PublicsController < ApplicationController
|
|||
end
|
||||
|
||||
def receive
|
||||
user = User.first(:id => params[:id])
|
||||
Rails.logger.info "PublicsController has received: #{params[:xml]}"
|
||||
store_objects_from_xml params[:xml]
|
||||
store_objects_from_xml params[:xml], user
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ module RequestsHelper
|
|||
f = Redfinger.finger(identifier)
|
||||
action = subscription_mode(f)
|
||||
url = subscription_url(action, f)
|
||||
|
||||
{ action => url }
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ class Person
|
|||
xml_accessor :_id
|
||||
xml_accessor :email
|
||||
xml_accessor :url
|
||||
xml_accessor :serialized_key
|
||||
xml_accessor :profile, :as => Profile
|
||||
|
||||
|
||||
|
|
@ -107,7 +106,6 @@ class Person
|
|||
end
|
||||
|
||||
def owns?(post)
|
||||
puts self.class
|
||||
self.id == post.person.id
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -44,8 +44,8 @@ class Request
|
|||
end
|
||||
|
||||
#ENCRYPTION
|
||||
before_validation :sign_if_mine
|
||||
validates_true_for :creator_signature, :logic => lambda {self.verify_creator_signature}
|
||||
#before_validation :sign_if_mine
|
||||
#validates_true_for :creator_signature, :logic => lambda {self.verify_creator_signature}
|
||||
|
||||
xml_accessor :creator_signature
|
||||
key :creator_signature, String
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ class User
|
|||
:recoverable, :rememberable, :trackable, :validatable
|
||||
|
||||
key :friend_ids, Array
|
||||
key :pending_friend_ids, Array
|
||||
key :pending_request_ids, Array
|
||||
|
||||
one :person, :class_name => 'Person', :foreign_key => :owner_id
|
||||
|
||||
many :friends, :in => :friend_ids, :class_name => 'Person'
|
||||
many :pending_friends, :in => :pending_friend_ids, :class_name => 'Person'
|
||||
many :pending_requests, :in => :pending_request_ids, :class_name => 'Request'
|
||||
|
||||
before_validation_on_create :assign_key
|
||||
before_validation :do_bad_things
|
||||
|
|
@ -31,9 +31,12 @@ class User
|
|||
|
||||
######### Friend Requesting
|
||||
def send_friend_request_to(friend_url)
|
||||
unless self.friends.find{ |x| x.url == friend_url}
|
||||
|
||||
unless self.friends.detect{ |x| x.url == friend_url}
|
||||
p = Request.instantiate(:to => friend_url, :from => self.person)
|
||||
if p.save
|
||||
self.pending_requests << p
|
||||
self.save
|
||||
p.push_to_url friend_url
|
||||
end
|
||||
p
|
||||
|
|
@ -42,7 +45,7 @@ class User
|
|||
|
||||
def accept_friend_request(friend_request_id)
|
||||
request = Request.where(:id => friend_request_id).first
|
||||
n = pending_friends.delete(request.person)
|
||||
n = pending_requests.delete(request)
|
||||
|
||||
friends << request.person
|
||||
save
|
||||
|
|
@ -57,12 +60,15 @@ class User
|
|||
def ignore_friend_request(friend_request_id)
|
||||
request = Request.first(:id => friend_request_id)
|
||||
person = request.person
|
||||
pending_friends.delete(request.person)
|
||||
pending_requests.delete(request)
|
||||
save
|
||||
person.destroy unless person.user_refs > 0
|
||||
request.destroy
|
||||
end
|
||||
|
||||
def receive_friend_request(friend_request)
|
||||
|
||||
puts friend_request.inspect
|
||||
Rails.logger.info("receiving friend request #{friend_request.to_json}")
|
||||
|
||||
friend_request.person.serialized_key = friend_request.exported_key
|
||||
|
|
@ -72,7 +78,7 @@ class User
|
|||
friend_request.destroy
|
||||
else
|
||||
friend_request.person.save
|
||||
pending_friends << friend_request.person
|
||||
pending_requests << friend_request
|
||||
save
|
||||
Rails.logger.info("#{self.real_name} has received a friend request")
|
||||
friend_request.save
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ Diaspora::Application.routes.draw do |map|
|
|||
|
||||
|
||||
#public routes
|
||||
match 'receive', :to => 'publics#receive'
|
||||
match 'receive/users/:id', :to => 'publics#receive'
|
||||
match '.well-known/host-meta',:to => 'publics#host_meta'
|
||||
match 'webfinger', :to => 'publics#webfinger'
|
||||
match 'hcard', :to => 'publics#hcard'
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ module Diaspora
|
|||
objects
|
||||
end
|
||||
|
||||
def store_objects_from_xml(xml)
|
||||
def store_objects_from_xml(xml, user)
|
||||
objects = parse_objects_from_xml(xml)
|
||||
objects.each do |p|
|
||||
Rails.logger.info("Receiving object:\n#{p.inspect}")
|
||||
|
|
@ -50,7 +50,7 @@ module Diaspora
|
|||
Rails.logger.info "Got a retraction for #{p.post_id}"
|
||||
p.perform
|
||||
elsif p.is_a? Request
|
||||
User.owner.receive_friend_request(p)
|
||||
user.receive_friend_request(p)
|
||||
elsif p.is_a? Profile
|
||||
p.save
|
||||
elsif p.respond_to?(:person) && !(p.person.nil?) && !(p.person.is_a? User)
|
||||
|
|
|
|||
|
|
@ -10,15 +10,38 @@ describe PublicsController do
|
|||
end
|
||||
|
||||
describe 'receive endpoint' do
|
||||
it 'should have a and endpoint and return a 200 on successful receipt of a request' do
|
||||
post :receive, :id =>@user.id
|
||||
response.code.should == '200'
|
||||
end
|
||||
|
||||
it 'should accept a post from anohter node and save the information' do
|
||||
it 'should accept a post from another node and save the information' do
|
||||
|
||||
person = Factory.create(:person)
|
||||
message = StatusMessage.new(:message => 'foo', :person => person)
|
||||
StatusMessage.all.count.should == 0
|
||||
post :receive, {:xml => Post.build_xml_for(message)}
|
||||
StatusMessage.all.count.should == 1
|
||||
StatusMessage.all.count.should be 0
|
||||
post :receive, :id => @user.id, :xml => Post.build_xml_for(message)
|
||||
StatusMessage.all.count.should be 1
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
it 'should save requests for the specified user (LOCAL)' do
|
||||
@user2 = Factory.create(:user)
|
||||
@user2.person.save
|
||||
|
||||
req = Request.instantiate(:from => @user2.person, :to => @user.person.url)
|
||||
xml = Request.build_xml_for [req]
|
||||
|
||||
puts xml
|
||||
|
||||
|
||||
req.delete
|
||||
post :receive, :id =>@user.id, :xml => xml
|
||||
|
||||
@user2.pending_requests.count.should be 1
|
||||
@user.pending_requests.count.should be 1
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@ describe User do
|
|||
it 'should not be able to friend request an existing friend' do
|
||||
friend = Factory.create(:person)
|
||||
|
||||
@user.friends << friend
|
||||
@user.save
|
||||
|
||||
|
||||
@user.send_friend_request_to( friend.url ).should be nil
|
||||
end
|
||||
|
||||
|
|
@ -52,27 +56,27 @@ describe User do
|
|||
it 'should get the pending friends' do
|
||||
person_one = Factory.create :person
|
||||
person_two = Factory.create :person
|
||||
@user.pending_friends.empty?.should be true
|
||||
@user.pending_requests.empty?.should be true
|
||||
@user.friends.empty?.should be true
|
||||
|
||||
request = Request.instantiate(:to => @user.url, :from => person_one)
|
||||
person_one.destroy
|
||||
@user.receive_friend_request request
|
||||
@user.pending_friends.size.should be 1
|
||||
@user.pending_requests.size.should be 1
|
||||
@user.friends.size.should be 0
|
||||
|
||||
request_two = Request.instantiate(:to => @user.url, :from => person_two)
|
||||
person_two.destroy
|
||||
@user.receive_friend_request request_two
|
||||
@user.pending_friends.size.should be 2
|
||||
@user.pending_requests.size.should be 2
|
||||
@user.friends.size.should be 0
|
||||
|
||||
@user.accept_friend_request request.id
|
||||
@user.pending_friends.size.should be 1
|
||||
@user.pending_requests.size.should be 1
|
||||
@user.friends.size.should be 1
|
||||
|
||||
@user.ignore_friend_request request_two.id
|
||||
@user.pending_friends.size.should be 0
|
||||
@user.pending_requests.size.should be 0
|
||||
@user.friends.size.should be 1
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue