diff --git a/app/models/person.rb b/app/models/person.rb index 45ba1f5fe..6f684aed9 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -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 diff --git a/config/initializers/diaspora_federation.rb b/config/initializers/diaspora_federation.rb index 6a9b59dee..114d524bd 100644 --- a/config/initializers/diaspora_federation.rb +++ b/config/initializers/diaspora_federation.rb @@ -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 diff --git a/lib/diaspora/federation/receive.rb b/lib/diaspora/federation/receive.rb index 53916b0ae..97aa916de 100644 --- a/lib/diaspora/federation/receive.rb +++ b/lib/diaspora/federation/receive.rb @@ -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| diff --git a/spec/federation_callbacks_spec.rb b/spec/federation_callbacks_spec.rb index 8b107420e..4ea7fb9b0 100644 --- a/spec/federation_callbacks_spec.rb +++ b/spec/federation_callbacks_spec.rb @@ -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)) diff --git a/spec/integration/federation/shared_receive_retraction.rb b/spec/integration/federation/shared_receive_retraction.rb index 2deaf84a9..afa415993 100644 --- a/spec/integration/federation/shared_receive_retraction.rb +++ b/spec/integration/federation/shared_receive_retraction.rb @@ -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)