marsharing reshares now grabs the post from the original poster, also fetcheer that person if they don't exist locally still need to ping for xml and give the right xml back

This commit is contained in:
danielgrippi 2011-07-14 15:32:04 -07:00 committed by Raphael Sofaer
parent 509a435cc9
commit bdc4b9f746
6 changed files with 63 additions and 27 deletions

View file

@ -66,7 +66,12 @@ class PublicsController < ApplicationController
end end
def post def post
if params[:guid].to_s.length <= 8
@post = Post.where(:id => params[:guid], :public => true).includes(:author, :comments => :author).first
else
@post = Post.where(:guid => params[:guid], :public => true).includes(:author, :comments => :author).first @post = Post.where(:guid => params[:guid], :public => true).includes(:author, :comments => :author).first
end
#hax to upgrade logged in users who can comment #hax to upgrade logged in users who can comment
if @post if @post

View file

@ -1,4 +1,5 @@
class Reshare < Post class Reshare < Post
belongs_to :root, :class_name => 'Post' belongs_to :root, :class_name => 'Post'
validate :root_must_be_public validate :root_must_be_public
attr_accessible :root_id, :public attr_accessible :root_id, :public
@ -6,8 +7,6 @@ class Reshare < Post
xml_attr :root_diaspora_id xml_attr :root_diaspora_id
xml_attr :root_guid xml_attr :root_guid
attr_accessible :root_diaspora_id, :root_guid
before_validation do before_validation do
self.public = true self.public = true
end end
@ -15,19 +14,10 @@ class Reshare < Post
def root_guid def root_guid
self.root.guid self.root.guid
end end
def root_guid= rg
#self.root = Post.where(:guid => rg).first
debugger
person = Person.where(:diaspora_handle => self[:root_diaspora_id]).first
Faraday.get(person.url + public_post_path(:guid => rg))
end
def root_diaspora_id def root_diaspora_id
self.root.author.diaspora_handle self.root.author.diaspora_handle
end end
def root_diaspora_id= id
Webfinger.new(id).fetch
end
def receive(user, person) def receive(user, person)
local_reshare = Reshare.where(:guid => self.guid).first local_reshare = Reshare.where(:guid => self.guid).first
@ -45,6 +35,17 @@ class Reshare < Post
private private
def after_parse
root_author = Webfinger.new(@root_diaspora_id).fetch
root_author.save!
unless self.root = Post.where(:guid => @root_guid).first
self.root = Diaspora::Parser.from_xml(Faraday.get(root_author.url + "/p/#{@root_guid}").body)
self.root.save!
end
end
def root_must_be_public def root_must_be_public
if self.root.nil? || !self.root.public if self.root.nil? || !self.root.public
errors[:base] << "you must reshare public posts" errors[:base] << "you must reshare public posts"

View file

@ -9,7 +9,7 @@
- else - else
.right.controls .right.controls
= link_to image_tag('deletelabel.png'), post_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete stream_element_delete", :title => t('delete') = link_to image_tag('deletelabel.png'), post_visibility_path(:id => "42", :post_id => post.id), :method => :put, :remote => true, :class => "delete stream_element_delete", :title => t('hide')
.undo_text.hidden .undo_text.hidden
= t('post_visibilites.update.post_hidden', :name => post.author.name) = t('post_visibilites.update.post_hidden', :name => post.author.name)

View file

@ -64,6 +64,7 @@ Feature: posting
And I am on "bob@bob.bob"'s page And I am on "bob@bob.bob"'s page
And I hover over the ".stream_element" And I hover over the ".stream_element"
And I preemptively confirm the alert
And I click to delete the first post And I click to delete the first post
And I wait for the ajax to finish And I wait for the ajax to finish
And I go to "bob@bob.bob"'s page And I go to "bob@bob.bob"'s page

View file

@ -65,22 +65,43 @@ describe PublicsController do
it 'shows a public post' do it 'shows a public post' do
status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all') status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all')
get :post, :id => status.id get :post, :guid => status.id
response.status= 200 response.status= 200
end end
it 'does not show a private post' do it 'does not show a private post' do
status = alice.post(:status_message, :text => "hello", :public => false, :to => 'all') status = alice.post(:status_message, :text => "hello", :public => false, :to => 'all')
get :post, :id => status.id get :post, :guid => status.id
response.status = 302 response.status = 302
end end
it 'redirects to the proper show page if the user has visibility of the post' do it 'redirects to the proper show page if the user has visibility of the post' do
status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all') status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all')
sign_in bob sign_in bob
get :post, :id => status.id get :post, :guid => status.id
response.should be_redirect response.should be_redirect
end end
# We want to be using guids from now on for this post route, but do not want to break
# preexisiting permalinks. We can assume a guid is 8 characters long as we have
# guids set to hex(8) since we started using them.
context 'id/guid switch' do
before do
@status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all')
end
it 'assumes guids less than 8 chars are ids and not guids' do
Post.should_receive(:where).with(hash_including(:id => @status.id)).and_return(Post)
get :post, :guid => @status.id
response.status= 200
end
it 'assumes guids more than (or equal to) 8 chars are actually guids' do
Post.should_receive(:where).with(hash_including(:guid => @status.guid)).and_return(Post)
get :post, :guid => @status.guid
response.status= 200
end
end
end end
describe '#hcard' do describe '#hcard' do

View file

@ -45,7 +45,6 @@ describe Reshare do
before do before do
@reshare = Factory(:reshare) @reshare = Factory(:reshare)
@xml = @reshare.to_xml.to_s @xml = @reshare.to_xml.to_s
pp @xml
end end
context 'serialization' do context 'serialization' do
@ -76,25 +75,34 @@ describe Reshare do
context 'remote' do context 'remote' do
before do before do
@original_profile = @reshare.root.author.profile
@original_author = @reshare.root.author.delete
@root_object = @reshare.root.delete @root_object = @reshare.root.delete
end end
it 'fetches the root post from root_guid' do it 'fetches the root post from root_guid' do
@original_profile.save! response = mock
pp @original_profile response.stub(:body).and_return(@root_object.to_diaspora_xml)
@original_author.save! Faraday.default_connection.should_receive(:get).with(@reshare.root.author.url + public_post_path(:guid => @root_object.guid)).and_return(response)
pp @original_author
Faraday.should_receive(:get).with(@original_author.url + public_post_path(:guid => @reshare.guid)).and_return(@root_object.to_diaspora_xml) root = Reshare.from_xml(@xml).root
Reshare.from_xml(@xml).root.should == @root_object
[:text, :guid, :diaspora_handle, :type].each do |attr|
root.send(attr).should == @reshare.root.send(attr)
end
end end
it 'fetches the root author from root_diaspora_id' do it 'fetches the root author from root_diaspora_id' do
person = Factory.build(:person) @original_profile = @reshare.root.author.profile
@original_author = @reshare.root.author.delete
wf_prof_mock = mock wf_prof_mock = mock
wf_prof_mock.should_receive(:fetch).and_return(person) wf_prof_mock.should_receive(:fetch).and_return(@original_author)
Webfinger.should_receive(:new).and_return(wf_prof_mock) Webfinger.should_receive(:new).and_return(wf_prof_mock)
response = mock
response.stub(:body).and_return(@root_object.to_diaspora_xml)
Faraday.default_connection.should_receive(:get).with(@original_author.url + public_post_path(:guid => @root_object.guid)).and_return(response)
Reshare.from_xml(@xml) Reshare.from_xml(@xml)
end end
end end