Do not fail on receiving a SignedRetraction via the public route

This commit is contained in:
Jonne Haß 2013-03-01 03:36:03 +01:00
parent fa8f4bd0b1
commit 7b56c2dd52
3 changed files with 23 additions and 5 deletions

View file

@ -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

View file

@ -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<Integer>] User ids

View file

@ -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