Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ETQ expert, je dois confirmer mon mail #10705

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/controllers/concerns/create_avis_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ def create_avis_from_params(dossier, instructeur_or_expert, confidentiel = false
avis.dossier.demander_un_avis!(avis)
if avis.dossier == dossier
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
sent_emails_addresses << avis.expert.email
# the email format is already verified, we update value to nil
Expand Down
1 change: 1 addition & 0 deletions app/controllers/experts/avis_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def update_expert

if user.valid?
sign_in(user)
user.update!(email_verified_at: Time.zone.now) if user.unverified_email?
redirect_to url_for(expert_all_avis_path)
else
flash[:alert] = user.errors.full_messages
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/instructeurs/avis_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ def revoquer
def remind
avis = Avis.find(params[:id])
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}"
redirect_back(fallback_location: avis_instructeur_dossier_path(avis.procedure, avis.dossier))
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users/activate_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
else
if user.present?
flash[:alert] = "Ce lien n'est plus valable, un nouveau lien a été envoyé à l'adresse #{user.email}"
User.create_or_promote_to_tiers(user.email, SecureRandom.hex)
user.resend_confirmation_email!

Check warning on line 43 in app/controllers/users/activate_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/users/activate_controller.rb#L43

Added line #L43 was not covered by tests
else
flash[:alert] = "Un problème est survenu, vous pouvez nous contacter sur #{Current.contact_email}"
end
Expand Down
19 changes: 19 additions & 0 deletions app/mailers/avis_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ def avis_invitation(avis, targeted_user_link = nil) # ensure re-entrance if exis
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")
def notify_new_commentaire_to_expert(dossier, avis, expert)
I18n.with_locale(dossier.user_locale) do
Expand Down
14 changes: 14 additions & 0 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@
reply_to: Current.contact_email)
end

def resend_confirmation_email(user, token)
@token = token
@user = user
subject = "Vérification de votre mail"

Check warning on line 69 in app/mailers/user_mailer.rb

View check run for this annotation

Codecov / codecov/patch

app/mailers/user_mailer.rb#L67-L69

Added lines #L67 - L69 were not covered by tests

configure_defaults_for_user(user)

Check warning on line 71 in app/mailers/user_mailer.rb

View check run for this annotation

Codecov / codecov/patch

app/mailers/user_mailer.rb#L71

Added line #L71 was not covered by tests

bypass_unverified_mail_protection!

Check warning on line 73 in app/mailers/user_mailer.rb

View check run for this annotation

Codecov / codecov/patch

app/mailers/user_mailer.rb#L73

Added line #L73 was not covered by tests

mail(to: user.email,

Check warning on line 75 in app/mailers/user_mailer.rb

View check run for this annotation

Codecov / codecov/patch

app/mailers/user_mailer.rb#L75

Added line #L75 was not covered by tests
subject: subject,
reply_to: Current.contact_email)
end

def invite_gestionnaire(user, reset_password_token, groupe_gestionnaire)
@reset_password_token = reset_password_token
@user = user
Expand Down
6 changes: 4 additions & 2 deletions app/models/targeted_user_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
url_helper.invite_path(invite, params: { email: invite.email })
when "avis"
avis = target_model
avis.expert.user.active? ?
url_helper.expert_avis_path(avis.procedure, avis) :
if avis.expert.user.active?

Check warning on line 34 in app/models/targeted_user_link.rb

View check run for this annotation

Codecov / codecov/patch

app/models/targeted_user_link.rb#L34

Added line #L34 was not covered by tests
url_helper.expert_avis_path(avis.procedure, avis)
else
url_helper.sign_up_expert_avis_path(avis.procedure, avis, email: avis.expert.email)
end
end
end

Expand Down
20 changes: 15 additions & 5 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@
UserMailer.invite_tiers(self, token, dossier).deliver_later
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

Check warning on line 96 in app/models/user.rb

View check run for this annotation

Codecov / codecov/patch

app/models/user.rb#L92-L96

Added lines #L92 - L96 were not covered by tests

def resend_confirmation_email!
token = SecureRandom.hex(10)
self.update!(confirmation_token: token, confirmation_sent_at: Time.zone.now)
UserMailer.resend_confirmation_email(self, token).deliver_later
end

Check warning on line 102 in app/models/user.rb

View check run for this annotation

Codecov / codecov/patch

app/models/user.rb#L98-L102

Added lines #L98 - L102 were not covered by tests

def invite_gestionnaire!(groupe_gestionnaire)
UserMailer.invite_gestionnaire(self, set_reset_password_token, groupe_gestionnaire).deliver_later
end
Expand Down Expand Up @@ -161,13 +173,11 @@

def self.create_or_promote_to_expert(email, password)
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)

Check warning on line 176 in app/models/user.rb

View check run for this annotation

Codecov / codecov/patch

app/models/user.rb#L176

Added line #L176 was not covered by tests
.find_or_create_by(email: email)

if user.valid?
if user.expert.nil?
user.create_expert!
end
if user.valid? && user.expert.nil?
user.create_expert!

Check warning on line 180 in app/models/user.rb

View check run for this annotation

Codecov / codecov/patch

app/models/user.rb#L179-L180

Added lines #L179 - L180 were not covered by tests
end

user
Expand Down
8 changes: 2 additions & 6 deletions app/views/avis_mailer/avis_invitation.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@
%p{ style: "padding: 8px; color: #333333; background-color: #EEEEEE; font-size: 14px;" }
= @avis.introduction

- if @avis.expert.user.active?.present?
%p
= round_button("Donner votre avis", @url, :primary)
- else
%p
= round_button("Inscrivez-vous pour donner votre avis", @url, :primary)
%p
= round_button("Donner votre avis", @url, :primary)

= render partial: "layouts/mailers/signature"
33 changes: 33 additions & 0 deletions app/views/avis_mailer/avis_invitation_and_confirm_email.html.haml
Original file line number Diff line number Diff line change
@@ -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('Confirmez votre adresse email pour donner votre avis', users_confirm_email_url(token: @token), :primary)
- else
%p
= round_button("Inscrivez-vous pour donner votre avis", @url, :primary)


= render partial: "layouts/mailers/signature"
18 changes: 18 additions & 0 deletions app/views/user_mailer/resend_confirmation_email.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
- content_for(:title, "Vérification de votre mail sur #{Current.application_name}")

%p
Bonjour,

%p
Votre précédente confirmation de mail n'a pas fonctionné, vous pouvez essayer de nouveau en cliquant sur ce bouton :
= round_button 'Je confirme', users_confirm_email_url(token: @token), :primary

%p
Vous pouvez aussi utiliser ce lien :
= link_to(users_confirm_email_url(token: @token), users_confirm_email_url(token: @token))

%p
Nous restons à votre disposition si vous avez besoin d’accompagnement à l'adresse #{link_to CONTACT_EMAIL, "mailto:#{CONTACT_EMAIL}"}.


= render partial: "layouts/mailers/signature"
Loading