2018-06-13 16:18:23 +02:00
|
|
|
|
require Rails.root.join("lib", "tasks", "task_helper")
|
|
|
|
|
|
|
|
|
|
namespace :support do
|
2018-06-27 12:38:38 +02:00
|
|
|
|
desc <<~EOD
|
2019-07-15 16:00:49 +02:00
|
|
|
|
Delete the user account for a given USER_EMAIL on the behalf of ADMIN_EMAIL.
|
2018-06-27 12:38:38 +02:00
|
|
|
|
Only works if the user has no dossier where the instruction has started.
|
|
|
|
|
EOD
|
|
|
|
|
task delete_user_account: :environment do
|
2018-10-04 11:59:27 +02:00
|
|
|
|
user_email = ENV['USER_EMAIL']
|
2019-07-15 16:00:49 +02:00
|
|
|
|
fail "Must specify a USER_EMAIL" if user_email.nil?
|
|
|
|
|
|
|
|
|
|
administration_email = ENV['ADMIN_EMAIL']
|
|
|
|
|
fail "Must specify the ADMIN_EMAIL of the operator performing the deletion (yourself)" if administration_email.nil?
|
|
|
|
|
|
|
|
|
|
user = User.find_by!(email: user_email)
|
|
|
|
|
administration = Administration.find_by!(email: administration_email)
|
|
|
|
|
|
2020-01-08 11:18:44 +01:00
|
|
|
|
user.delete_and_keep_track_dossiers(administration)
|
2018-06-27 12:38:38 +02:00
|
|
|
|
user.destroy
|
|
|
|
|
end
|
2018-10-05 19:05:55 +02:00
|
|
|
|
|
|
|
|
|
desc <<~EOD
|
|
|
|
|
Change the SIRET for a given dossier (specified by DOSSIER_ID)
|
|
|
|
|
EOD
|
|
|
|
|
task update_dossier_siret: :environment do
|
|
|
|
|
siret_number = ENV['SIRET']
|
|
|
|
|
dossier_id = ENV['DOSSIER_ID']
|
|
|
|
|
|
|
|
|
|
if siret_number.nil?
|
|
|
|
|
fail "Must specify a SIRET"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
siret_number = siret_number.dup # Unfreeze the string
|
|
|
|
|
siret = Siret.new(siret: siret_number)
|
|
|
|
|
if siret.invalid?
|
|
|
|
|
fail siret.errors.full_messages.to_sentence
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
dossier = Dossier.find(dossier_id)
|
|
|
|
|
|
|
|
|
|
EtablissementUpdateJob.perform_now(dossier, siret_number)
|
|
|
|
|
end
|
2018-10-05 19:11:22 +02:00
|
|
|
|
|
|
|
|
|
desc <<~EOD
|
|
|
|
|
Change a user’s mail from OLD_EMAIL to NEW_EMAIL.
|
|
|
|
|
Also works for administrateurs and instructeurs.
|
|
|
|
|
EOD
|
|
|
|
|
task change_user_email: :environment do
|
|
|
|
|
old_email = ENV['OLD_EMAIL']
|
|
|
|
|
new_email = ENV['NEW_EMAIL']
|
|
|
|
|
|
|
|
|
|
if User.find_by(email: new_email).present?
|
|
|
|
|
fail "There is an existing account for #{new_email}, not overwriting"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
user = User.find_by(email: old_email)
|
|
|
|
|
|
|
|
|
|
if user.nil?
|
|
|
|
|
fail "Couldn’t find existing account for #{old_email}"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
user.update(email: new_email)
|
|
|
|
|
end
|
2018-06-13 16:18:23 +02:00
|
|
|
|
end
|