From 8b9f1b1096db482ce487f6b407e4a8114e325e35 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Fri, 5 Oct 2018 19:11:22 +0200 Subject: [PATCH] Support task to change a user's email --- lib/tasks/support.rake | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/tasks/support.rake b/lib/tasks/support.rake index d889ecb17..0c27f909e 100644 --- a/lib/tasks/support.rake +++ b/lib/tasks/support.rake @@ -70,4 +70,25 @@ namespace :support do EtablissementUpdateJob.perform_now(dossier, siret_number) end + + 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 end