don't force remove contact on block
this creates inconsistent states, if you remove the block in the future
This commit is contained in:
parent
102e2a0834
commit
581f8d7226
4 changed files with 17 additions and 18 deletions
|
|
@ -35,9 +35,7 @@ class BlocksController < ApplicationController
|
||||||
private
|
private
|
||||||
|
|
||||||
def disconnect_if_contact(person)
|
def disconnect_if_contact(person)
|
||||||
if contact = current_user.contact_for(person)
|
current_user.contact_for(person).try {|contact| current_user.disconnect(contact) }
|
||||||
current_user.disconnect(contact, :force => true)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def block_params
|
def block_params
|
||||||
|
|
|
||||||
|
|
@ -27,29 +27,28 @@ class User
|
||||||
contact
|
contact
|
||||||
end
|
end
|
||||||
|
|
||||||
def disconnect(contact, opts={force: false})
|
def disconnect(contact)
|
||||||
logger.info "event=disconnect user=#{diaspora_handle} target=#{contact.person.diaspora_handle}"
|
logger.info "event=disconnect user=#{diaspora_handle} target=#{contact.person.diaspora_handle}"
|
||||||
|
|
||||||
# TODO: send retraction
|
# TODO: send retraction
|
||||||
|
|
||||||
contact.aspect_memberships.delete_all
|
contact.aspect_memberships.delete_all
|
||||||
|
|
||||||
if !contact.sharing || opts[:force]
|
disconnect_contact(contact, direction: :receiving, destroy: !contact.sharing)
|
||||||
contact.destroy
|
|
||||||
else
|
|
||||||
contact.update_attributes(receiving: false)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def disconnected_by(person)
|
def disconnected_by(person)
|
||||||
logger.info "event=disconnected_by user=#{diaspora_handle} target=#{person.diaspora_handle}"
|
logger.info "event=disconnected_by user=#{diaspora_handle} target=#{person.diaspora_handle}"
|
||||||
contact = contact_for(person)
|
contact_for(person).try {|contact| disconnect_contact(contact, direction: :sharing, destroy: !contact.receiving) }
|
||||||
return unless contact
|
end
|
||||||
|
|
||||||
if contact.receiving
|
private
|
||||||
contact.update_attributes(sharing: false)
|
|
||||||
else
|
def disconnect_contact(contact, direction:, destroy:)
|
||||||
|
if destroy
|
||||||
contact.destroy
|
contact.destroy
|
||||||
|
else
|
||||||
|
contact.update_attributes(direction => false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ describe BlocksController, :type => :controller do
|
||||||
it "calls disconnect with the force option if there is a contact for a given user" do
|
it "calls disconnect with the force option if there is a contact for a given user" do
|
||||||
contact = alice.contact_for(bob.person)
|
contact = alice.contact_for(bob.person)
|
||||||
allow(alice).to receive(:contact_for).and_return(contact)
|
allow(alice).to receive(:contact_for).and_return(contact)
|
||||||
expect(alice).to receive(:disconnect).with(contact, hash_including(:force => true))
|
expect(alice).to receive(:disconnect).with(contact)
|
||||||
@controller.send(:disconnect_if_contact, bob.person)
|
@controller.send(:disconnect_if_contact, bob.person)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,11 @@ describe 'a user receives a post', :type => :request do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not remove visibility on disconnect" do
|
it "does not remove visibility on disconnect" do
|
||||||
alice.disconnect(alice.contact_for(bob.person), force: true)
|
contact = alice.contact_for(bob.person)
|
||||||
alice.reload
|
alice.disconnect(contact)
|
||||||
expect(ShareVisibility.find_by(user_id: alice.id, shareable_id: @status_message.id)).not_to be_nil
|
contact.destroy
|
||||||
|
|
||||||
|
expect(ShareVisibility.exists?(user_id: alice.id, shareable_id: @status_message.id)).to be_truthy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue