handle retractions
This commit is contained in:
parent
58a5a881cf
commit
59bb46eeb6
5 changed files with 29 additions and 10 deletions
|
|
@ -198,6 +198,10 @@ class Person < ActiveRecord::Base
|
|||
@username ||= owner ? owner.username : diaspora_handle.split("@")[0]
|
||||
end
|
||||
|
||||
def author
|
||||
self
|
||||
end
|
||||
|
||||
def owns?(obj)
|
||||
self.id == obj.author_id
|
||||
end
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ DiasporaFederation.configure do |config|
|
|||
when DiasporaFederation::Entities::AccountDeletion
|
||||
Diaspora::Federation::Receive.account_deletion(entity)
|
||||
when DiasporaFederation::Entities::Retraction
|
||||
# TODO
|
||||
Diaspora::Federation::Receive.retraction(entity, recipient_id)
|
||||
else
|
||||
persisted = case entity
|
||||
when DiasporaFederation::Entities::Comment
|
||||
|
|
|
|||
|
|
@ -148,6 +148,17 @@ module Diaspora
|
|||
).tap(&:save!)
|
||||
end
|
||||
|
||||
def self.retraction(entity, recipient_id)
|
||||
object = entity.target_type.constantize.where(guid: entity.target_guid).take!
|
||||
|
||||
case object
|
||||
when Person
|
||||
User.find(recipient_id).disconnected_by(object)
|
||||
else
|
||||
object.destroy!
|
||||
end
|
||||
end
|
||||
|
||||
def self.status_message(entity)
|
||||
save_status_message(entity).tap do
|
||||
entity.photos.map do |photo|
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ describe "diaspora federation callbacks" do
|
|||
end
|
||||
|
||||
describe ":fetch_related_entity" do
|
||||
it "returns related entity for a existing local post" do
|
||||
it "returns related entity for an existing local post" do
|
||||
post = FactoryGirl.create(:status_message, author: local_person)
|
||||
entity = DiasporaFederation.callbacks.trigger(:fetch_related_entity, "Post", post.guid)
|
||||
expect(entity.author).to eq(post.diaspora_handle)
|
||||
|
|
@ -236,7 +236,7 @@ describe "diaspora federation callbacks" do
|
|||
expect(entity.parent).to be_nil
|
||||
end
|
||||
|
||||
it "returns related entity for a existing remote post" do
|
||||
it "returns related entity for an existing remote post" do
|
||||
post = FactoryGirl.create(:status_message, author: remote_person)
|
||||
entity = DiasporaFederation.callbacks.trigger(:fetch_related_entity, "Post", post.guid)
|
||||
expect(entity.author).to eq(post.diaspora_handle)
|
||||
|
|
@ -245,7 +245,7 @@ describe "diaspora federation callbacks" do
|
|||
expect(entity.parent).to be_nil
|
||||
end
|
||||
|
||||
it "returns related entity for a existing public post" do
|
||||
it "returns related entity for an existing public post" do
|
||||
post = FactoryGirl.create(:status_message, author: local_person, public: true)
|
||||
entity = DiasporaFederation.callbacks.trigger(:fetch_related_entity, "Post", post.guid)
|
||||
expect(entity.author).to eq(post.diaspora_handle)
|
||||
|
|
@ -254,7 +254,7 @@ describe "diaspora federation callbacks" do
|
|||
expect(entity.parent).to be_nil
|
||||
end
|
||||
|
||||
it "returns related entity for a existing comment" do
|
||||
it "returns related entity for an existing comment" do
|
||||
post = FactoryGirl.create(:status_message, author: local_person, public: true)
|
||||
comment = FactoryGirl.create(:comment, author: remote_person, parent: post)
|
||||
entity = DiasporaFederation.callbacks.trigger(:fetch_related_entity, "Comment", comment.guid)
|
||||
|
|
@ -267,7 +267,7 @@ describe "diaspora federation callbacks" do
|
|||
expect(entity.parent.parent).to be_nil
|
||||
end
|
||||
|
||||
it "returns related entity for a existing conversation" do
|
||||
it "returns related entity for an existing conversation" do
|
||||
conversation = FactoryGirl.create(:conversation, author: local_person)
|
||||
entity = DiasporaFederation.callbacks.trigger(:fetch_related_entity, "Conversation", conversation.guid)
|
||||
expect(entity.author).to eq(local_person.diaspora_handle)
|
||||
|
|
@ -276,6 +276,14 @@ describe "diaspora federation callbacks" do
|
|||
expect(entity.parent).to be_nil
|
||||
end
|
||||
|
||||
it "returns related entity for an existing person" do
|
||||
entity = DiasporaFederation.callbacks.trigger(:fetch_related_entity, "Person", remote_person.guid)
|
||||
expect(entity.author).to eq(remote_person.diaspora_handle)
|
||||
expect(entity.local).to be_falsey
|
||||
expect(entity.public).to be_falsey
|
||||
expect(entity.parent).to be_nil
|
||||
end
|
||||
|
||||
it "returns nil for a non-existing guid" do
|
||||
expect(
|
||||
DiasporaFederation.callbacks.trigger(:fetch_related_entity, "Post", FactoryGirl.generate(:guid))
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ end
|
|||
|
||||
shared_examples_for "it retracts non-relayable object" do
|
||||
it "retracts object by a correct retraction message" do
|
||||
skip("TODO: handle retractions") # TODO
|
||||
|
||||
entity = retraction_entity(entity_name, target_object, sender)
|
||||
post_message(generate_xml(entity, sender, recipient), recipient)
|
||||
|
||||
|
|
@ -36,8 +34,6 @@ end
|
|||
|
||||
shared_examples_for "it retracts relayable object" do
|
||||
it "retracts object by a correct message" do
|
||||
skip("TODO: handle retractions") # TODO
|
||||
|
||||
entity = retraction_entity(entity_name, target_object, sender)
|
||||
post_message(generate_xml(entity, sender, recipient), recipient)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue