[#10751] Allow sending a new invitation if the user's previous one has expired
This commit is contained in:
parent
790177c758
commit
a99fae168c
5 changed files with 31 additions and 4 deletions
|
@ -254,7 +254,7 @@ module Administrateurs
|
||||||
|
|
||||||
known_instructeurs, not_verified_instructeurs = instructeurs.partition { |instructeur| instructeur.user.email_verified_at }
|
known_instructeurs, not_verified_instructeurs = instructeurs.partition { |instructeur| instructeur.user.email_verified_at }
|
||||||
|
|
||||||
not_verified_instructeurs.filter(&:previously_new_record?).each do
|
not_verified_instructeurs.filter(&:should_receive_email_activation?).each do
|
||||||
InstructeurMailer.confirm_and_notify_added_instructeur(_1, groupe_instructeur, current_administrateur.email).deliver_later
|
InstructeurMailer.confirm_and_notify_added_instructeur(_1, groupe_instructeur, current_administrateur.email).deliver_later
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ module Instructeurs
|
||||||
GroupeInstructeurMailer
|
GroupeInstructeurMailer
|
||||||
.notify_added_instructeurs(groupe_instructeur, [instructeur], current_user.email)
|
.notify_added_instructeurs(groupe_instructeur, [instructeur], current_user.email)
|
||||||
.deliver_later
|
.deliver_later
|
||||||
elsif instructeur.previously_new_record?
|
elsif instructeur.should_receive_email_activation?
|
||||||
InstructeurMailer.confirm_and_notify_added_instructeur(instructeur, groupe_instructeur, current_user.email).deliver_later
|
InstructeurMailer.confirm_and_notify_added_instructeur(instructeur, groupe_instructeur, current_user.email).deliver_later
|
||||||
end
|
end
|
||||||
# else instructeur already exists and email is not verified, so do not spam them
|
# else instructeur already exists and email is not verified, so do not spam them
|
||||||
|
|
|
@ -214,6 +214,11 @@ class Instructeur < ApplicationRecord
|
||||||
trusted_device_token&.token_young?
|
trusted_device_token&.token_young?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def should_receive_email_activation?
|
||||||
|
# if was recently created or received an activation email more than 7 days ago
|
||||||
|
previously_new_record? || user.reset_password_sent_at.nil? || user.reset_password_sent_at < Devise.reset_password_within.ago
|
||||||
|
end
|
||||||
|
|
||||||
def can_be_deleted?
|
def can_be_deleted?
|
||||||
user.administrateur.nil? && procedures.all? { |p| p.defaut_groupe_instructeur.instructeurs.count > 1 }
|
user.administrateur.nil? && procedures.all? { |p| p.defaut_groupe_instructeur.instructeurs.count > 1 }
|
||||||
end
|
end
|
||||||
|
|
|
@ -387,8 +387,9 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
|
||||||
context 'of news instructeurs' do
|
context 'of news instructeurs' do
|
||||||
let!(:user_email_verified) { create(:user, :with_email_verified) }
|
let!(:user_email_verified) { create(:user, :with_email_verified) }
|
||||||
let!(:instructeur_email_verified) { create(:instructeur, user: user_email_verified) }
|
let!(:instructeur_email_verified) { create(:instructeur, user: user_email_verified) }
|
||||||
let!(:instructeur_email_not_verified) { create(:instructeur, user: create(:user)) }
|
let!(:instructeur_email_not_verified) { create(:instructeur, user: create(:user, { reset_password_sent_at: 1.day.ago })) }
|
||||||
let(:new_instructeur_emails) { ['new_i1@gmail.com', 'new_i2@gmail.com', instructeur_email_verified.email, instructeur_email_not_verified.email] }
|
let!(:instructeur_email_not_verified_but_received_invitation_long_time_ago) { create(:instructeur, user: create(:user, { reset_password_sent_at: 10.days.ago })) }
|
||||||
|
let(:new_instructeur_emails) { ['new_i1@gmail.com', 'new_i2@gmail.com', instructeur_email_verified.email, instructeur_email_not_verified.email, instructeur_email_not_verified_but_received_invitation_long_time_ago.email] }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(GroupeInstructeurMailer).to receive(:notify_added_instructeurs)
|
allow(GroupeInstructeurMailer).to receive(:notify_added_instructeurs)
|
||||||
|
@ -429,6 +430,12 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
|
||||||
gi_1_2,
|
gi_1_2,
|
||||||
admin.email
|
admin.email
|
||||||
)
|
)
|
||||||
|
|
||||||
|
expect(InstructeurMailer).to have_received(:confirm_and_notify_added_instructeur).with(
|
||||||
|
instructeur_email_not_verified_but_received_invitation_long_time_ago,
|
||||||
|
gi_1_2,
|
||||||
|
admin.email
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,21 @@ describe Instructeurs::GroupeInstructeursController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'of an instructeur already known that has received a invitation email long time ago' do
|
||||||
|
let(:known_instructeur) { create(:instructeur, user: create(:user, { reset_password_sent_at: 10.days.ago })) }
|
||||||
|
let(:new_instructeur_email) { known_instructeur.email }
|
||||||
|
|
||||||
|
before { subject }
|
||||||
|
|
||||||
|
it "works" do
|
||||||
|
expect(gi_1_2.instructeurs.map(&:email)).to include(new_instructeur_email)
|
||||||
|
expect(flash.notice).to be_present
|
||||||
|
expect(response).to redirect_to(instructeur_groupe_path(procedure, gi_1_2))
|
||||||
|
expect(InstructeurMailer).to have_received(:confirm_and_notify_added_instructeur)
|
||||||
|
expect(GroupeInstructeurMailer).not_to have_received(:notify_added_instructeurs)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'of an instructeur already in the group' do
|
context 'of an instructeur already in the group' do
|
||||||
let(:new_instructeur_email) { instructeur.email }
|
let(:new_instructeur_email) { instructeur.email }
|
||||||
before { subject }
|
before { subject }
|
||||||
|
|
Loading…
Add table
Reference in a new issue