From 5b31aca888e96e85f5d84358e7618662ab373fa1 Mon Sep 17 00:00:00 2001 From: Lisa Durand Date: Wed, 18 Sep 2024 17:19:26 +0200 Subject: [PATCH] improve transfer mail for user without account --- app/mailers/dossier_mailer.rb | 2 ++ .../dossier_mailer/notify_transfer.html.haml | 10 ++++++++-- .../dossier_mailer/notify_transfer/en.yml | 2 ++ .../dossier_mailer/notify_transfer/fr.yml | 2 ++ spec/mailers/dossier_mailer_spec.rb | 18 ++++++++++++++++++ 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/mailers/dossier_mailer.rb b/app/mailers/dossier_mailer.rb index 9dbe65026..aa4fb081d 100644 --- a/app/mailers/dossier_mailer.rb +++ b/app/mailers/dossier_mailer.rb @@ -206,6 +206,8 @@ class DossierMailer < ApplicationMailer def notify_transfer @transfer = params[:dossier_transfer] + @user = User.find_by(email: @transfer.email) + configure_defaults_for_email(@transfer.email) I18n.with_locale(@transfer.user_locale) do diff --git a/app/views/dossier_mailer/notify_transfer.html.haml b/app/views/dossier_mailer/notify_transfer.html.haml index fac5aabd2..c2e9d083f 100644 --- a/app/views/dossier_mailer/notify_transfer.html.haml +++ b/app/views/dossier_mailer/notify_transfer.html.haml @@ -10,7 +10,13 @@ = dossier.procedure.libelle %p - = t('.transfer_text') - = link_to t('.transfer_link'), dossiers_url(statut: 'dossiers-transferes') + - if @user.present? + = t('.transfer_text') + %br + = link_to t('.transfer_link'), dossiers_url(statut: 'dossiers-transferes') + - else + = t('.no_user_transfer_text') + %br + = link_to t('.no_user_transfer_link', app_name: Current.application_name), new_user_registration_url = render partial: "layouts/mailers/signature" diff --git a/config/locales/views/dossier_mailer/notify_transfer/en.yml b/config/locales/views/dossier_mailer/notify_transfer/en.yml index a27e5a5d2..c32b38d67 100644 --- a/config/locales/views/dossier_mailer/notify_transfer/en.yml +++ b/config/locales/views/dossier_mailer/notify_transfer/en.yml @@ -4,5 +4,7 @@ en: subject: You have a pending transfer request. transfer_text: "Access the transfer request by clicking on the following link:" transfer_link: transfer request + no_user_transfer_text: "In order to accept or refuse the request you must have an account:" + no_user_transfer_link: Create an account on %{app_name} transfert_multiple: "%{sender} sends you a transfer request for %{count} files." transfert_simple: "%{sender} sends you a transfer request for file no. %{dossier_id} on the procedure" diff --git a/config/locales/views/dossier_mailer/notify_transfer/fr.yml b/config/locales/views/dossier_mailer/notify_transfer/fr.yml index cdd89147f..fbbd21d0d 100644 --- a/config/locales/views/dossier_mailer/notify_transfer/fr.yml +++ b/config/locales/views/dossier_mailer/notify_transfer/fr.yml @@ -4,5 +4,7 @@ fr: subject: Vous avez une demande de transfert en attente. transfer_text: "Accéder à la demande de transfert en cliquant sur le lien suivant :" transfer_link: demande de transfert + no_user_transfer_text: "Afin de pouvoir accepter ou refuser la demande vous devez avoir un compte :" + no_user_transfer_link: se créer un compte sur %{app_name} transfert_multiple: "%{sender} vous adresse une demande de transfert pour %{count} dossiers." transfert_simple: "%{sender} vous adresse une demande de transfert pour le dossier n° %{dossier_id} sur la démarche" diff --git a/spec/mailers/dossier_mailer_spec.rb b/spec/mailers/dossier_mailer_spec.rb index 57d66f1d0..eb662dd7f 100644 --- a/spec/mailers/dossier_mailer_spec.rb +++ b/spec/mailers/dossier_mailer_spec.rb @@ -313,6 +313,7 @@ RSpec.describe DossierMailer, type: :mailer do describe 'notify_transfer' do let(:user) { create(:user) } + let(:user_2) { create(:user) } let(:procedure) { create(:procedure) } let(:dossier_transfer) { create(:dossier_transfer) } let!(:dossier) { create(:dossier, user: user, transfer: dossier_transfer, procedure: procedure) } @@ -327,6 +328,23 @@ RSpec.describe DossierMailer, type: :mailer do end end + context 'when the user has already an account' do + before do + dossier_transfer.update!(email: user_2.email) + end + it 'includes a direct URL to transfers' do + expect(subject.body).to include('Accéder à la demande de transfert en cliquant sur le lien suivant :') + expect(subject.body).to include(dossiers_url(statut: 'dossiers-transferes', host: ENV.fetch("APP_HOST_LEGACY"))) + end + end + + context 'when the user has no account' do + it 'includes a URL to create one' do + expect(subject.body).to include('Afin de pouvoir accepter ou refuser la demande vous devez avoir un compte :') + expect(subject.body).to include(new_user_registration_url) + end + end + context 'when recipient has preferred domain' do let(:dossier_transfer) { create(:dossier_transfer, email: create(:user, preferred_domain: :demarches_gouv_fr).email) } it 'includes a link with the preferred domain in the email body' do