fix #1400 where deleting a user will clean up tags and dependencies too

This commit is contained in:
Reinier Balt 2014-09-23 16:35:45 +02:00
parent f8d4f85a8c
commit 18b7a467c1
2 changed files with 16 additions and 1 deletions

View file

@ -108,6 +108,7 @@ class User < ActiveRecord::Base
before_create :crypt_password, :generate_token
before_update :crypt_password
before_destroy :destroy_dependencies, :delete_taggings, prepend: true # run before deleting todos, projects, contexts, etc.
def validate_auth_type
unless Tracks::Config.auth_schemes.include?(auth_type)
@ -220,4 +221,16 @@ protected
auth_type == 'database' && crypted_password.blank? || password.present?
end
def destroy_dependencies
ids = todos.pluck(:id)
pred_deps = Dependency.where(predecessor_id: ids).destroy_all
succ_deps = Dependency.where(predecessor_id: ids).destroy_all
end
def delete_taggings
ids = todos.pluck(:id)
taggings = Tagging.where(taggable_id: ids).pluck(:id)
Tagging.where(id: taggings).delete_all
end
end