diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb index 1b59bd1efc07483763b8494923b3e681746931da..c58b7f917cba7fe9e6d58d4da51f972ea403f05d 100644 --- a/app/controllers/publics_controller.rb +++ b/app/controllers/publics_controller.rb @@ -66,7 +66,12 @@ class PublicsController < ApplicationController end def post - @post = Post.where(:guid => params[:guid], :public => true).includes(:author, :comments => :author).first + + 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 + end #hax to upgrade logged in users who can comment if @post diff --git a/app/models/reshare.rb b/app/models/reshare.rb index fb1c59542eb340732adbaf5a6f9032858bb7ce2a..8eb0303d7851b8aa2aee7a8e2e49117586db7353 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -1,4 +1,5 @@ class Reshare < Post + belongs_to :root, :class_name => 'Post' validate :root_must_be_public attr_accessible :root_id, :public @@ -6,8 +7,6 @@ class Reshare < Post xml_attr :root_diaspora_id xml_attr :root_guid - attr_accessible :root_diaspora_id, :root_guid - before_validation do self.public = true end @@ -15,19 +14,10 @@ class Reshare < Post def root_guid self.root.guid 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 self.root.author.diaspora_handle end - def root_diaspora_id= id - Webfinger.new(id).fetch - end def receive(user, person) local_reshare = Reshare.where(:guid => self.guid).first @@ -45,6 +35,17 @@ class Reshare < Post 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 if self.root.nil? || !self.root.public errors[:base] << "you must reshare public posts" diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index a4a1f735fac520413637f4e72b750e7c45109ac5..0a4a3ef13c2ecca66b11ac4a6ce357f024567732 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -9,7 +9,7 @@ - else .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 = t('post_visibilites.update.post_hidden', :name => post.author.name) diff --git a/features/posts.feature b/features/posts.feature index 74b9f024e0f0e31015feadd51e9e0a00aa643dd1..ed6b226c746227a08a4a11ab0cd15a903491e5f8 100644 --- a/features/posts.feature +++ b/features/posts.feature @@ -64,6 +64,7 @@ Feature: posting And I am on "bob@bob.bob"'s page And I hover over the ".stream_element" + And I preemptively confirm the alert And I click to delete the first post And I wait for the ajax to finish And I go to "bob@bob.bob"'s page diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index 0e4b6d4651729251677299f472492c1feac04f8e..8f55400fc32b8641fe64552589e6a9c6affc3a8b 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -65,22 +65,43 @@ describe PublicsController do it 'shows a public post' do status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all') - get :post, :id => status.id + get :post, :guid => status.id response.status= 200 end it 'does not show a private post' do status = alice.post(:status_message, :text => "hello", :public => false, :to => 'all') - get :post, :id => status.id + get :post, :guid => status.id response.status = 302 end 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') sign_in bob - get :post, :id => status.id + get :post, :guid => status.id response.should be_redirect 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 describe '#hcard' do diff --git a/spec/models/reshare_spec.rb b/spec/models/reshare_spec.rb index 10b93d261354e8b48cb74ce630c836773956cba8..c84890052ba9866adf8cb9ed5c08cc5490acf7d4 100644 --- a/spec/models/reshare_spec.rb +++ b/spec/models/reshare_spec.rb @@ -45,7 +45,6 @@ describe Reshare do before do @reshare = Factory(:reshare) @xml = @reshare.to_xml.to_s - pp @xml end context 'serialization' do @@ -76,25 +75,34 @@ describe Reshare do context 'remote' do before do - @original_profile = @reshare.root.author.profile - @original_author = @reshare.root.author.delete @root_object = @reshare.root.delete end it 'fetches the root post from root_guid' do - @original_profile.save! - pp @original_profile - @original_author.save! - pp @original_author - Faraday.should_receive(:get).with(@original_author.url + public_post_path(:guid => @reshare.guid)).and_return(@root_object.to_diaspora_xml) - Reshare.from_xml(@xml).root.should == @root_object + response = mock + response.stub(:body).and_return(@root_object.to_diaspora_xml) + Faraday.default_connection.should_receive(:get).with(@reshare.root.author.url + public_post_path(:guid => @root_object.guid)).and_return(response) + + root = Reshare.from_xml(@xml).root + + [:text, :guid, :diaspora_handle, :type].each do |attr| + root.send(attr).should == @reshare.root.send(attr) + end end 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.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) + + 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) end end