save signature data on receive
This commit is contained in:
parent
2a6ca1b831
commit
1d8ce00bef
2 changed files with 79 additions and 6 deletions
|
|
@ -254,12 +254,20 @@ module Diaspora
|
||||||
yield.tap do |relayable|
|
yield.tap do |relayable|
|
||||||
retract_if_author_ignored(relayable)
|
retract_if_author_ignored(relayable)
|
||||||
|
|
||||||
relayable.author_signature = entity.author_signature if relayable.parent.author.local?
|
relayable.signature = build_signature(klass, entity) if relayable.parent.author.local?
|
||||||
relayable.save!
|
relayable.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private_class_method def self.build_signature(klass, entity)
|
||||||
|
klass.reflect_on_association(:signature).klass.new(
|
||||||
|
author_signature: entity.author_signature,
|
||||||
|
additional_data: entity.additional_xml_elements,
|
||||||
|
signature_order: SignatureOrder.find_or_create_by!(order: entity.xml_order.join(" "))
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
private_class_method def self.retract_if_author_ignored(relayable)
|
private_class_method def self.retract_if_author_ignored(relayable)
|
||||||
parent_author = relayable.parent.author.owner
|
parent_author = relayable.parent.author.owner
|
||||||
return unless parent_author && parent_author.ignored_people.include?(relayable.author)
|
return unless parent_author && parent_author.ignored_people.include?(relayable.author)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,19 @@ describe Diaspora::Federation::Receive do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".comment" do
|
describe ".comment" do
|
||||||
let(:comment_entity) { FactoryGirl.build(:comment_entity, author: sender.diaspora_handle, parent_guid: post.guid) }
|
let(:comment_data) {
|
||||||
|
FactoryGirl.attributes_for(
|
||||||
|
:comment_entity,
|
||||||
|
author: sender.diaspora_handle,
|
||||||
|
parent_guid: post.guid,
|
||||||
|
author_signature: "aa"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
let(:comment_entity) {
|
||||||
|
DiasporaFederation::Entities::Comment.new(
|
||||||
|
comment_data, [:author, :guid, :parent_guid, :text, "new_property"], "new_property" => "data"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
it "saves the comment" do
|
it "saves the comment" do
|
||||||
received = Diaspora::Federation::Receive.perform(comment_entity)
|
received = Diaspora::Federation::Receive.perform(comment_entity)
|
||||||
|
|
@ -39,6 +51,17 @@ describe Diaspora::Federation::Receive do
|
||||||
expect(comment.post).to eq(post)
|
expect(comment.post).to eq(post)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "saves the signature data" do
|
||||||
|
Diaspora::Federation::Receive.perform(comment_entity)
|
||||||
|
|
||||||
|
comment = Comment.find_by!(guid: comment_entity.guid)
|
||||||
|
|
||||||
|
expect(comment.signature).not_to be_nil
|
||||||
|
expect(comment.signature.author_signature).to eq("aa")
|
||||||
|
expect(comment.signature.additional_data).to eq("new_property" => "data")
|
||||||
|
expect(comment.signature.order).to eq(%w(author guid parent_guid text new_property))
|
||||||
|
end
|
||||||
|
|
||||||
let(:entity) { comment_entity }
|
let(:entity) { comment_entity }
|
||||||
it_behaves_like "it ignores existing object received twice", Comment
|
it_behaves_like "it ignores existing object received twice", Comment
|
||||||
it_behaves_like "it rejects if the parent author ignores the author", Comment
|
it_behaves_like "it rejects if the parent author ignores the author", Comment
|
||||||
|
|
@ -164,7 +187,19 @@ describe Diaspora::Federation::Receive do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".like" do
|
describe ".like" do
|
||||||
let(:like_entity) { FactoryGirl.build(:like_entity, author: sender.diaspora_handle, parent_guid: post.guid) }
|
let(:like_data) {
|
||||||
|
FactoryGirl.attributes_for(
|
||||||
|
:like_entity,
|
||||||
|
author: sender.diaspora_handle,
|
||||||
|
parent_guid: post.guid,
|
||||||
|
author_signature: "aa"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
let(:like_entity) {
|
||||||
|
DiasporaFederation::Entities::Like.new(
|
||||||
|
like_data, [:author, :guid, :parent_guid, :parent_type, :positive, "new_property"], "new_property" => "data"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
it "saves the like" do
|
it "saves the like" do
|
||||||
received = Diaspora::Federation::Receive.perform(like_entity)
|
received = Diaspora::Federation::Receive.perform(like_entity)
|
||||||
|
|
@ -185,6 +220,17 @@ describe Diaspora::Federation::Receive do
|
||||||
expect(like.target).to eq(post)
|
expect(like.target).to eq(post)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "saves the signature data" do
|
||||||
|
Diaspora::Federation::Receive.perform(like_entity)
|
||||||
|
|
||||||
|
like = Like.find_by!(guid: like_entity.guid)
|
||||||
|
|
||||||
|
expect(like.signature).not_to be_nil
|
||||||
|
expect(like.signature.author_signature).to eq("aa")
|
||||||
|
expect(like.signature.additional_data).to eq("new_property" => "data")
|
||||||
|
expect(like.signature.order).to eq(%w(author guid parent_guid parent_type positive new_property))
|
||||||
|
end
|
||||||
|
|
||||||
let(:entity) { like_entity }
|
let(:entity) { like_entity }
|
||||||
it_behaves_like "it ignores existing object received twice", Like
|
it_behaves_like "it ignores existing object received twice", Like
|
||||||
it_behaves_like "it rejects if the parent author ignores the author", Like
|
it_behaves_like "it rejects if the parent author ignores the author", Like
|
||||||
|
|
@ -310,12 +356,20 @@ describe Diaspora::Federation::Receive do
|
||||||
|
|
||||||
describe ".poll_participation" do
|
describe ".poll_participation" do
|
||||||
let(:post_with_poll) { FactoryGirl.create(:status_message_with_poll, author: alice.person) }
|
let(:post_with_poll) { FactoryGirl.create(:status_message_with_poll, author: alice.person) }
|
||||||
let(:poll_participation_entity) {
|
let(:poll_participation_data) {
|
||||||
FactoryGirl.build(
|
FactoryGirl.attributes_for(
|
||||||
:poll_participation_entity,
|
:poll_participation_entity,
|
||||||
author: sender.diaspora_handle,
|
author: sender.diaspora_handle,
|
||||||
parent_guid: post_with_poll.poll.guid,
|
parent_guid: post_with_poll.poll.guid,
|
||||||
poll_answer_guid: post_with_poll.poll.poll_answers.first.guid
|
poll_answer_guid: post_with_poll.poll.poll_answers.first.guid,
|
||||||
|
author_signature: "aa"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
let(:poll_participation_entity) {
|
||||||
|
DiasporaFederation::Entities::PollParticipation.new(
|
||||||
|
poll_participation_data,
|
||||||
|
[:author, :guid, :parent_guid, :poll_answer_guid, "new_property"],
|
||||||
|
"new_property" => "data"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -338,6 +392,17 @@ describe Diaspora::Federation::Receive do
|
||||||
expect(poll_participation.poll).to eq(post_with_poll.poll)
|
expect(poll_participation.poll).to eq(post_with_poll.poll)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "saves the signature data" do
|
||||||
|
Diaspora::Federation::Receive.perform(poll_participation_entity)
|
||||||
|
|
||||||
|
poll_participation = PollParticipation.find_by!(guid: poll_participation_entity.guid)
|
||||||
|
|
||||||
|
expect(poll_participation.signature).not_to be_nil
|
||||||
|
expect(poll_participation.signature.author_signature).to eq("aa")
|
||||||
|
expect(poll_participation.signature.additional_data).to eq("new_property" => "data")
|
||||||
|
expect(poll_participation.signature.order).to eq(%w(author guid parent_guid poll_answer_guid new_property))
|
||||||
|
end
|
||||||
|
|
||||||
let(:entity) { poll_participation_entity }
|
let(:entity) { poll_participation_entity }
|
||||||
it_behaves_like "it ignores existing object received twice", PollParticipation
|
it_behaves_like "it ignores existing object received twice", PollParticipation
|
||||||
it_behaves_like "it rejects if the parent author ignores the author", PollParticipation
|
it_behaves_like "it rejects if the parent author ignores the author", PollParticipation
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue