Create new invitation email if expert not confirm
This commit is contained in:
parent
bf1a057ac3
commit
ea354d46c4
8 changed files with 78 additions and 15 deletions
|
@ -60,7 +60,11 @@ module CreateAvisConcern
|
||||||
avis.dossier.demander_un_avis!(avis)
|
avis.dossier.demander_un_avis!(avis)
|
||||||
if avis.dossier == dossier
|
if avis.dossier == dossier
|
||||||
if avis.experts_procedure.notify_on_new_avis?
|
if avis.experts_procedure.notify_on_new_avis?
|
||||||
AvisMailer.avis_invitation(avis).deliver_later
|
if avis.expert.user.unverified_email?
|
||||||
|
avis.expert.user.invite_expert_and_send_avis!(avis)
|
||||||
|
else
|
||||||
|
AvisMailer.avis_invitation(avis).deliver_later
|
||||||
|
end
|
||||||
end
|
end
|
||||||
sent_emails_addresses << avis.expert.email
|
sent_emails_addresses << avis.expert.email
|
||||||
# the email format is already verified, we update value to nil
|
# the email format is already verified, we update value to nil
|
||||||
|
|
|
@ -144,6 +144,7 @@ module Experts
|
||||||
|
|
||||||
if user.valid?
|
if user.valid?
|
||||||
sign_in(user)
|
sign_in(user)
|
||||||
|
user.update!(email_verified_at: Time.zone.now) if user.unverified_email?
|
||||||
redirect_to url_for(expert_all_avis_path)
|
redirect_to url_for(expert_all_avis_path)
|
||||||
else
|
else
|
||||||
flash[:alert] = user.errors.full_messages
|
flash[:alert] = user.errors.full_messages
|
||||||
|
|
|
@ -17,7 +17,11 @@ module Instructeurs
|
||||||
def remind
|
def remind
|
||||||
avis = Avis.find(params[:id])
|
avis = Avis.find(params[:id])
|
||||||
if avis.remind_by!(current_instructeur)
|
if avis.remind_by!(current_instructeur)
|
||||||
AvisMailer.avis_invitation(avis).deliver_later
|
if avis.expert.user.unverified_email?
|
||||||
|
avis.expert.user.invite_expert_and_send_avis!(avis)
|
||||||
|
else
|
||||||
|
AvisMailer.avis_invitation(avis).deliver_later
|
||||||
|
end
|
||||||
flash.notice = "Un mail de relance a été envoyé à #{avis.expert.email}"
|
flash.notice = "Un mail de relance a été envoyé à #{avis.expert.email}"
|
||||||
redirect_back(fallback_location: avis_instructeur_dossier_path(avis.procedure, avis.dossier))
|
redirect_back(fallback_location: avis_instructeur_dossier_path(avis.procedure, avis.dossier))
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,6 +20,25 @@ class AvisMailer < ApplicationMailer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def avis_invitation_and_confirm_email(user, token, avis, targeted_user_link = nil) # ensure re-entrance if existing AvisMailer.avis_invitation in queue
|
||||||
|
if avis.dossier.visible_by_administration?
|
||||||
|
targeted_user_link = avis.targeted_user_links
|
||||||
|
.find_or_create_by(target_context: 'avis',
|
||||||
|
target_model_type: Avis.name,
|
||||||
|
target_model_id: avis.id,
|
||||||
|
user: avis.expert.user)
|
||||||
|
email = user.email
|
||||||
|
@token = token
|
||||||
|
@avis = avis
|
||||||
|
@url = targeted_user_link_url(targeted_user_link)
|
||||||
|
subject = "Donnez votre avis sur le dossier nº #{@avis.dossier.id} (#{@avis.dossier.procedure.libelle})"
|
||||||
|
|
||||||
|
bypass_unverified_mail_protection!
|
||||||
|
|
||||||
|
mail(to: email, subject: subject)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# i18n-tasks-use t("avis_mailer.#{action}.subject")
|
# i18n-tasks-use t("avis_mailer.#{action}.subject")
|
||||||
def notify_new_commentaire_to_expert(dossier, avis, expert)
|
def notify_new_commentaire_to_expert(dossier, avis, expert)
|
||||||
I18n.with_locale(dossier.user_locale) do
|
I18n.with_locale(dossier.user_locale) do
|
||||||
|
|
|
@ -31,9 +31,11 @@ class TargetedUserLink < ApplicationRecord
|
||||||
url_helper.invite_path(invite, params: { email: invite.email })
|
url_helper.invite_path(invite, params: { email: invite.email })
|
||||||
when "avis"
|
when "avis"
|
||||||
avis = target_model
|
avis = target_model
|
||||||
avis.expert.user.active? ?
|
if avis.expert.user.active?
|
||||||
url_helper.expert_avis_path(avis.procedure, avis) :
|
url_helper.expert_avis_path(avis.procedure, avis)
|
||||||
|
else
|
||||||
url_helper.sign_up_expert_avis_path(avis.procedure, avis, email: avis.expert.email)
|
url_helper.sign_up_expert_avis_path(avis.procedure, avis, email: avis.expert.email)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,12 @@ class User < ApplicationRecord
|
||||||
UserMailer.invite_tiers(self, token, dossier).deliver_later
|
UserMailer.invite_tiers(self, token, dossier).deliver_later
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def invite_expert_and_send_avis!(avis)
|
||||||
|
token = SecureRandom.hex(10)
|
||||||
|
self.update!(confirmation_token: token, confirmation_sent_at: Time.zone.now)
|
||||||
|
AvisMailer.avis_invitation_and_confirm_email(self, token, avis).deliver_later
|
||||||
|
end
|
||||||
|
|
||||||
def invite_gestionnaire!(groupe_gestionnaire)
|
def invite_gestionnaire!(groupe_gestionnaire)
|
||||||
UserMailer.invite_gestionnaire(self, set_reset_password_token, groupe_gestionnaire).deliver_later
|
UserMailer.invite_gestionnaire(self, set_reset_password_token, groupe_gestionnaire).deliver_later
|
||||||
end
|
end
|
||||||
|
@ -161,13 +167,11 @@ class User < ApplicationRecord
|
||||||
|
|
||||||
def self.create_or_promote_to_expert(email, password)
|
def self.create_or_promote_to_expert(email, password)
|
||||||
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)
|
||||||
.find_or_create_by(email: email)
|
.find_or_create_by(email: email)
|
||||||
|
|
||||||
if user.valid?
|
if user.valid? && user.expert.nil?
|
||||||
if user.expert.nil?
|
user.create_expert!
|
||||||
user.create_expert!
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
user
|
user
|
||||||
|
|
|
@ -22,11 +22,7 @@
|
||||||
%p{ style: "padding: 8px; color: #333333; background-color: #EEEEEE; font-size: 14px;" }
|
%p{ style: "padding: 8px; color: #333333; background-color: #EEEEEE; font-size: 14px;" }
|
||||||
= @avis.introduction
|
= @avis.introduction
|
||||||
|
|
||||||
- if @avis.expert.user.active?.present?
|
%p
|
||||||
%p
|
= round_button("Donner votre avis", @url, :primary)
|
||||||
= round_button("Donner votre avis", @url, :primary)
|
|
||||||
- else
|
|
||||||
%p
|
|
||||||
= round_button("Inscrivez-vous pour donner votre avis", @url, :primary)
|
|
||||||
|
|
||||||
= render partial: "layouts/mailers/signature"
|
= render partial: "layouts/mailers/signature"
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
- content_for(:title, 'Invitation à donner votre avis')
|
||||||
|
|
||||||
|
- content_for(:footer) do
|
||||||
|
Merci de ne pas répondre à cet email. Donnez votre avis
|
||||||
|
= link_to("sur #{Current.application_name}", @url)
|
||||||
|
ou
|
||||||
|
= succeed '.' do
|
||||||
|
= mail_to(@avis.claimant.email, "contactez la personne qui vous a invité")
|
||||||
|
|
||||||
|
%p
|
||||||
|
Bonjour,
|
||||||
|
|
||||||
|
%p
|
||||||
|
Vous avez été invité par
|
||||||
|
%strong= @avis.claimant.email
|
||||||
|
= "à donner votre avis sur le dossier nº #{@avis.dossier.id} de la démarche :"
|
||||||
|
%strong= @avis.procedure.libelle
|
||||||
|
|
||||||
|
%p
|
||||||
|
= "#{@avis.claimant.email} vous a écrit :"
|
||||||
|
%br
|
||||||
|
%p{ style: "padding: 8px; color: #333333; background-color: #EEEEEE; font-size: 14px;" }
|
||||||
|
= @avis.introduction
|
||||||
|
|
||||||
|
- if @avis.expert.user.active?
|
||||||
|
%p
|
||||||
|
= round_button("Confirmer le mail pour donner votre avis", @url, :primary)
|
||||||
|
- else
|
||||||
|
%p
|
||||||
|
= round_button("Inscrivez-vous pour donner votre avis", @url, :primary)
|
||||||
|
|
||||||
|
|
||||||
|
= render partial: "layouts/mailers/signature"
|
Loading…
Add table
Reference in a new issue