Merge branch 'dev'
This commit is contained in:
commit
0f600045c1
2 changed files with 62 additions and 0 deletions
33
app/mailers/preactivate_users_mailer.rb
Normal file
33
app/mailers/preactivate_users_mailer.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
class PreactivateUsersMailer < ApplicationMailer
|
||||
layout 'mailers/layout'
|
||||
|
||||
def reinvite(model, model_name)
|
||||
subject = "Votre compte #{model_name} est activé sur demarches-simplifiees.fr"
|
||||
signature_separator = "-- "
|
||||
body = <<~END_OF_MAIL
|
||||
Bonjour,
|
||||
|
||||
les activations de compte #{model_name} sur demarches-simplifiees.fr
|
||||
ont connu depuis deux semaines un fonctionnement erratique, et nous
|
||||
pensons que votre inscription sur demarches-simplifiees.fr a pu s’en
|
||||
trouver affectée.
|
||||
|
||||
Nous avons maintenant rétabli un fonctionnement normal de l’activation
|
||||
des comptes. Vous pouvez désormais vous connecter sans encombres à votre
|
||||
compte #{model_name} sur demarches-simplifiees.fr.
|
||||
Si toutefois des difficultés devaient persister, n’hésitez pas à nous
|
||||
en faire part.
|
||||
|
||||
Nous vous présentons nos excuses pour la gène occasionnée.
|
||||
|
||||
Cordialement
|
||||
#{signature_separator}
|
||||
L’équipe demarches-simplifees.fr
|
||||
END_OF_MAIL
|
||||
|
||||
mail(to: model.email,
|
||||
subject: subject,
|
||||
reply_to: CONTACT_EMAIL,
|
||||
body: body)
|
||||
end
|
||||
end
|
29
lib/tasks/2018_06_06_users_for_admins_and_gestionnaires.rake
Normal file
29
lib/tasks/2018_06_06_users_for_admins_and_gestionnaires.rake
Normal file
|
@ -0,0 +1,29 @@
|
|||
namespace :'2018_06_06_users_for_admins_and_gestionnaires' do
|
||||
task preactivate: :environment do
|
||||
preactivate_users(Gestionnaire, 'accompagnateur') { |g| g.reset_password_token.nil? }
|
||||
preactivate_users(Administrateur) { |a| a.active? }
|
||||
end
|
||||
|
||||
def preactivate_users(model, role_name = nil, &block)
|
||||
table_name = model.table_name
|
||||
role_name ||= table_name.singularize
|
||||
|
||||
already_activated = model
|
||||
.joins("INNER JOIN users ON #{table_name}.email = users.email")
|
||||
.where(users: { confirmed_at: nil })
|
||||
.to_a
|
||||
.select(&block)
|
||||
|
||||
puts("Sending emails to #{already_activated.count} #{table_name} that were already confirmed")
|
||||
|
||||
already_activated.each { |m| PreactivateUsersMailer.reinvite(m, role_name).deliver_later }
|
||||
|
||||
count =
|
||||
User
|
||||
.joins("INNER JOIN #{table_name} ON #{table_name}.email = users.email")
|
||||
.where(confirmed_at: nil)
|
||||
.update_all(confirmed_at: DateTime.now)
|
||||
|
||||
puts("Fixed #{count} #{table_name} with unconfirmed user")
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue