disconnect when receiving a Contact with sharing=false

This commit is contained in:
Benjamin Neff 2016-06-18 05:22:00 +02:00
parent 2367be3f66
commit f58167c154
2 changed files with 35 additions and 1 deletions

View file

@ -21,7 +21,12 @@ module Diaspora
def self.contact(entity)
recipient = Person.find_by(diaspora_handle: entity.recipient).owner
if entity.sharing.to_s == "true"
Contact.create_or_update_sharing_contact(recipient, author_of(entity))
else
recipient.disconnected_by(author_of(entity))
nil
end
end
def self.conversation(entity)

View file

@ -77,6 +77,35 @@ describe Diaspora::Federation::Receive do
expect(Diaspora::Federation::Receive.contact(contact_entity)).to be_nil
end
context "sharing=false" do
let(:unshare_contact_entity) {
FactoryGirl.build(
:contact_entity,
author: sender.diaspora_handle,
recipient: alice.diaspora_handle,
sharing: "false"
)
}
it "disconnects, if currently connected" do
alice.contacts.find_or_initialize_by(person_id: sender.id, receiving: true, sharing: true).save!
received = Diaspora::Federation::Receive.contact(unshare_contact_entity)
expect(received).to be_nil
contact = alice.contacts.find_by!(person_id: sender.id)
expect(contact).not_to be_nil
expect(contact.sharing).to be_falsey
end
it "does nothing, if already disconnected" do
received = Diaspora::Federation::Receive.contact(unshare_contact_entity)
expect(received).to be_nil
expect(alice.contacts.find_by(person_id: sender.id)).to be_nil
end
end
end
describe ".conversation" do