refactor delete_user_account task

This commit is contained in:
Christophe Robillard 2020-01-08 11:18:44 +01:00 committed by clemkeirua
parent 9a62d3fe0c
commit c72ce977f7

View file

@ -15,13 +15,11 @@ namespace :support do
user = User.find_by!(email: user_email)
administration = Administration.find_by!(email: administration_email)
if user.dossiers.state_instruction_commencee.any?
if !user.can_be_deleted?
fail "Cannot delete this user because instruction has started for some dossiers"
end
user.dossiers.each do |dossier|
dossier.delete_and_keep_track(administration)
end
user.delete_and_keep_track_dossiers(administration)
user.destroy
end