Unverified Commit 7ffd7878 authored by Benjamin Neff's avatar Benjamin Neff
Browse files

Use person for AccountDeleter

Also remove `disconnect_contacts` methods, because contacts are already
removed with aspects memberships in `before_destroy`.
parent 245ad9e0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ class AccountDeletion < ApplicationRecord

  def perform!
    Diaspora::Federation::Dispatcher.build(person.owner, self).dispatch if person.local?
    AccountDeleter.new(diaspora_handle).perform!
    AccountDeleter.new(person).perform!
  end

  def subscribers
+9 −14
Original line number Diff line number Diff line
@@ -17,9 +17,9 @@ class AccountDeleter

  attr_accessor :person, :user

  def initialize(diaspora_handle)
    self.person = Person.where(:diaspora_handle => diaspora_handle).first
    self.user = self.person.owner
  def initialize(person)
    self.person = person
    self.user = person.owner
  end

  def perform!
@@ -34,7 +34,6 @@ class AccountDeleter
        #user deletion methods
        remove_share_visibilities_on_contacts_posts
        delete_standard_user_associations
        disconnect_contacts
        tombstone_user
      end

@@ -44,17 +43,17 @@ class AccountDeleter

  #user deletions
  def normal_ar_user_associates_to_delete
    %i(tag_followings services aspects user_preferences
       notifications blocks authorizations o_auth_applications pairwise_pseudonymous_identifiers)
    %i[tag_followings services aspects user_preferences
       notifications blocks authorizations o_auth_applications pairwise_pseudonymous_identifiers]
  end

  def special_ar_user_associations
    %i(person profile contacts auto_follow_back_aspect)
    %i[person profile contacts auto_follow_back_aspect]
  end

  def ignored_ar_user_associations
    %i(followed_tags invited_by contact_people aspect_memberships
       ignored_people share_visibilities conversation_visibilities conversations reports)
    %i[followed_tags invited_by contact_people aspect_memberships
       ignored_people share_visibilities conversation_visibilities conversations reports]
  end

  def delete_standard_user_associations
@@ -69,10 +68,6 @@ class AccountDeleter
    end
  end

  def disconnect_contacts
    user.contacts.destroy_all
  end

  # Currently this would get deleted due to the db foreign key constrainsts,
  # but we'll keep this method here for completeness
  def remove_share_visibilities_on_contacts_posts
@@ -97,7 +92,7 @@ class AccountDeleter
  end

  def normal_ar_person_associates_to_delete
    %i(posts photos mentions participations roles)
    %i[posts photos mentions participations roles]
  end

  def ignored_or_special_ar_person_associations
+3 −4
Original line number Diff line number Diff line
describe "deleteing account", type: :request do
  def account_removal_method
    AccountDeleter.new(subject.diaspora_handle).perform!
    AccountDeleter.new(person).perform!
    subject.reload
  end

  context "of local user" do
    subject(:user) { FactoryGirl.create(:user_with_aspect) }
    let(:person) { user.person }

    before do
      DataGenerator.create(subject, :generic_user_data)
@@ -29,9 +30,7 @@ describe "deleteing account", type: :request do
        }.to(eq([true] * user.send(:clearable_fields).count)))
    end

    it_behaves_like "it removes the person associations" do
      subject(:person) { user.person }
    end
    it_behaves_like "it removes the person associations"
  end

  context "of remote person" do
+10 −17
Original line number Diff line number Diff line
@@ -4,28 +4,28 @@

describe AccountDeleter do
  before do
    @account_deletion = AccountDeleter.new(bob.person.diaspora_handle)
    @account_deletion = AccountDeleter.new(bob.person)
    @account_deletion.user = bob
  end

  it "attaches the user" do
    expect(AccountDeleter.new(bob.person.diaspora_handle).user).to eq(bob)
    expect(AccountDeleter.new(remote_raphael.diaspora_handle).user).to eq(nil)
    expect(AccountDeleter.new(bob.person).user).to eq(bob)
    expect(AccountDeleter.new(remote_raphael).user).to eq(nil)
  end

  describe '#perform' do
    user_removal_methods = %i(
    user_removal_methods = %i[
      delete_standard_user_associations
      remove_share_visibilities_on_contacts_posts
      disconnect_contacts tombstone_user
    )
      tombstone_user
    ]

    person_removal_methods = %i(
    person_removal_methods = %i[
      delete_contacts_of_me
      delete_standard_person_associations
      tombstone_person_and_profile
      remove_conversation_visibilities
    )
    ]

    context "user deletion" do
      after do
@@ -42,7 +42,7 @@ describe AccountDeleter do

    context "profile deletion" do
      before do
        @profile_deletion = AccountDeleter.new(remote_raphael.diaspora_handle)
        @profile_deletion = AccountDeleter.new(remote_raphael)
        @profile = remote_raphael.profile
      end

@@ -57,7 +57,7 @@ describe AccountDeleter do

    context "person deletion" do
      before do
        @person_deletion = AccountDeleter.new(remote_raphael.diaspora_handle)
        @person_deletion = AccountDeleter.new(remote_raphael)
      end

      after do
@@ -109,13 +109,6 @@ describe AccountDeleter do
  end

  context 'person associations' do
    describe '#disconnect_contacts' do
      it "deletes all of user's contacts" do
        expect(bob.contacts).to receive(:destroy_all)
        @account_deletion.disconnect_contacts
      end
    end

    describe '#delete_contacts_of_me' do
      it 'deletes all the local contact objects where deleted account is the person' do
        contacts = double
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ describe AccountDeletion, type: :model do

  describe "#perform!" do
    it "creates a deleter" do
      expect(AccountDeleter).to receive(:new).with(alice.person.diaspora_handle).and_return(double(perform!: true))
      expect(AccountDeleter).to receive(:new).with(alice.person).and_return(double(perform!: true))
      account_deletion.perform!
    end