Merge pull request #2773 from betagouv/frederic/support_change_user_mail

Support task to change a user's email
This commit is contained in:
Frederic Merizen 2018-10-06 14:23:16 +02:00 committed by GitHub
commit d5659b69d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -70,4 +70,25 @@ namespace :support do
EtablissementUpdateJob.perform_now(dossier, siret_number)
end
desc <<~EOD
Change a users 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 "Couldnt find existing account for #{old_email}"
end
user.update(email: new_email)
end
end