Harden account deletion
* Wrap it into a transaction * Use destroy over delete so dependent destroys get triggered and we thus don't fail on the foreign key constraits * Check if a photos status message actually exists before accessing it * Add missing dependent destroys
This commit is contained in:
parent
1e09814b13
commit
fc1f249129
7 changed files with 26 additions and 24 deletions
|
|
@ -8,7 +8,7 @@ class Aspect < ActiveRecord::Base
|
|||
has_many :aspect_memberships, :dependent => :destroy
|
||||
has_many :contacts, :through => :aspect_memberships
|
||||
|
||||
has_many :aspect_visibilities
|
||||
has_many :aspect_visibilities, :dependent => :destroy
|
||||
has_many :posts, :through => :aspect_visibilities, :source => :shareable, :source_type => 'Post'
|
||||
has_many :photos, :through => :aspect_visibilities, :source => :shareable, :source_type => 'Photo'
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class Contact < ActiveRecord::Base
|
|||
delegate :name, :diaspora_handle, :guid, :first_name,
|
||||
to: :person, prefix: true
|
||||
|
||||
has_many :aspect_memberships
|
||||
has_many :aspect_memberships, :dependent => :destroy
|
||||
has_many :aspects, :through => :aspect_memberships
|
||||
|
||||
has_many :share_visibilities, :source => :shareable, :source_type => 'Post'
|
||||
|
|
@ -51,7 +51,7 @@ class Contact < ActiveRecord::Base
|
|||
Notification.where(:target_type => "Person",
|
||||
:target_id => person_id,
|
||||
:recipient_id => user_id,
|
||||
:type => "Notifications::StartedSharing").delete_all
|
||||
:type => "Notifications::StartedSharing").destroy_all
|
||||
end
|
||||
|
||||
def dispatch_request
|
||||
|
|
|
|||
|
|
@ -22,6 +22,6 @@ class Mention < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def delete_notification
|
||||
Notification.where(:target_type => self.class.name, :target_id => self.id).delete_all
|
||||
Notification.where(:target_type => self.class.name, :target_id => self.id).destroy_all
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class Photo < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def clear_empty_status_message
|
||||
if self.status_message_guid && self.status_message.text_and_photos_blank?
|
||||
if self.status_message && self.status_message.text_and_photos_blank?
|
||||
self.status_message.destroy
|
||||
else
|
||||
true
|
||||
|
|
|
|||
|
|
@ -23,20 +23,22 @@ class AccountDeleter
|
|||
end
|
||||
|
||||
def perform!
|
||||
#person
|
||||
delete_standard_person_associations
|
||||
remove_conversation_visibilities
|
||||
remove_share_visibilities_on_persons_posts
|
||||
delete_contacts_of_me
|
||||
tombstone_person_and_profile
|
||||
ActiveRecord::Base.transaction do
|
||||
#person
|
||||
delete_standard_person_associations
|
||||
remove_conversation_visibilities
|
||||
remove_share_visibilities_on_persons_posts
|
||||
delete_contacts_of_me
|
||||
tombstone_person_and_profile
|
||||
|
||||
if self.user
|
||||
#user deletion methods
|
||||
remove_share_visibilities_on_contacts_posts
|
||||
delete_standard_user_associations
|
||||
disassociate_invitations
|
||||
disconnect_contacts
|
||||
tombstone_user
|
||||
if self.user
|
||||
#user deletion methods
|
||||
remove_share_visibilities_on_contacts_posts
|
||||
delete_standard_user_associations
|
||||
disassociate_invitations
|
||||
disconnect_contacts
|
||||
tombstone_user
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -55,13 +57,13 @@ class AccountDeleter
|
|||
|
||||
def delete_standard_user_associations
|
||||
normal_ar_user_associates_to_delete.each do |asso|
|
||||
self.user.send(asso).each{|model| model.delete}
|
||||
self.user.send(asso).each{|model| model.destroy }
|
||||
end
|
||||
end
|
||||
|
||||
def delete_standard_person_associations
|
||||
normal_ar_person_associates_to_delete.each do |asso|
|
||||
self.person.send(asso).delete_all
|
||||
self.person.send(asso).destroy_all
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ namespace :accounts do
|
|||
account_delete.perform!
|
||||
end
|
||||
puts "OK."
|
||||
else
|
||||
puts "No acccount deletions to run."
|
||||
end
|
||||
|
||||
puts "No acccount deletions to run."
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ describe AccountDeleter do
|
|||
it 'removes all standard user associaltions' do
|
||||
@account_deletion.normal_ar_user_associates_to_delete.each do |asso|
|
||||
association_double = double
|
||||
association_double.should_receive(:delete)
|
||||
association_double.should_receive(:destroy)
|
||||
bob.should_receive(asso).and_return([association_double])
|
||||
end
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ describe AccountDeleter do
|
|||
it 'removes all standard person associaltions' do
|
||||
@account_deletion.normal_ar_person_associates_to_delete.each do |asso|
|
||||
association_double = double
|
||||
association_double.should_receive(:delete_all)
|
||||
association_double.should_receive(:destroy_all)
|
||||
bob.person.should_receive(asso).and_return(association_double)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue