Merge pull request #10549 from demarches-simplifiees/new-instructeur-need-mail-confirmation-ldu
ETQ nouvel instructeur, je dois confirmer mon mail
This commit is contained in:
commit
159cc942f6
15 changed files with 116 additions and 28 deletions
|
@ -239,10 +239,16 @@ module Administrateurs
|
||||||
"Les instructeurs ont bien été affectés à la démarche"
|
"Les instructeurs ont bien été affectés à la démarche"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
known_instructeurs, new_instructeurs = instructeurs.partition { |instructeur| instructeur.user.email_verified_at }
|
||||||
|
|
||||||
|
new_instructeurs.each { InstructeurMailer.confirm_and_notify_added_instructeur(_1, groupe_instructeur, current_administrateur.email).deliver_later }
|
||||||
|
|
||||||
|
if known_instructeurs.present?
|
||||||
GroupeInstructeurMailer
|
GroupeInstructeurMailer
|
||||||
.notify_added_instructeurs(groupe_instructeur, instructeurs, current_administrateur.email)
|
.notify_added_instructeurs(groupe_instructeur, known_instructeurs, current_administrateur.email)
|
||||||
.deliver_later
|
.deliver_later
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if procedure.routing_enabled?
|
if procedure.routing_enabled?
|
||||||
redirect_to admin_procedure_groupe_instructeur_path(procedure, groupe_instructeur)
|
redirect_to admin_procedure_groupe_instructeur_path(procedure, groupe_instructeur)
|
||||||
|
|
|
@ -25,7 +25,7 @@ class AgentConnect::AgentController < ApplicationController
|
||||||
instructeur = Instructeur.find_by(users: { email: santized_email(user_info) })
|
instructeur = Instructeur.find_by(users: { email: santized_email(user_info) })
|
||||||
|
|
||||||
if instructeur.nil?
|
if instructeur.nil?
|
||||||
user = User.create_or_promote_to_instructeur(santized_email(user_info), Devise.friendly_token[0, 20])
|
user = User.create_or_promote_to_instructeur(santized_email(user_info), Devise.friendly_token[0, 20], agent_connect: true)
|
||||||
instructeur = user.instructeur
|
instructeur = user.instructeur
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -30,9 +30,13 @@ module Instructeurs
|
||||||
groupe_instructeur.add(instructeur)
|
groupe_instructeur.add(instructeur)
|
||||||
flash[:notice] = "L’instructeur « #{instructeur_email} » a été affecté au groupe."
|
flash[:notice] = "L’instructeur « #{instructeur_email} » a été affecté au groupe."
|
||||||
|
|
||||||
|
if instructeur.user.email_verified_at
|
||||||
GroupeInstructeurMailer
|
GroupeInstructeurMailer
|
||||||
.notify_added_instructeurs(groupe_instructeur, [instructeur], current_user.email)
|
.notify_added_instructeurs(groupe_instructeur, [instructeur], current_user.email)
|
||||||
.deliver_later
|
.deliver_later
|
||||||
|
else
|
||||||
|
InstructeurMailer.confirm_and_notify_added_instructeur(instructeur, groupe_instructeur, current_user.email).deliver_later
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_to instructeur_groupe_path(procedure, groupe_instructeur)
|
redirect_to instructeur_groupe_path(procedure, groupe_instructeur)
|
||||||
|
@ -65,7 +69,6 @@ module Instructeurs
|
||||||
administrateurs: [procedure.administrateurs.first]
|
administrateurs: [procedure.administrateurs.first]
|
||||||
)
|
)
|
||||||
|
|
||||||
user.invite_instructeur! if user.valid?
|
|
||||||
user.instructeur
|
user.instructeur
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -20,9 +20,9 @@ class GroupeInstructeurMailer < ApplicationMailer
|
||||||
@current_instructeur_email = current_instructeur_email
|
@current_instructeur_email = current_instructeur_email
|
||||||
|
|
||||||
subject = if group.procedure.groupe_instructeurs.many?
|
subject = if group.procedure.groupe_instructeurs.many?
|
||||||
"Vous avez été ajouté(e) au groupe \"#{group.label}\" de la démarche \"#{group.procedure.libelle}\""
|
"Vous avez été ajouté(e) au groupe « #{group.label} » de la démarche « #{group.procedure.libelle} »"
|
||||||
else
|
else
|
||||||
"Vous avez été affecté(e) à la démarche \"#{group.procedure.libelle}\""
|
"Vous avez été affecté(e) à la démarche « #{group.procedure.libelle} »"
|
||||||
end
|
end
|
||||||
|
|
||||||
mail(bcc: added_instructeur_emails, subject: subject)
|
mail(bcc: added_instructeur_emails, subject: subject)
|
||||||
|
|
|
@ -47,4 +47,21 @@ class InstructeurMailer < ApplicationMailer
|
||||||
def self.critical_email?(action_name)
|
def self.critical_email?(action_name)
|
||||||
action_name == "send_login_token"
|
action_name == "send_login_token"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def confirm_and_notify_added_instructeur(instructeur, group, current_instructeur_email)
|
||||||
|
@instructeur = instructeur
|
||||||
|
@group = group
|
||||||
|
@current_instructeur_email = current_instructeur_email
|
||||||
|
@reset_password_token = instructeur.user.send(:set_reset_password_token)
|
||||||
|
|
||||||
|
subject = if group.procedure.groupe_instructeurs.many?
|
||||||
|
"Vous avez été ajouté(e) au groupe \"#{group.label}\" de la démarche \"#{group.procedure.libelle}\""
|
||||||
|
else
|
||||||
|
"Vous avez été affecté(e) à la démarche \"#{group.procedure.libelle}\""
|
||||||
|
end
|
||||||
|
|
||||||
|
bypass_unverified_mail_protection!
|
||||||
|
|
||||||
|
mail(to: instructeur.email, subject: subject)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -58,7 +58,6 @@ class GroupeInstructeur < ApplicationRecord
|
||||||
if not_found_emails.present?
|
if not_found_emails.present?
|
||||||
instructeurs_to_add += not_found_emails.map do |email|
|
instructeurs_to_add += not_found_emails.map do |email|
|
||||||
user = User.create_or_promote_to_instructeur(email, SecureRandom.hex, administrateurs: procedure.administrateurs)
|
user = User.create_or_promote_to_instructeur(email, SecureRandom.hex, administrateurs: procedure.administrateurs)
|
||||||
user.invite_instructeur!
|
|
||||||
user.instructeur
|
user.instructeur
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -97,10 +97,16 @@ class User < ApplicationRecord
|
||||||
AdministrateurMailer.activate_before_expiration(self, reset_password_token).deliver_later
|
AdministrateurMailer.activate_before_expiration(self, reset_password_token).deliver_later
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.create_or_promote_to_instructeur(email, password, administrateurs: [])
|
def self.create_or_promote_to_instructeur(email, password, administrateurs: [], agent_connect: false)
|
||||||
|
if agent_connect
|
||||||
user = User
|
user = User
|
||||||
.create_with(password: password, confirmed_at: Time.zone.now, email_verified_at: Time.zone.now)
|
.create_with(password: password, confirmed_at: Time.zone.now, email_verified_at: Time.zone.now)
|
||||||
.find_or_create_by(email: email)
|
.find_or_create_by(email: email)
|
||||||
|
else
|
||||||
|
user = User
|
||||||
|
.create_with(password: password, confirmed_at: Time.zone.now)
|
||||||
|
.find_or_create_by(email: email)
|
||||||
|
end
|
||||||
|
|
||||||
if user.valid?
|
if user.valid?
|
||||||
if user.instructeur.nil?
|
if user.instructeur.nil?
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
%p= t(:hello, scope: [:views, :shared, :greetings])
|
||||||
|
|
||||||
|
%p
|
||||||
|
- number_of_groups = @group.procedure.groupe_instructeurs.many? ? 'many_groups' : 'one_group'
|
||||||
|
= t(".email_body.#{number_of_groups}", groupe: @group.label, email: @current_instructeur_email, procedure: @group.procedure.libelle)
|
||||||
|
|
||||||
|
%p
|
||||||
|
Votre compte a été créé pour l'adresse email
|
||||||
|
%strong #{@instructeur.email}.
|
||||||
|
|
||||||
|
%p
|
||||||
|
Pour l’activer, cliquez sur le lien suivant :
|
||||||
|
= link_to(users_activate_url(token: @reset_password_token), users_activate_url(token: @reset_password_token))
|
||||||
|
|
||||||
|
%p
|
||||||
|
Lors de vos prochaines connexions sur #{Current.application_name} cliquez sur le bouton « Se connecter » positionné sur le haut de page ou bien sur ce lien :
|
||||||
|
= link_to new_user_session_url, new_user_session_url
|
||||||
|
|
||||||
|
%p
|
||||||
|
Nous vous invitons aussi à consulter notre tutoriel à destination des nouveaux instructeurs :
|
||||||
|
= link_to(INSTRUCTEUR_TUTORIAL_URL, INSTRUCTEUR_TUTORIAL_URL)
|
||||||
|
|
||||||
|
|
||||||
|
= render partial: "layouts/mailers/signature"
|
|
@ -18,10 +18,6 @@
|
||||||
Lors de vos prochaines connexions sur #{Current.application_name} cliquez sur le bouton « Se connecter » positionné sur le haut de page ou bien sur ce lien :
|
Lors de vos prochaines connexions sur #{Current.application_name} cliquez sur le bouton « Se connecter » positionné sur le haut de page ou bien sur ce lien :
|
||||||
= link_to new_user_session_url, new_user_session_url
|
= link_to new_user_session_url, new_user_session_url
|
||||||
|
|
||||||
- if AgentConnectService.enabled?
|
|
||||||
%p
|
|
||||||
Vous êtes un agent de l'état et avez accès à AgentConnect ? Vous pouvez utiliser la connexion AgentConnect en suivant ce lien :
|
|
||||||
= link_to agent_connect_url, agent_connect_url
|
|
||||||
%p
|
%p
|
||||||
Nous vous invitons aussi à consulter notre tutoriel à destination des nouveaux instructeurs :
|
Nous vous invitons aussi à consulter notre tutoriel à destination des nouveaux instructeurs :
|
||||||
= link_to(INSTRUCTEUR_TUTORIAL_URL, INSTRUCTEUR_TUTORIAL_URL)
|
= link_to(INSTRUCTEUR_TUTORIAL_URL, INSTRUCTEUR_TUTORIAL_URL)
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
en:
|
||||||
|
instructeur_mailer:
|
||||||
|
confirm_and_notify_added_instructeur:
|
||||||
|
email_body:
|
||||||
|
one_group: "You were assigned to the procedure « %{procedure} » by « %{email} »."
|
||||||
|
many_groups: "You were assigned to the group « %{groupe} » by « %{email} », in charge of procedure « %{procedure} »."
|
|
@ -0,0 +1,6 @@
|
||||||
|
fr:
|
||||||
|
instructeur_mailer:
|
||||||
|
confirm_and_notify_added_instructeur:
|
||||||
|
email_body:
|
||||||
|
one_group: "Vous avez été affecté(e) à la démarche « %{procedure} » par « %{email} »."
|
||||||
|
many_groups: "Vous avez été ajouté(e) au groupe « %{groupe} » par « %{email} », en charge de la démarche « %{procedure} »."
|
|
@ -366,11 +366,17 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
|
||||||
|
|
||||||
before { gi_1_2.instructeurs << instructeur }
|
before { gi_1_2.instructeurs << instructeur }
|
||||||
|
|
||||||
context 'of a news instructeurs' do
|
context 'of news instructeurs' do
|
||||||
let(:new_instructeur_emails) { ['new_i1@mail.com', 'new_i2@mail.com'] }
|
let!(:user_email_verified) { create(:user, :with_email_verified) }
|
||||||
|
let!(:instructeur_email_verified) { create(:instructeur, user: user_email_verified) }
|
||||||
|
let(:new_instructeur_emails) { ['new_i1@mail.com', 'new_i2@mail.com', instructeur_email_verified.email] }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(GroupeInstructeurMailer).to receive(:notify_added_instructeurs)
|
allow(GroupeInstructeurMailer).to receive(:notify_added_instructeurs)
|
||||||
.and_return(double(deliver_later: true))
|
.and_return(double(deliver_later: true))
|
||||||
|
|
||||||
|
allow(InstructeurMailer).to receive(:confirm_and_notify_added_instructeur)
|
||||||
|
.and_return(double(deliver_later: true))
|
||||||
do_request
|
do_request
|
||||||
end
|
end
|
||||||
it { expect(gi_1_2.instructeurs.pluck(:email)).to include(*new_instructeur_emails) }
|
it { expect(gi_1_2.instructeurs.pluck(:email)).to include(*new_instructeur_emails) }
|
||||||
|
@ -380,7 +386,21 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
|
||||||
it "calls GroupeInstructeurMailer with the right params" do
|
it "calls GroupeInstructeurMailer with the right params" do
|
||||||
expect(GroupeInstructeurMailer).to have_received(:notify_added_instructeurs).with(
|
expect(GroupeInstructeurMailer).to have_received(:notify_added_instructeurs).with(
|
||||||
gi_1_2,
|
gi_1_2,
|
||||||
gi_1_2.instructeurs.last(2),
|
[instructeur_email_verified],
|
||||||
|
admin.email
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "calls InstructeurMailer with the right params" do
|
||||||
|
expect(InstructeurMailer).to have_received(:confirm_and_notify_added_instructeur).with(
|
||||||
|
User.find_by(email: 'new_i1@mail.com').instructeur,
|
||||||
|
gi_1_2,
|
||||||
|
admin.email
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(InstructeurMailer).to have_received(:confirm_and_notify_added_instructeur).with(
|
||||||
|
User.find_by(email: 'new_i2@mail.com').instructeur,
|
||||||
|
gi_1_2,
|
||||||
admin.email
|
admin.email
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,5 +16,9 @@ FactoryBot.define do
|
||||||
trait :with_fci do
|
trait :with_fci do
|
||||||
france_connect_informations { [association(:france_connect_information)] }
|
france_connect_informations { [association(:france_connect_information)] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :with_email_verified do
|
||||||
|
email_verified_at { Time.zone.now }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -117,7 +117,7 @@ describe User, type: :model do
|
||||||
user = subject
|
user = subject
|
||||||
expect(user.valid_password?(password)).to be true
|
expect(user.valid_password?(password)).to be true
|
||||||
expect(user.confirmed_at).to be_present
|
expect(user.confirmed_at).to be_present
|
||||||
expect(user.email_verified_at).to be_present
|
expect(user.email_verified_at).not_to be_present
|
||||||
expect(user.instructeur).to be_present
|
expect(user.instructeur).to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -224,13 +224,14 @@ describe User, type: :model do
|
||||||
|
|
||||||
describe '.create_or_promote_to_gestionnaire' do
|
describe '.create_or_promote_to_gestionnaire' do
|
||||||
let(:email) { 'inst1@gmail.com' }
|
let(:email) { 'inst1@gmail.com' }
|
||||||
let(:password) { 'un super password !' }
|
let(:password) { 'un super p1ssw0rd !' }
|
||||||
|
|
||||||
subject { User.create_or_promote_to_gestionnaire(email, password) }
|
subject { User.create_or_promote_to_gestionnaire(email, password) }
|
||||||
|
|
||||||
it 'verifies its email' do
|
it 'creates a gestionnaire with unverified email' do
|
||||||
user = subject
|
user = subject
|
||||||
expect(user.email_verified_at).to be_present
|
expect(user.email_verified_at).to be_nil
|
||||||
|
expect(user.reload.gestionnaire?).to be true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -293,8 +293,8 @@ describe 'The routing with rules', js: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
def register_instructeur_and_log_in(email)
|
def register_instructeur_and_log_in(email)
|
||||||
confirmation_email = emails_sent_to(email)
|
confirmation_email = emails_sent_to(email).reverse
|
||||||
.find { |m| m.subject == 'Activez votre compte instructeur' }
|
.find { |m| m.subject.starts_with?('Vous avez été ajouté(e) au groupe') }
|
||||||
token_params = confirmation_email.body.match(/token=[^"]+/)
|
token_params = confirmation_email.body.match(/token=[^"]+/)
|
||||||
|
|
||||||
visit "users/activate?#{token_params}"
|
visit "users/activate?#{token_params}"
|
||||||
|
|
Loading…
Add table
Reference in a new issue