force password reset on admin promotion or creation
This commit is contained in:
parent
6f5547cafa
commit
de3118bc7b
4 changed files with 21 additions and 13 deletions
|
@ -90,13 +90,7 @@ class User < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def invite_administrateur!(administration_id)
|
def invite_administrateur!(administration_id)
|
||||||
reset_password_token = nil
|
AdministrationMailer.invite_admin(self, set_reset_password_token, administration_id).deliver_later
|
||||||
|
|
||||||
if !active?
|
|
||||||
reset_password_token = set_reset_password_token
|
|
||||||
end
|
|
||||||
|
|
||||||
AdministrationMailer.invite_admin(self, reset_password_token, administration_id).deliver_later
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def remind_invitation!
|
def remind_invitation!
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
%p
|
%p
|
||||||
Votre compte administrateur a été créé pour l'adresse email #{@admin.email}.
|
Votre compte administrateur a été créé pour l'adresse email #{@admin.email}.
|
||||||
|
|
||||||
- if @reset_password_token.present?
|
- if !@admin.active?
|
||||||
%p
|
%p
|
||||||
%b
|
%b
|
||||||
Pour l’activer, cliquez sur le lien suivant :
|
Pour l’activer, cliquez sur le lien suivant :
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
- else
|
- else
|
||||||
%p
|
%p
|
||||||
Pour vous connecter, cliquez sur le lien suivant :
|
Pour vous connecter, cliquez sur le lien suivant :
|
||||||
= link_to(new_user_session_url, new_user_session_url)
|
= link_to edit_user_password_url(@admin, reset_password_token: @reset_password_token), edit_user_password_url(@admin, reset_password_token: @reset_password_token)
|
||||||
|
|
||||||
%p
|
%p
|
||||||
= render partial: "layouts/mailers/bizdev_signature", locals: { author_name: @author_name }
|
= render partial: "layouts/mailers/bizdev_signature", locals: { author_name: @author_name }
|
||||||
|
|
|
@ -1,12 +1,24 @@
|
||||||
RSpec.describe AdministrationMailer, type: :mailer do
|
RSpec.describe AdministrationMailer, type: :mailer do
|
||||||
describe '#invite_admin' do
|
describe '#invite_admin' do
|
||||||
let(:admin) { create(:administrateur) }
|
let(:admin_user) { create(:user, last_sign_in_at: last_sign_in_at) }
|
||||||
let(:token) { "Toc toc toc" }
|
let(:token) { "some_token" }
|
||||||
let(:administration_id) { BizDev::PIPEDRIVE_ID }
|
let(:administration_id) { BizDev::PIPEDRIVE_ID }
|
||||||
|
let(:last_sign_in_at) { nil }
|
||||||
|
|
||||||
subject { described_class.invite_admin(admin, token, administration_id) }
|
subject { described_class.invite_admin(admin_user, token, administration_id) }
|
||||||
|
|
||||||
it { expect(subject.subject).not_to be_empty }
|
it { expect(subject.subject).not_to be_empty }
|
||||||
|
|
||||||
|
describe "when the user has not been activated" do
|
||||||
|
it { expect(subject.body).to include(admin_activate_path(token: token)) }
|
||||||
|
it { expect(subject.body).not_to include(edit_user_password_url(admin_user, reset_password_token: token)) }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "when the user is already active" do
|
||||||
|
let(:last_sign_in_at) { Time.zone.now }
|
||||||
|
it { expect(subject.body).not_to include(admin_activate_path(token: token)) }
|
||||||
|
it { expect(subject.body).to include(edit_user_password_url(admin_user, reset_password_token: token)) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#refuse_admin' do
|
describe '#refuse_admin' do
|
||||||
|
|
|
@ -186,7 +186,9 @@ describe User, type: :model do
|
||||||
subject
|
subject
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(AdministrationMailer).to have_received(:invite_admin).with(user, nil, administration.id) }
|
it 'receives an invitation to update its password' do
|
||||||
|
expect(AdministrationMailer).to have_received(:invite_admin).with(user, kind_of(String), administration.id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue