Skip to content
Extraits de code Groupes Projets
Valider fc1f2491 rédigé par Jonne Haß's avatar Jonne Haß
Parcourir les fichiers

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
parent 1e09814b
Aucune requête de fusion associée trouvée
......@@ -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
if self.user
#user deletion methods
remove_share_visibilities_on_contacts_posts
delete_standard_user_associations
disassociate_invitations
disconnect_contacts
tombstone_user
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
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
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter