! NEED JOB REBOOT Move remind activation logic to user
This commit is contained in:
parent
dc816472e9
commit
e3e6bc7689
6 changed files with 16 additions and 17 deletions
|
@ -2,6 +2,10 @@ class Administrateurs::ActivateBeforeExpirationJob < ApplicationJob
|
|||
queue_as :cron
|
||||
|
||||
def perform(*args)
|
||||
Administrateur.inactive.where(created_at: 3.days.ago.all_day).each(&:remind_invitation!)
|
||||
Administrateur
|
||||
.includes(:user)
|
||||
.inactive
|
||||
.where(created_at: 3.days.ago.all_day)
|
||||
.each { |a| a.user.remind_invitation! }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
class AdministrateurMailer < ApplicationMailer
|
||||
layout 'mailers/layout'
|
||||
|
||||
def activate_before_expiration(administrateur, reset_password_token)
|
||||
@administrateur = administrateur
|
||||
def activate_before_expiration(user, reset_password_token)
|
||||
@user = user
|
||||
@reset_password_token = reset_password_token
|
||||
@expiration_date = @administrateur.reset_password_sent_at + Devise.reset_password_within
|
||||
@expiration_date = @user.reset_password_sent_at + Devise.reset_password_within
|
||||
@subject = "N'oubliez pas d'activer votre compte administrateur"
|
||||
|
||||
mail(to: administrateur.email,
|
||||
mail(to: user.email,
|
||||
subject: @subject,
|
||||
reply_to: CONTACT_EMAIL)
|
||||
end
|
||||
|
|
|
@ -55,16 +55,6 @@ class Administrateur < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def remind_invitation!
|
||||
if active?
|
||||
raise "Impossible d'envoyer un rappel d'invitation à un utilisateur déjà actif !"
|
||||
end
|
||||
|
||||
reset_password_token = set_reset_password_token
|
||||
|
||||
AdministrateurMailer.activate_before_expiration(self, reset_password_token).deliver_later
|
||||
end
|
||||
|
||||
def invitation_expired?
|
||||
!active && !reset_password_period_valid?
|
||||
end
|
||||
|
|
|
@ -56,6 +56,11 @@ class User < ApplicationRecord
|
|||
reset_password_token
|
||||
end
|
||||
|
||||
def remind_invitation!
|
||||
reset_password_token = set_reset_password_token
|
||||
|
||||
AdministrateurMailer.activate_before_expiration(self, reset_password_token).deliver_later
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
%p
|
||||
Afin d’activer votre compte, veuillez cliquer sur le lien ci-dessous :
|
||||
= link_to(admin_activate_url(token: @reset_password_token), admin_activate_url(token: @reset_password_token))
|
||||
= link_to(users_activate_url(token: @reset_password_token), users_activate_url(token: @reset_password_token))
|
||||
|
||||
%p
|
||||
Nous restons à votre disposition si vous avez besoin d’accompagnement.
|
||||
|
|
|
@ -38,7 +38,7 @@ RSpec.describe Administrateurs::ActivateBeforeExpirationJob, type: :job do
|
|||
subject
|
||||
end
|
||||
|
||||
it { expect(AdministrateurMailer).to have_received(:activate_before_expiration).with(administrateur, kind_of(String)) }
|
||||
it { expect(AdministrateurMailer).to have_received(:activate_before_expiration).with(administrateur.user, kind_of(String)) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue