RS, IZ; removed lots of putses, fixed up request, parser, retractions

This commit is contained in:
Raphael 2010-08-06 16:01:39 -07:00
parent f2e327d908
commit 4350e17656
14 changed files with 71 additions and 43 deletions

View file

@ -18,7 +18,7 @@ class PublicsController < ApplicationController
end end
def receive def receive
puts "SOMEONE JUST SENT ME: #{params[:xml]}" Rails.logger.info "PublicsController has received: #{params[:xml]}"
store_objects_from_xml params[:xml] store_objects_from_xml params[:xml]
render :nothing => true render :nothing => true
end end

View file

@ -13,9 +13,8 @@ module SocketsHelper
begin begin
v = render_to_string(:partial => type_partial(object), :locals => {:post => object}) unless object.is_a? Retraction v = render_to_string(:partial => type_partial(object), :locals => {:post => object}) unless object.is_a? Retraction
rescue Exception => e rescue Exception => e
puts "web socket view rendering failed for some reason." + v.inspect Rails.logger.error ("web socket view rendering failed for some reason." + v.inspect)
puts object.inspect Rails.logger.error("Socketed object was #{object.inspect}")
puts e.message
raise e raise e
end end
action_hash = {:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)} action_hash = {:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)}

View file

@ -26,12 +26,10 @@ class Comment
end end
def push_upstream def push_upstream
puts "Comment going upstream"
push_to([post.person]) push_to([post.person])
end end
def push_downstream def push_downstream
puts "Comment going downstream"
push_to(post.people_with_permissions) push_to(post.people_with_permissions)
end end
@ -63,7 +61,6 @@ class Comment
def verify_post_creator_signature def verify_post_creator_signature
unless person == User.owner unless person == User.owner
puts "verifying post creator sig from #{post.person.real_name}"
verify_signature(post_creator_signature, post.person) verify_signature(post_creator_signature, post.person)
else else
true true

View file

@ -93,7 +93,6 @@ class Person
##profile ##profile
def update_profile(params) def update_profile(params)
if self.update_attributes(params) if self.update_attributes(params)
puts self.profile.class
self.profile.notify_people! self.profile.notify_people!
true true
else else

View file

@ -33,16 +33,19 @@ class Request
self.new(:destination_url => options[:to], :callback_url => person.url, :person => person, :exported_key => person.export_key) self.new(:destination_url => options[:to], :callback_url => person.url, :person => person, :exported_key => person.export_key)
end end
def activate_friend def activate_friend
from_user = Person.first(:url => self.callback_url).owner from_user = Person.first(:url => self.callback_url).owner
puts from_user.inspect from_user.pending_friends.delete(person)
from_user.friends << from_user.pending_friends.delete(person)
from_user.friends << person
from_user.save
end end
def set_pending_friend def set_pending_friend
p = Person.first(:id => self.person.id) p = Person.first(:id => self.person.id)
puts p.inspect
self.person.save #save pending friend self.person.save #save pending friend
end end

View file

@ -5,11 +5,15 @@ class Retraction
def self.for(object) def self.for(object)
retraction = self.new retraction = self.new
if object.is_a? User
retraction.post_id = object.person.id
retraction.type = object.person.class.to_s
else
retraction.post_id= object.id retraction.post_id= object.id
retraction.person_id = person_id_from(object)
retraction.type = object.class.to_s retraction.type = object.class.to_s
end
retraction.person_id = person_id_from(object)
retraction retraction
end end
xml_accessor :post_id xml_accessor :post_id
@ -23,6 +27,7 @@ class Retraction
def perform def perform
begin begin
return unless signature_valid? return unless signature_valid?
Rails.logger.info("Retracting #{self.type} id: #{self.post_id}")
self.type.constantize.destroy(self.post_id) self.type.constantize.destroy(self.post_id)
rescue NameError rescue NameError
Rails.logger.info("Retraction for unknown type recieved.") Rails.logger.info("Retraction for unknown type recieved.")

View file

@ -8,7 +8,9 @@ class User
key :pending_friend_ids, Array key :pending_friend_ids, Array
one :person, :class_name => 'Person', :foreign_key => :owner_id one :person, :class_name => 'Person', :foreign_key => :owner_id
many :friends, :in => :friend_ids, :class_name => 'Person' many :friends, :in => :friend_ids, :class_name => 'Person'
many :pending_friends, :in => :pending_friend_ids, :class_name => 'Person'
before_validation_on_create :assign_key before_validation_on_create :assign_key
before_validation :do_bad_things before_validation :do_bad_things
@ -20,10 +22,6 @@ class User
self.person.send(method, *args) self.person.send(method, *args)
end end
def pending_friends
Person.all(:id => self.pending_friend_ids)
end
def real_name def real_name
"#{person.profile.first_name.to_s} #{person.profile.last_name.to_s}" "#{person.profile.first_name.to_s} #{person.profile.last_name.to_s}"
@ -44,7 +42,9 @@ class User
def accept_friend_request(friend_request_id) def accept_friend_request(friend_request_id)
request = Request.where(:id => friend_request_id).first request = Request.where(:id => friend_request_id).first
request.activate_friend pending_friends.delete(request.person)
friends << request.person
request.person = self request.person = self
request.exported_key = self.export_key request.exported_key = self.export_key
request.destination_url = request.callback_url request.destination_url = request.callback_url
@ -55,7 +55,8 @@ class User
def ignore_friend_request(friend_request_id) def ignore_friend_request(friend_request_id)
request = Request.first(:id => friend_request_id) request = Request.first(:id => friend_request_id)
person = request.person person = request.person
person.destroy unless self.friends.include? person pending_friends.delete(request.person)
person.destroy unless person.user_refs > 0
request.destroy request.destroy
end end
@ -65,12 +66,12 @@ class User
friend_request.person.serialized_key = friend_request.exported_key friend_request.person.serialized_key = friend_request.exported_key
if Request.where(:callback_url => friend_request.callback_url).first if Request.where(:callback_url => friend_request.callback_url).first
friend_request.activate_friend friend_request.activate_friend
Rails.logger.info("#{self.real_name}'s friend request has been accepted")
friend_request.destroy friend_request.destroy
else else
friend_request.person.save friend_request.person.save
pending_friends << friend_request.person
friend_request.create_pending_friend Rails.logger.info("#{self.real_name} has received a friend request")
friend_request.save friend_request.save
end end
end end

View file

@ -23,13 +23,12 @@ module Diaspora
begin begin
object = post.name.camelize.constantize.from_xml post.to_s object = post.name.camelize.constantize.from_xml post.to_s
if object.is_a? Retraction if object.is_a? Retraction
elsif object.respond_to? :person
object.person = parse_owner_from_xml post.to_s
elsif object.is_a? Profile elsif object.is_a? Profile
puts "got into parse objects from xml PROFILE"
person = parse_owner_id_from_xml post person = parse_owner_id_from_xml post
person.profile = object person.profile = object
person.save person.save
elsif object.respond_to? :person
object.person = parse_owner_from_xml post.to_s
end end
objects << object objects << object
rescue NameError => e rescue NameError => e
@ -48,7 +47,7 @@ module Diaspora
objects.each do |p| objects.each do |p|
Rails.logger.info("Receiving object:\n#{p.inspect}") Rails.logger.info("Receiving object:\n#{p.inspect}")
if p.is_a? Retraction if p.is_a? Retraction
puts "Got a retraction for #{p.post_id}" Rails.logger.info "Got a retraction for #{p.post_id}"
p.perform p.perform
elsif p.is_a? Request elsif p.is_a? Request
User.owner.receive_friend_request(p) User.owner.receive_friend_request(p)

View file

@ -13,7 +13,6 @@ class MessageHandler
end end
def add_post_request(destinations, body) def add_post_request(destinations, body)
puts "sending to: #{destinations.inspect}"
b = CGI::escape( body ) b = CGI::escape( body )
[*destinations].each{|dest| @queue.push(Message.new(:post, dest, :body => b))} [*destinations].each{|dest| @queue.push(Message.new(:post, dest, :body => b))}
end end

View file

@ -105,7 +105,6 @@ describe Diaspora::Parser do
message = Factory.create(:status_message, :person => person) message = Factory.create(:status_message, :person => person)
retraction = Retraction.for(message) retraction = Retraction.for(message)
request = Post.build_xml_for( [retraction] ) request = Post.build_xml_for( [retraction] )
puts request
StatusMessage.count.should == 1 StatusMessage.count.should == 1
store_objects_from_xml( request ) store_objects_from_xml( request )
@ -141,11 +140,14 @@ describe Diaspora::Parser do
@person.destroy @person.destroy
request_remote.destroy request_remote.destroy
store_objects_from_xml(xml) store_objects_from_xml(xml)
Person.first(:url => @person.url).active.should be true new_person = Person.first(:url => @person.url)
new_person.nil?.should be false
@user.reload
@user.friends.include?(new_person).should be true
end end
it 'should marshal a retraction for a person' do it 'should process retraction for a person' do
retraction = Retraction.for(@user) retraction = Retraction.for(@user)
request = Retraction.build_xml_for( [retraction] ) request = Retraction.build_xml_for( [retraction] )
@ -169,7 +171,7 @@ describe Diaspora::Parser do
xml = Post.build_xml_for(person.profile) xml = Post.build_xml_for(person.profile)
reloaded_person = Person.first(:id => id) reloaded_person = Person.first(:id => id)
reloaded_person.profile = nil reloaded_person.profile = nil
reloaded_person.profile.save reloaded_person.save(:validate => false)
#Make sure profile is cleared #Make sure profile is cleared
Person.first(:id => id).profile.should be nil Person.first(:id => id).profile.should be nil

View file

@ -138,7 +138,6 @@ class FakeHttpRequest
@callback = callback_wanted @callback = callback_wanted
end end
def response def response
"NOTE YOU ARE IN FAKE HTTP"
end end
def post; end def post; end

View file

@ -46,7 +46,6 @@ describe Comment do
it 'should send a user comment on his own post to lots of people' do it 'should send a user comment on his own post to lots of people' do
allowed_urls = @user_status.people_with_permissions.map!{|x| x = x.url + "receive/"} allowed_urls = @user_status.people_with_permissions.map!{|x| x = x.url + "receive/"}
puts allowed_urls
message_queue.should_receive(:add_post_request).with(allowed_urls, anything) message_queue.should_receive(:add_post_request).with(allowed_urls, anything)
@user.comment "yo", :on => @user_status @user.comment "yo", :on => @user_status
end end

View file

@ -59,7 +59,6 @@ describe Photo do
it 'should not use the imported filename as the url' do it 'should not use the imported filename as the url' do
@photo.image.store! File.open(@fixture_name) @photo.image.store! File.open(@fixture_name)
puts @photo.image.url(:thumb_medium)
@photo.image.url.include?(@fixture_filename).should be false @photo.image.url.include?(@fixture_filename).should be false
@photo.image.url(:thumb_medium).include?("/" + @fixture_filename).should be false @photo.image.url(:thumb_medium).include?("/" + @fixture_filename).should be false
end end

View file

@ -1,6 +1,9 @@
require File.dirname(__FILE__) + '/../spec_helper' require File.dirname(__FILE__) + '/../spec_helper'
describe User do describe User do
before do
@user = Factory.create(:user)
end
it "should be a person" do it "should be a person" do
n = Person.count n = Person.count
@ -9,10 +12,6 @@ describe User do
end end
describe 'friend requesting' do describe 'friend requesting' do
before do
@user = Factory.create(:user)
end
it "should be able to accept a pending friend request" do it "should be able to accept a pending friend request" do
friend = Factory.create(:person) friend = Factory.create(:person)
r = Request.instantiate(:to => @user.url, :from => friend) r = Request.instantiate(:to => @user.url, :from => friend)
@ -50,6 +49,35 @@ describe User do
@user.terse_url.should == 'example.com' @user.terse_url.should == 'example.com'
end end
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.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.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.friends.size.should be 0
@user.accept_friend_request request.id
@user.pending_friends.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.friends.size.should be 1
end
end
describe 'profiles' do
it 'should be able to update their profile and send it to their friends' do it 'should be able to update their profile and send it to their friends' do
Factory.create(:person) Factory.create(:person)
@ -61,5 +89,4 @@ describe User do
@user.profile.image_url.should == "http://clown.com" @user.profile.image_url.should == "http://clown.com"
end end
end end
end end