instructeur need to confirm mail after invitation
This commit is contained in:
parent
169f07cadd
commit
d7893b9102
10 changed files with 79 additions and 12 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
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,6 @@ module Instructeurs
|
||||||
administrateurs: [procedure.administrateurs.first]
|
administrateurs: [procedure.administrateurs.first]
|
||||||
)
|
)
|
||||||
|
|
||||||
user.invite_instructeur! if user.valid?
|
|
||||||
user.instructeur
|
user.instructeur
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -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,28 @@
|
||||||
|
%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
|
||||||
|
|
||||||
|
- 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
|
||||||
|
Nous vous invitons aussi à consulter notre tutoriel à destination des nouveaux instructeurs :
|
||||||
|
= link_to(INSTRUCTEUR_TUTORIAL_URL, INSTRUCTEUR_TUTORIAL_URL)
|
||||||
|
|
||||||
|
|
||||||
|
= render partial: "layouts/mailers/signature"
|
|
@ -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} »."
|
|
@ -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
|
||||||
|
|
||||||
|
@ -230,7 +230,7 @@ describe User, type: :model do
|
||||||
|
|
||||||
it 'verifies its email' do
|
it 'verifies its email' do
|
||||||
user = subject
|
user = subject
|
||||||
expect(user.email_verified_at).to be_present
|
expect(user.email_verified_at).not_to be_present
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue