Skip to content

Commit 8a4ec1d

Browse files
committed
Merge branch 'stable' into develop
2 parents ad52eaf + d42b5c1 commit 8a4ec1d

17 files changed

+175
-75
lines changed

Changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Ruby 2.0 is no longer officially supported.
6161
* Improved logging source [#6041](https://github.com/diaspora/diaspora/pull/6041)
6262
* Gracefully handle duplicate entry while receiving share-visibility in parallel [#6068](https://github.com/diaspora/diaspora/pull/6068)
6363
* Update twitter gem to get rid of deprecation warnings [#6083](https://github.com/diaspora/diaspora/pull/6083)
64+
* Refactor photos federation to get rid of some hacks [#6082](https://github.com/diaspora/diaspora/pull/6082)
6465

6566
## Bug fixes
6667
* Disable auto follow back on aspect deletion [#5846](https://github.com/diaspora/diaspora/pull/5846)
@@ -93,6 +94,7 @@ Ruby 2.0 is no longer officially supported.
9394
* Only strip text direction codepoints around hashtags [#6067](https://github.com/diaspora/diaspora/issues/6067)
9495
* Fix selected week on admin weekly stats page [#6079](https://github.com/diaspora/diaspora/pull/6079)
9596
* Fix that some unread conversations may be hidden [#6060](https://github.com/diaspora/diaspora/pull/6060)
97+
* Fix photo links in the mobile interface [#6082](https://github.com/diaspora/diaspora/pull/6082)
9698

9799
## Features
98100
* Hide post title of limited post in comment notification email [#5843](https://github.com/diaspora/diaspora/pull/5843)

app/controllers/status_messages_controller.rb

-5
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ def create
7373

7474
current_user.dispatch_post(@status_message, :url => short_post_url(@status_message.guid), :service_types => receiving_services)
7575

76-
#this is done implicitly, somewhere else, but it doesnt work, says max. :'(
77-
@status_message.photos.each do |photo|
78-
current_user.dispatch_post(photo)
79-
end
80-
8176
current_user.participate!(@status_message)
8277

8378
if coming_from_profile_page? && !own_profile_page? # if this is a post coming from a profile page

app/models/status_message.rb

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def after_dispatch(sender)
116116

117117
def update_and_dispatch_attached_photos(sender)
118118
if self.photos.any?
119+
logger.info "dispatch photos for StatusMessage:#{guid}"
119120
Photo.where(status_message_guid: guid).update_all(:public => self.public)
120121
self.photos.each do |photo|
121122
if photo.pending
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class FixPhotoPublicFlag < ActiveRecord::Migration
2+
def up
3+
Photo.joins(:status_message).where(posts: {public: true}).update_all(public: true)
4+
end
5+
6+
def down
7+
raise ActiveRecord::IrreversibleMigration
8+
end
9+
end

db/schema.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20150531005120) do
14+
ActiveRecord::Schema.define(version: 20150607143809) do
1515

1616
create_table "account_deletions", force: :cascade do |t|
1717
t.string "diaspora_handle", limit: 255

lib/diaspora/federated/base.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ def self.included(model)
2323

2424
module InstanceMethods
2525
def to_diaspora_xml
26+
xml = to_xml
27+
::Logging::Logger["XMLLogger"].debug "to_xml: #{xml}"
2628
<<-XML
2729
<XML>
28-
<post>#{to_xml.to_s}</post>
30+
<post>#{xml}</post>
2931
</XML>
30-
XML
32+
XML
3133
end
3234

3335
def x(input)

lib/diaspora/federated/shareable.rb

+10
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ def receive(user, person)
4444
end
4545
end
4646

47+
# @return [void]
48+
def receive_public
49+
local_shareable = persisted_shareable
50+
if local_shareable
51+
update_existing_sharable(local_shareable) if verify_persisted_shareable(local_shareable)
52+
else
53+
save!
54+
end
55+
end
56+
4757
# The list of people that should receive this Shareable.
4858
#
4959
# @param [User] user The context, or dispatching user.

lib/diaspora/parser.rb

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def self.from_xml(xml)
88
doc = Nokogiri::XML(xml) {|cfg| cfg.noblanks }
99
return unless body = doc.xpath("/XML/post").children.first
1010
class_name = body.name.gsub("-", "/")
11+
::Logging::Logger["XMLLogger"].debug "from_xml: #{body}"
1112
begin
1213
class_name.camelize.constantize.from_xml body.to_s
1314
rescue NameError => e

lib/postzord/receiver.rb

+13-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@ def perform!
1414
self.receive!
1515
end
1616

17+
private
18+
1719
def author_does_not_match_xml_author?
18-
if (@author.diaspora_handle != xml_author)
19-
logger.warn "event=receive status=abort reason='author in xml does not match retrieved person' " \
20-
"payload_type=#{@object.class} sender=#{@author.diaspora_handle}"
21-
return true
22-
end
20+
return false unless @author.diaspora_handle != xml_author
21+
logger.error "event=receive status=abort reason='author in xml does not match retrieved person' " \
22+
"type=#{@object.class} sender=#{@author.diaspora_handle}"
23+
true
2324
end
24-
end
2525

26+
def relayable_without_parent?
27+
return false unless @object.respond_to?(:relayable?) && @object.parent.nil?
28+
logger.error "event=receive status=abort reason='no corresponding post' type=#{@object.class} " \
29+
"sender=#{@author.diaspora_handle}"
30+
true
31+
end
32+
end

lib/postzord/receiver/private.rb

+19-28
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,28 @@ def initialize(user, opts={})
99
@user_person = @user.person
1010
@salmon_xml = opts[:salmon_xml]
1111

12-
@sender = opts[:person] || Webfinger.new(self.salmon.author_id).fetch
13-
@author = @sender
12+
@author = opts[:person] || Webfinger.new(salmon.author_id).fetch
1413

1514
@object = opts[:object]
1615
end
1716

1817
def receive!
19-
if @sender && self.salmon.verified_for_key?(@sender.public_key)
18+
if @author && salmon.verified_for_key?(@author.public_key)
2019
parse_and_receive(salmon.parsed_data)
2120
else
2221
logger.error "event=receive status=abort reason='not_verified for key' " \
2322
"recipient=#{@user.diaspora_handle} sender=#{@salmon.author_id}"
2423
end
2524
rescue => e
26-
logger.error "failed to receive #{@object.class} from sender:#{@sender.id} for user:#{@user.id}: #{e.message}\n" \
25+
logger.error "failed to receive #{@object.class} from sender:#{@author.id} for user:#{@user.id}: #{e.message}\n" \
2726
"#{@object.inspect}"
2827
raise e
2928
end
3029

3130
def parse_and_receive(xml)
3231
@object ||= Diaspora::Parser.from_xml(xml)
33-
return if @object.nil?
3432

35-
logger.info "user:#{@user.id} starting private receive from person:#{@sender.guid}"
33+
logger.info "user:#{@user.id} starting private receive from person:#{@author.guid}"
3634

3735
validate_object
3836
set_author!
@@ -43,27 +41,17 @@ def parse_and_receive(xml)
4341
def receive_object
4442
obj = @object.receive(@user, @author)
4543
Notification.notify(@user, obj, @author) if obj.respond_to?(:notification_type)
46-
logger.info "user:#{@user.id} successfully received #{@object.class} from person #{@sender.guid}" \
44+
logger.info "user:#{@user.id} successfully received #{@object.class} from person #{@author.guid}" \
4745
"#{": #{@object.guid}" if @object.respond_to?(:guid)}"
4846
logger.debug "received: #{@object.inspect}"
4947
end
5048

5149
protected
50+
5251
def salmon
5352
@salmon ||= Salmon::EncryptedSlap.from_xml(@salmon_xml, @user)
5453
end
5554

56-
def validate_object
57-
raise Diaspora::ContactRequiredUnlessRequest if contact_required_unless_request
58-
raise Diaspora::RelayableObjectWithoutParent if relayable_without_parent?
59-
60-
assign_sender_handle_if_request
61-
62-
raise Diaspora::AuthorXMLAuthorMismatch if author_does_not_match_xml_author?
63-
64-
@object
65-
end
66-
6755
def xml_author
6856
if @object.respond_to?(:relayable?)
6957
#if A and B are friends, and A sends B a comment from C, we delegate the validation to the owner of the post being commented on
@@ -84,27 +72,30 @@ def set_author!
8472

8573
private
8674

87-
#validations
88-
def relayable_without_parent?
89-
if @object.respond_to?(:relayable?) && @object.parent.nil?
90-
logger.error "event=receive status=abort reason='no corresponding post' type=#{@object.class} " \
91-
"recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle}"
92-
return true
93-
end
75+
# validations
76+
77+
def validate_object
78+
raise Diaspora::XMLNotParseable if @object.nil?
79+
raise Diaspora::ContactRequiredUnlessRequest if contact_required_unless_request
80+
raise Diaspora::RelayableObjectWithoutParent if relayable_without_parent?
81+
82+
assign_sender_handle_if_request
83+
84+
raise Diaspora::AuthorXMLAuthorMismatch if author_does_not_match_xml_author?
9485
end
9586

9687
def contact_required_unless_request
97-
unless @object.is_a?(Request) || @user.contact_for(@sender)
88+
unless @object.is_a?(Request) || @user.contact_for(@author)
9889
logger.error "event=receive status=abort reason='sender not connected to recipient' type=#{@object.class} " \
99-
"recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle}"
90+
"recipient=#{@user_person.diaspora_handle} sender=#{@author.diaspora_handle}"
10091
return true
10192
end
10293
end
10394

10495
def assign_sender_handle_if_request
10596
#special casey
10697
if @object.is_a?(Request)
107-
@object.sender_handle = @sender.diaspora_handle
98+
@object.sender_handle = @author.diaspora_handle
10899
end
109100
end
110101
end

lib/postzord/receiver/public.rb

+27-20
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ class Postzord::Receiver::Public < Postzord::Receiver
99
def initialize(xml)
1010
@salmon = Salmon::Slap.from_xml(xml)
1111
@author = Webfinger.new(@salmon.author_id).fetch
12-
13-
logger.info "Receiving public object from person:#{@author.id}"
1412
end
1513

1614
# @return [Boolean]
@@ -23,7 +21,7 @@ def receive!
2321
return unless verified_signature?
2422
# return false unless account_deletion_is_from_author
2523

26-
return unless save_object
24+
parse_and_receive(@salmon.parsed_data)
2725

2826
logger.info "received a #{@object.inspect}"
2927
if @object.is_a?(SignedRetraction) # feels like a hack
@@ -51,15 +49,23 @@ def receive_relayable
5149
receiver.notify_users
5250
end
5351

54-
# @return [Object]
55-
def save_object
56-
@object = Diaspora::Parser.from_xml(@salmon.parsed_data)
57-
raise Diaspora::XMLNotParseable if @object.nil?
58-
raise Diaspora::NonPublic if object_can_be_public_and_it_is_not?
59-
raise Diaspora::RelayableObjectWithoutParent if object_must_have_parent_and_does_not?
60-
raise Diaspora::AuthorXMLAuthorMismatch if author_does_not_match_xml_author?
61-
@object.save! if @object.respond_to?(:save!)
62-
@object
52+
# @return [void]
53+
def parse_and_receive(xml)
54+
@object = Diaspora::Parser.from_xml(xml)
55+
56+
logger.info "starting public receive from person:#{@author.guid}"
57+
58+
validate_object
59+
receive_object
60+
end
61+
62+
# @return [void]
63+
def receive_object
64+
if @object.respond_to?(:receive_public)
65+
@object.receive_public
66+
elsif @object.respond_to?(:save!)
67+
@object.save!
68+
end
6369
end
6470

6571
# @return [Array<Integer>] User ids
@@ -78,6 +84,15 @@ def xml_author
7884

7985
private
8086

87+
# validations
88+
89+
def validate_object
90+
raise Diaspora::XMLNotParseable if @object.nil?
91+
raise Diaspora::NonPublic if object_can_be_public_and_it_is_not?
92+
raise Diaspora::RelayableObjectWithoutParent if relayable_without_parent?
93+
raise Diaspora::AuthorXMLAuthorMismatch if author_does_not_match_xml_author?
94+
end
95+
8196
def account_deletion_is_from_author
8297
return true unless @object.is_a?(AccountDeletion)
8398
return false if @object.diaspora_handle != @author.diaspora_handle
@@ -88,12 +103,4 @@ def account_deletion_is_from_author
88103
def object_can_be_public_and_it_is_not?
89104
@object.respond_to?(:public) && !@object.public?
90105
end
91-
92-
def object_must_have_parent_and_does_not?
93-
if @object.respond_to?(:relayable?) # comment, like
94-
@object.parent.nil?
95-
else
96-
false
97-
end
98-
end
99106
end

spec/lib/postzord/receiver/private_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
zord = Postzord::Receiver::Private.new(bob, :person => alice.person, :object => @alices_post)
2020
expect(zord.instance_variable_get(:@user)).not_to be_nil
21-
expect(zord.instance_variable_get(:@sender)).not_to be_nil
21+
expect(zord.instance_variable_get(:@author)).not_to be_nil
2222
expect(zord.instance_variable_get(:@object)).not_to be_nil
2323
end
2424

@@ -32,7 +32,7 @@
3232

3333
zord = Postzord::Receiver::Private.new(bob, :salmon_xml => @salmon_xml)
3434
expect(zord.instance_variable_get(:@user)).not_to be_nil
35-
expect(zord.instance_variable_get(:@sender)).not_to be_nil
35+
expect(zord.instance_variable_get(:@author)).not_to be_nil
3636
expect(zord.instance_variable_get(:@salmon_xml)).not_to be_nil
3737
end
3838
end
@@ -45,13 +45,13 @@
4545

4646
context "does not parse and receive" do
4747
it "if the salmon author does not exist" do
48-
@zord.instance_variable_set(:@sender, nil)
48+
@zord.instance_variable_set(:@author, nil)
4949
expect(@zord).not_to receive(:parse_and_receive)
5050
@zord.receive!
5151
end
5252

5353
it "if the author does not match the signature" do
54-
@zord.instance_variable_set(:@sender, FactoryGirl.create(:person))
54+
@zord.instance_variable_set(:@author, FactoryGirl.create(:person))
5555
expect(@zord).not_to receive(:parse_and_receive)
5656
@zord.receive!
5757
end

spec/lib/postzord/receiver/public_spec.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
it "does not save the object if signature is not verified" do
4949
expect(@receiver).to receive(:verified_signature?).and_return(false)
50-
expect(@receiver).not_to receive(:save_object)
50+
expect(@receiver).not_to receive(:parse_and_receive)
5151
@receiver.perform!
5252
end
5353

@@ -58,7 +58,7 @@
5858
end
5959

6060
it 'saves the parsed object' do
61-
expect(@receiver).to receive(:save_object)
61+
expect(@receiver).to receive(:parse_and_receive).and_call_original
6262
@receiver.perform!
6363
end
6464

@@ -120,14 +120,15 @@
120120
end
121121
end
122122

123-
describe "#save_object" do
123+
describe "#parse_and_receive" do
124124
before do
125125
@receiver = Postzord::Receiver::Public.new(@xml)
126+
@parsed_salmon = Salmon::Slap.from_xml(@xml)
126127
end
127128

128129
it "should raise a Diaspora::XMLNotParseable when the parsed object is nil" do
129130
expect(Diaspora::Parser).to receive(:from_xml).and_return(nil)
130-
expect { @receiver.save_object }.to raise_error(Diaspora::XMLNotParseable)
131+
expect { @receiver.parse_and_receive(@parsed_salmon.parsed_data) }.to raise_error(Diaspora::XMLNotParseable)
131132
end
132133
end
133134
end

0 commit comments

Comments
 (0)