Use person for AccountDeleter
Also remove `disconnect_contacts` methods, because contacts are already removed with aspects memberships in `before_destroy`.
This commit is contained in:
parent
245ad9e04d
commit
7ffd7878d0
5 changed files with 24 additions and 37 deletions
|
|
@ -18,7 +18,7 @@ class AccountDeletion < ApplicationRecord
|
||||||
|
|
||||||
def perform!
|
def perform!
|
||||||
Diaspora::Federation::Dispatcher.build(person.owner, self).dispatch if person.local?
|
Diaspora::Federation::Dispatcher.build(person.owner, self).dispatch if person.local?
|
||||||
AccountDeleter.new(diaspora_handle).perform!
|
AccountDeleter.new(person).perform!
|
||||||
end
|
end
|
||||||
|
|
||||||
def subscribers
|
def subscribers
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@ class AccountDeleter
|
||||||
|
|
||||||
attr_accessor :person, :user
|
attr_accessor :person, :user
|
||||||
|
|
||||||
def initialize(diaspora_handle)
|
def initialize(person)
|
||||||
self.person = Person.where(:diaspora_handle => diaspora_handle).first
|
self.person = person
|
||||||
self.user = self.person.owner
|
self.user = person.owner
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform!
|
def perform!
|
||||||
|
|
@ -34,7 +34,6 @@ class AccountDeleter
|
||||||
#user deletion methods
|
#user deletion methods
|
||||||
remove_share_visibilities_on_contacts_posts
|
remove_share_visibilities_on_contacts_posts
|
||||||
delete_standard_user_associations
|
delete_standard_user_associations
|
||||||
disconnect_contacts
|
|
||||||
tombstone_user
|
tombstone_user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -44,17 +43,17 @@ class AccountDeleter
|
||||||
|
|
||||||
#user deletions
|
#user deletions
|
||||||
def normal_ar_user_associates_to_delete
|
def normal_ar_user_associates_to_delete
|
||||||
%i(tag_followings services aspects user_preferences
|
%i[tag_followings services aspects user_preferences
|
||||||
notifications blocks authorizations o_auth_applications pairwise_pseudonymous_identifiers)
|
notifications blocks authorizations o_auth_applications pairwise_pseudonymous_identifiers]
|
||||||
end
|
end
|
||||||
|
|
||||||
def special_ar_user_associations
|
def special_ar_user_associations
|
||||||
%i(person profile contacts auto_follow_back_aspect)
|
%i[person profile contacts auto_follow_back_aspect]
|
||||||
end
|
end
|
||||||
|
|
||||||
def ignored_ar_user_associations
|
def ignored_ar_user_associations
|
||||||
%i(followed_tags invited_by contact_people aspect_memberships
|
%i[followed_tags invited_by contact_people aspect_memberships
|
||||||
ignored_people share_visibilities conversation_visibilities conversations reports)
|
ignored_people share_visibilities conversation_visibilities conversations reports]
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_standard_user_associations
|
def delete_standard_user_associations
|
||||||
|
|
@ -69,10 +68,6 @@ class AccountDeleter
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def disconnect_contacts
|
|
||||||
user.contacts.destroy_all
|
|
||||||
end
|
|
||||||
|
|
||||||
# Currently this would get deleted due to the db foreign key constrainsts,
|
# Currently this would get deleted due to the db foreign key constrainsts,
|
||||||
# but we'll keep this method here for completeness
|
# but we'll keep this method here for completeness
|
||||||
def remove_share_visibilities_on_contacts_posts
|
def remove_share_visibilities_on_contacts_posts
|
||||||
|
|
@ -97,7 +92,7 @@ class AccountDeleter
|
||||||
end
|
end
|
||||||
|
|
||||||
def normal_ar_person_associates_to_delete
|
def normal_ar_person_associates_to_delete
|
||||||
%i(posts photos mentions participations roles)
|
%i[posts photos mentions participations roles]
|
||||||
end
|
end
|
||||||
|
|
||||||
def ignored_or_special_ar_person_associations
|
def ignored_or_special_ar_person_associations
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
describe "deleteing account", type: :request do
|
describe "deleteing account", type: :request do
|
||||||
def account_removal_method
|
def account_removal_method
|
||||||
AccountDeleter.new(subject.diaspora_handle).perform!
|
AccountDeleter.new(person).perform!
|
||||||
subject.reload
|
subject.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
context "of local user" do
|
context "of local user" do
|
||||||
subject(:user) { FactoryGirl.create(:user_with_aspect) }
|
subject(:user) { FactoryGirl.create(:user_with_aspect) }
|
||||||
|
let(:person) { user.person }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
DataGenerator.create(subject, :generic_user_data)
|
DataGenerator.create(subject, :generic_user_data)
|
||||||
|
|
@ -29,9 +30,7 @@ describe "deleteing account", type: :request do
|
||||||
}.to(eq([true] * user.send(:clearable_fields).count)))
|
}.to(eq([true] * user.send(:clearable_fields).count)))
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like "it removes the person associations" do
|
it_behaves_like "it removes the person associations"
|
||||||
subject(:person) { user.person }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "of remote person" do
|
context "of remote person" do
|
||||||
|
|
|
||||||
|
|
@ -4,28 +4,28 @@
|
||||||
|
|
||||||
describe AccountDeleter do
|
describe AccountDeleter do
|
||||||
before do
|
before do
|
||||||
@account_deletion = AccountDeleter.new(bob.person.diaspora_handle)
|
@account_deletion = AccountDeleter.new(bob.person)
|
||||||
@account_deletion.user = bob
|
@account_deletion.user = bob
|
||||||
end
|
end
|
||||||
|
|
||||||
it "attaches the user" do
|
it "attaches the user" do
|
||||||
expect(AccountDeleter.new(bob.person.diaspora_handle).user).to eq(bob)
|
expect(AccountDeleter.new(bob.person).user).to eq(bob)
|
||||||
expect(AccountDeleter.new(remote_raphael.diaspora_handle).user).to eq(nil)
|
expect(AccountDeleter.new(remote_raphael).user).to eq(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#perform' do
|
describe '#perform' do
|
||||||
user_removal_methods = %i(
|
user_removal_methods = %i[
|
||||||
delete_standard_user_associations
|
delete_standard_user_associations
|
||||||
remove_share_visibilities_on_contacts_posts
|
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_contacts_of_me
|
||||||
delete_standard_person_associations
|
delete_standard_person_associations
|
||||||
tombstone_person_and_profile
|
tombstone_person_and_profile
|
||||||
remove_conversation_visibilities
|
remove_conversation_visibilities
|
||||||
)
|
]
|
||||||
|
|
||||||
context "user deletion" do
|
context "user deletion" do
|
||||||
after do
|
after do
|
||||||
|
|
@ -42,7 +42,7 @@ describe AccountDeleter do
|
||||||
|
|
||||||
context "profile deletion" do
|
context "profile deletion" do
|
||||||
before do
|
before do
|
||||||
@profile_deletion = AccountDeleter.new(remote_raphael.diaspora_handle)
|
@profile_deletion = AccountDeleter.new(remote_raphael)
|
||||||
@profile = remote_raphael.profile
|
@profile = remote_raphael.profile
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -57,7 +57,7 @@ describe AccountDeleter do
|
||||||
|
|
||||||
context "person deletion" do
|
context "person deletion" do
|
||||||
before do
|
before do
|
||||||
@person_deletion = AccountDeleter.new(remote_raphael.diaspora_handle)
|
@person_deletion = AccountDeleter.new(remote_raphael)
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
|
|
@ -109,13 +109,6 @@ describe AccountDeleter do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'person associations' do
|
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
|
describe '#delete_contacts_of_me' do
|
||||||
it 'deletes all the local contact objects where deleted account is the person' do
|
it 'deletes all the local contact objects where deleted account is the person' do
|
||||||
contacts = double
|
contacts = double
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ describe AccountDeletion, type: :model do
|
||||||
|
|
||||||
describe "#perform!" do
|
describe "#perform!" do
|
||||||
it "creates a deleter" 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!
|
account_deletion.perform!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue