[fix #4473] Invite_administrateur!: do not reset password if the user is active
This commit is contained in:
parent
53c7997081
commit
e3d7688e66
4 changed files with 28 additions and 7 deletions
|
@ -47,11 +47,12 @@ class User < ApplicationRecord
|
|||
end
|
||||
|
||||
def invite_administrateur!(administration_id)
|
||||
if administrateur.active?
|
||||
raise "Impossible d'inviter un utilisateur déjà actif !"
|
||||
reset_password_token = nil
|
||||
|
||||
if !administrateur.active?
|
||||
reset_password_token = set_reset_password_token
|
||||
end
|
||||
|
||||
reset_password_token = set_reset_password_token
|
||||
AdministrationMailer.invite_admin(self, reset_password_token, administration_id).deliver_later
|
||||
end
|
||||
|
||||
|
|
|
@ -9,10 +9,15 @@
|
|||
%p
|
||||
Votre compte administrateur a été créé pour l'adresse email #{@admin.email}.
|
||||
|
||||
%p
|
||||
%b
|
||||
Pour l’activer, cliquez sur le lien suivant :
|
||||
= link_to(admin_activate_url(token: @reset_password_token), admin_activate_url(token: @reset_password_token))
|
||||
- if @reset_password_token.present?
|
||||
%p
|
||||
%b
|
||||
Pour l’activer, cliquez sur le lien suivant :
|
||||
= link_to(admin_activate_url(token: @reset_password_token), admin_activate_url(token: @reset_password_token))
|
||||
- else
|
||||
%p
|
||||
Pour vous connecter, cliquez sur le lien suivant :
|
||||
= link_to(new_user_session_url, new_user_session_url)
|
||||
|
||||
%p
|
||||
= render partial: "layouts/mailers/bizdev_signature", locals: { author_name: @author_name }
|
||||
|
|
|
@ -11,6 +11,10 @@ class AdministrationMailerPreview < ActionMailer::Preview
|
|||
AdministrationMailer.invite_admin(administrateur, "12345678", 0)
|
||||
end
|
||||
|
||||
def invite_admin_whose_already_has_an_account
|
||||
AdministrationMailer.invite_admin(administrateur, nil, 0)
|
||||
end
|
||||
|
||||
def refuse_admin
|
||||
AdministrationMailer.refuse_admin('bad_admin@pipo.com')
|
||||
end
|
||||
|
|
|
@ -181,5 +181,16 @@ describe User, type: :model do
|
|||
|
||||
it { expect(AdministrationMailer).to have_received(:invite_admin).with(user, kind_of(String), administration.id) }
|
||||
end
|
||||
|
||||
context 'when the user is actif' do
|
||||
before do
|
||||
user.update(last_sign_in_at: Time.zone.now)
|
||||
mailer_double = double('mailer', deliver_later: true)
|
||||
allow(AdministrationMailer).to receive(:invite_admin).and_return(mailer_double)
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(AdministrationMailer).to have_received(:invite_admin).with(user, nil, administration.id) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue