update photos when received over public path

closes #6082
This commit is contained in:
Benjamin Neff 2015-06-08 01:41:27 +02:00 committed by Dennis Schubert
parent 99b36598c7
commit d42b5c128e
5 changed files with 48 additions and 1 deletions

View file

@ -28,6 +28,7 @@
* Improved logging source [#6041](https://github.com/diaspora/diaspora/pull/6041) * Improved logging source [#6041](https://github.com/diaspora/diaspora/pull/6041)
* Gracefully handle duplicate entry while receiving share-visibility in parallel [#6068](https://github.com/diaspora/diaspora/pull/6068) * Gracefully handle duplicate entry while receiving share-visibility in parallel [#6068](https://github.com/diaspora/diaspora/pull/6068)
* Update twitter gem to get rid of deprecation warnings [#6083](https://github.com/diaspora/diaspora/pull/6083) * Update twitter gem to get rid of deprecation warnings [#6083](https://github.com/diaspora/diaspora/pull/6083)
* Refactor photos federation to get rid of some hacks [#6082](https://github.com/diaspora/diaspora/pull/6082)
## Bug fixes ## Bug fixes
* Disable auto follow back on aspect deletion [#5846](https://github.com/diaspora/diaspora/pull/5846) * Disable auto follow back on aspect deletion [#5846](https://github.com/diaspora/diaspora/pull/5846)
@ -60,6 +61,7 @@
* Only strip text direction codepoints around hashtags [#6067](https://github.com/diaspora/diaspora/issues/6067) * Only strip text direction codepoints around hashtags [#6067](https://github.com/diaspora/diaspora/issues/6067)
* Fix selected week on admin weekly stats page [#6079](https://github.com/diaspora/diaspora/pull/6079) * Fix selected week on admin weekly stats page [#6079](https://github.com/diaspora/diaspora/pull/6079)
* Fix that some unread conversations may be hidden [#6060](https://github.com/diaspora/diaspora/pull/6060) * Fix that some unread conversations may be hidden [#6060](https://github.com/diaspora/diaspora/pull/6060)
* Fix photo links in the mobile interface [#6082](https://github.com/diaspora/diaspora/pull/6082)
## Features ## Features
* Hide post title of limited post in comment notification email [#5843](https://github.com/diaspora/diaspora/pull/5843) * Hide post title of limited post in comment notification email [#5843](https://github.com/diaspora/diaspora/pull/5843)

View file

@ -44,6 +44,16 @@ module Diaspora
end end
end end
# @return [void]
def receive_public
local_shareable = persisted_shareable
if local_shareable
update_existing_sharable(local_shareable) if verify_persisted_shareable(local_shareable)
else
save!
end
end
# The list of people that should receive this Shareable. # The list of people that should receive this Shareable.
# #
# @param [User] user The context, or dispatching user. # @param [User] user The context, or dispatching user.

View file

@ -61,7 +61,11 @@ class Postzord::Receiver::Public < Postzord::Receiver
# @return [void] # @return [void]
def receive_object def receive_object
@object.save! if @object.respond_to?(:save!) if @object.respond_to?(:receive_public)
@object.receive_public
elsif @object.respond_to?(:save!)
@object.save!
end
end end
# @return [Array<Integer>] User ids # @return [Array<Integer>] User ids

View file

@ -277,4 +277,19 @@ describe Photo, :type => :model do
}.to_not change(StatusMessage, :count) }.to_not change(StatusMessage, :count)
end end
end end
describe "#receive_public" do
it "updates the photo if it is already persisted" do
allow(@photo).to receive(:persisted_shareable).and_return(@photo2)
expect(@photo2).to receive(:update_attributes)
@photo.receive_public
end
it "does not update the photo if the author mismatches" do
@photo.author = bob.person
allow(@photo).to receive(:persisted_shareable).and_return(@photo2)
expect(@photo).not_to receive(:update_existing_sharable)
@photo.receive_public
end
end
end end

View file

@ -336,6 +336,22 @@ describe Post, :type => :model do
end end
end end
describe "#receive_public" do
it "saves the post if the post is unknown" do
@post = FactoryGirl.create(:status_message, author: bob.person)
allow(@post).to receive(:persisted_shareable).and_return(nil)
expect(@post).to receive(:save!)
@post.receive_public
end
it "does not update the post because not mutable" do
@post = FactoryGirl.create(:status_message, author: bob.person)
expect(@post).to receive(:update_existing_sharable).and_call_original
expect(@post).not_to receive(:update_attributes)
@post.receive_public
end
end
describe '#reshares_count' do describe '#reshares_count' do
before :each do before :each do
@post = @user.post :status_message, :text => "hello", :to => @aspect.id, :public => true @post = @user.post :status_message, :text => "hello", :to => @aspect.id, :public => true