diff --git a/Changelog.md b/Changelog.md index bd07b6113..c7955fd6f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,7 @@ * avoid posting empty comments. [#3836](https://github.com/diaspora/diaspora/issues/3836) * Delegate parent_author to the target of a RelayableRetraction +* Do not fail on receiving a SignedRetraction via the public route ## Refactor diff --git a/lib/postzord/receiver/public.rb b/lib/postzord/receiver/public.rb index 374f8af93..43433b28b 100644 --- a/lib/postzord/receiver/public.rb +++ b/lib/postzord/receiver/public.rb @@ -30,6 +30,11 @@ class Postzord::Receiver::Public < Postzord::Receiver receive_relayable elsif @object.is_a?(AccountDeletion) #nothing + elsif @object.is_a?(SignedRetraction) # feels like a hack + self.recipient_user_ids.each do |user_id| + user = User.where(id: user_id).first + @object.perform user if user + end else Resque.enqueue(Jobs::ReceiveLocalBatch, @object.class.to_s, @object.id, self.recipient_user_ids) true @@ -53,7 +58,8 @@ class Postzord::Receiver::Public < Postzord::Receiver @object = Diaspora::Parser::from_xml(@salmon.parsed_data) raise "Object is not public" if object_can_be_public_and_it_is_not? raise "Author does not match XML author" if author_does_not_match_xml_author? - @object.save! if @object + @object.save! if @object && @object.respond_to?(:save!) + @object end # @return [Array] User ids diff --git a/spec/integration/receiving_spec.rb b/spec/integration/receiving_spec.rb index 0a9579428..b58d79f03 100644 --- a/spec/integration/receiving_spec.rb +++ b/spec/integration/receiving_spec.rb @@ -310,28 +310,39 @@ describe 'a user receives a post' do context 'retractions' do + let(:message) { bob.post(:status_message, text: "cats", to: @bobs_aspect.id) } + let(:zord) { Postzord::Receiver::Private.new(alice, person: bob.person) } + it 'should accept retractions' do - message = bob.post(:status_message, text: "cats", to: @bobs_aspect.id) retraction = Retraction.for(message) xml = retraction.to_diaspora_xml expect { - zord = Postzord::Receiver::Private.new(alice, person: bob.person) zord.parse_and_receive(xml) }.to change(StatusMessage, :count).by(-1) end it 'should accept relayable retractions' do - message = bob.post(:status_message, text: "cats", to: @bobs_aspect.id) comment = bob.comment! message, "and dogs" retraction = RelayableRetraction.build(bob, comment) xml = retraction.to_diaspora_xml expect { - zord = Postzord::Receiver::Private.new(alice, person: bob.person) zord.parse_and_receive xml }.to change(Comment, :count).by(-1) end + + it 'should accept signed retractions for public posts' do + message = bob.post(:status_message, text: "cats", public: true) + retraction = SignedRetraction.build(bob, message) + salmon = Postzord::Dispatcher::Public.salmon bob, retraction.to_diaspora_xml + xml = salmon.xml_for alice.person + zord = Postzord::Receiver::Public.new xml + + expect { + zord.receive! + }.to change(Post, :count).by(-1) + end end it 'should marshal a profile for a person' do