From 2fb1b19e09f8d020903580799b1e4403944579cf Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Wed, 10 Apr 2019 10:32:43 +0200 Subject: [PATCH 01/12] Hide other motivation fields when switching between states --- app/javascript/new_design/state-button.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/javascript/new_design/state-button.js b/app/javascript/new_design/state-button.js index da47340fd..c30fa64a2 100644 --- a/app/javascript/new_design/state-button.js +++ b/app/javascript/new_design/state-button.js @@ -2,6 +2,7 @@ import { show, hide } from '@utils'; export function showMotivation(event, state) { event.preventDefault(); + motivationCancel(); show(document.querySelector(`.motivation.${state}`)); hide(document.querySelector('.dropdown-items')); } From 988df15c6b6aed49fecdf20deac29803be463565 Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Tue, 9 Apr 2019 14:32:29 +0200 Subject: [PATCH 02/12] Refactor ProcedurePresentation::sanitize_columns to use model reflection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The passed “table” is actually an association, and may not match the table name. Use model reflection instead of manually pluralizing. --- app/models/procedure_presentation.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index 89ee71721..468bc64da 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -18,7 +18,7 @@ class ProcedurePresentation < ApplicationRecord field_hash('Créé le', 'self', 'created_at'), field_hash('En construction le', 'self', 'en_construction_at'), field_hash('Mis à jour le', 'self', 'updated_at'), - field_hash('Demandeur', 'user', 'email') + field_hash('Demandeur', 'user', 'email'), ] if procedure.for_individual @@ -114,7 +114,7 @@ class ProcedurePresentation < ApplicationRecord dossiers .includes(relation) .where("champs.type_de_champ_id = ?", column.to_i) - .filter_ilike(:champ, :value, values) + .filter_ilike(relation, :value, values) when 'etablissement' if column == 'entreprise_date_creation' dates = values @@ -230,8 +230,14 @@ class ProcedurePresentation < ApplicationRecord @column_whitelist[table] || [] end - def self.sanitized_column(table, column) - [(table == 'self' ? 'dossier' : table.to_s).pluralize, column] + def self.sanitized_column(association, column) + table = if association == 'self' + Dossier.table_name + else + Dossier.reflect_on_association(association).klass.table_name + end + + [table, column] .map { |name| ActiveRecord::Base.connection.quote_column_name(name) } .join('.') end From c5122ee7f528393d7ecc8981051b1a9f164fc7eb Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Tue, 9 Apr 2019 14:32:29 +0200 Subject: [PATCH 03/12] Allow filtering ProcedurePresentation by followers_gestionnaires fixes #3464 --- app/models/procedure_presentation.rb | 7 ++- spec/models/procedure_presentation_spec.rb | 65 ++++++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index 468bc64da..91be561f2 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -19,6 +19,7 @@ class ProcedurePresentation < ApplicationRecord field_hash('En construction le', 'self', 'en_construction_at'), field_hash('Mis à jour le', 'self', 'updated_at'), field_hash('Demandeur', 'user', 'email'), + field_hash('Email instructeur', 'followers_gestionnaires', 'email') ] if procedure.for_individual @@ -92,7 +93,7 @@ class ProcedurePresentation < ApplicationRecord .where("champs.type_de_champ_id = #{column.to_i}") .order("champs.value #{order}") .pluck(:id) - when 'self', 'user', 'individual', 'etablissement' + when 'self', 'user', 'individual', 'etablissement', 'followers_gestionnaires' return (table == 'self' ? dossiers : dossiers.includes(table)) .order("#{self.class.sanitized_column(table, column)} #{order}") .pluck(:id) @@ -128,7 +129,7 @@ class ProcedurePresentation < ApplicationRecord .includes(table) .filter_ilike(table, column, values) end - when 'user', 'individual' + when 'user', 'individual', 'followers_gestionnaires' dossiers .includes(table) .filter_ilike(table, column, values) @@ -201,6 +202,8 @@ class ProcedurePresentation < ApplicationRecord dossier.send(column)&.strftime('%d/%m/%Y') when 'user', 'individual', 'etablissement' dossier.send(table)&.send(column) + when 'followers_gestionnaires' + dossier.send(table)&.map { |g| g.send(column) }&.join(', ') when 'type_de_champ' dossier.champs.find { |c| c.type_de_champ_id == column.to_i }.value when 'type_de_champ_private' diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index d6f493144..b5011fd43 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -61,6 +61,7 @@ describe ProcedurePresentation do { "label" => 'En construction le', "table" => 'self', "column" => 'en_construction_at' }, { "label" => 'Mis à jour le', "table" => 'self', "column" => 'updated_at' }, { "label" => 'Demandeur', "table" => 'user', "column" => 'email' }, + { "label" => 'Email instructeur', "table" => 'followers_gestionnaires', "column" => 'email' }, { "label" => 'SIREN', "table" => 'etablissement', "column" => 'entreprise_siren' }, { "label" => 'Forme juridique', "table" => 'etablissement', "column" => 'entreprise_forme_juridique' }, { "label" => 'Nom commercial', "table" => 'etablissement', "column" => 'entreprise_nom_commercial' }, @@ -196,6 +197,17 @@ describe ProcedurePresentation do it { is_expected.to eq('75008') } end + context 'for followers_gestionnaires table' do + let(:table) { 'followers_gestionnaires' } + let(:column) { 'email' } + + let(:dossier) { create(:dossier, procedure: procedure) } + let!(:follow1) { create(:follow, dossier: dossier, gestionnaire: create(:gestionnaire, email: 'user1@host')) } + let!(:follow2) { create(:follow, dossier: dossier, gestionnaire: create(:gestionnaire, email: 'user2@host')) } + + it { is_expected.to eq('user1@host, user2@host') } + end + context 'for type_de_champ table' do let(:table) { 'type_de_champ' } let(:column) { procedure.types_de_champ.first.id.to_s } @@ -631,6 +643,39 @@ describe ProcedurePresentation do end end end + + context 'for followers_gestionnaires table' do + let(:filter) { [{ 'table' => 'followers_gestionnaires', 'column' => 'email', 'value' => 'keepmail' }] } + + let!(:kept_dossier) { create(:dossier, procedure: procedure) } + let!(:discarded_dossier) { create(:dossier, procedure: procedure) } + + before do + create(:follow, dossier: kept_dossier, gestionnaire: create(:gestionnaire, email: 'me@keepmail.com')) + create(:follow, dossier: discarded_dossier, gestionnaire: create(:gestionnaire, email: 'me@discard.com')) + end + + it { is_expected.to contain_exactly(kept_dossier.id) } + + context 'with multiple search values' do + let(:filter) do + [ + { 'table' => 'followers_gestionnaires', 'column' => 'email', 'value' => 'keepmail' }, + { 'table' => 'followers_gestionnaires', 'column' => 'email', 'value' => 'beta.gouv.fr' } + ] + end + + let(:other_kept_dossier) { create(:dossier, procedure: procedure) } + + before do + create(:follow, dossier: other_kept_dossier, gestionnaire: create(:gestionnaire, email: 'bazinga@beta.gouv.fr')) + end + + it 'returns every dossier that matches any of the search criteria for a given column' do + is_expected.to contain_exactly(kept_dossier.id, other_kept_dossier.id) + end + end + end end describe '#eager_load_displayed_fields' do @@ -650,6 +695,7 @@ describe ProcedurePresentation do expect(displayed_dossier.association(:user)).not_to be_loaded expect(displayed_dossier.association(:individual)).not_to be_loaded expect(displayed_dossier.association(:etablissement)).not_to be_loaded + expect(displayed_dossier.association(:followers_gestionnaires)).not_to be_loaded end end @@ -665,6 +711,7 @@ describe ProcedurePresentation do expect(displayed_dossier.association(:user)).not_to be_loaded expect(displayed_dossier.association(:individual)).not_to be_loaded expect(displayed_dossier.association(:etablissement)).not_to be_loaded + expect(displayed_dossier.association(:followers_gestionnaires)).not_to be_loaded end end @@ -678,6 +725,7 @@ describe ProcedurePresentation do expect(displayed_dossier.association(:user)).to be_loaded expect(displayed_dossier.association(:individual)).not_to be_loaded expect(displayed_dossier.association(:etablissement)).not_to be_loaded + expect(displayed_dossier.association(:followers_gestionnaires)).not_to be_loaded end end @@ -691,6 +739,7 @@ describe ProcedurePresentation do expect(displayed_dossier.association(:user)).not_to be_loaded expect(displayed_dossier.association(:individual)).to be_loaded expect(displayed_dossier.association(:etablissement)).not_to be_loaded + expect(displayed_dossier.association(:followers_gestionnaires)).not_to be_loaded end end @@ -704,6 +753,21 @@ describe ProcedurePresentation do expect(displayed_dossier.association(:user)).not_to be_loaded expect(displayed_dossier.association(:individual)).not_to be_loaded expect(displayed_dossier.association(:etablissement)).to be_loaded + expect(displayed_dossier.association(:followers_gestionnaires)).not_to be_loaded + end + end + + context 'for followers_gestionnaires' do + let(:table) { 'followers_gestionnaires' } + let(:column) { 'email' } + + it 'preloads the followers_gestionnaires relation' do + expect(displayed_dossier.association(:champs)).not_to be_loaded + expect(displayed_dossier.association(:champs_private)).not_to be_loaded + expect(displayed_dossier.association(:user)).not_to be_loaded + expect(displayed_dossier.association(:individual)).not_to be_loaded + expect(displayed_dossier.association(:etablissement)).not_to be_loaded + expect(displayed_dossier.association(:followers_gestionnaires)).to be_loaded end end @@ -717,6 +781,7 @@ describe ProcedurePresentation do expect(displayed_dossier.association(:user)).not_to be_loaded expect(displayed_dossier.association(:individual)).not_to be_loaded expect(displayed_dossier.association(:etablissement)).not_to be_loaded + expect(displayed_dossier.association(:followers_gestionnaires)).not_to be_loaded end end end From e91b412254b807c945b2879badce52aa200e251a Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 14 Mar 2019 10:39:38 +0100 Subject: [PATCH 04/12] [Fix #3064] Use a different layout for state notifications emails --- .../layouts/mailers/notification.html.haml | 2 +- .../mailers/notifications_layout.html.erb | 180 ++++++++++++++++++ .../previews/notification_mailer_preview.rb | 3 +- 3 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 app/views/layouts/mailers/notifications_layout.html.erb diff --git a/app/views/layouts/mailers/notification.html.haml b/app/views/layouts/mailers/notification.html.haml index c71be0360..65d748cd1 100644 --- a/app/views/layouts/mailers/notification.html.haml +++ b/app/views/layouts/mailers/notification.html.haml @@ -4,4 +4,4 @@ = succeed '.' do = link_to 'messagerie', messagerie_dossier_url(@dossier), target: '_blank', rel: 'noopener' -= render template: 'layouts/mailers/layout' += render template: 'layouts/mailers/notifications_layout' diff --git a/app/views/layouts/mailers/notifications_layout.html.erb b/app/views/layouts/mailers/notifications_layout.html.erb new file mode 100644 index 000000000..0fe399670 --- /dev/null +++ b/app/views/layouts/mailers/notifications_layout.html.erb @@ -0,0 +1,180 @@ + + + + + <%= yield(:title) %> + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+
+ + + + + + +
+
+

+

+
+
+
+ +
+
+ + +
+ + + + + + +
+ +
+ + + + + + <% if content_for?(:footer) %> + + + + <% end %> + +
+
+

<%= yield(:title) %>

+ <%= yield %> +
+
+

+ — +

+

+ <%= yield(:footer) %> +

+
+
+ +
+
+ + +
+ + + + + + +
+ +
+ + + + + + + + + +
+
+ demarches-simplifiees.fr est un service fourni par la DINSIC et incubé par beta.gouv.fr +
+
+
+

+

+
+
+
+ +
+
+ +
+ + diff --git a/spec/mailers/previews/notification_mailer_preview.rb b/spec/mailers/previews/notification_mailer_preview.rb index af96ed00e..064d5471d 100644 --- a/spec/mailers/previews/notification_mailer_preview.rb +++ b/spec/mailers/previews/notification_mailer_preview.rb @@ -4,7 +4,8 @@ class NotificationMailerPreview < ActionMailer::Preview end def send_initiated_notification - NotificationMailer.send_initiated_notification(Dossier.last) + p = Procedure.where(id: Mails::InitiatedMail.where("body like ?", "% Date: Thu, 14 Mar 2019 14:58:01 +0100 Subject: [PATCH 05/12] [Fix #3064] Add a preview button for state notifications emails --- .../mail_templates_controller.rb | 33 +++++++++++++++++++ app/views/admin/mail_templates/edit.html.haml | 1 + config/routes.rb | 4 +++ .../mail_templates/edit.html.haml_spec.rb | 1 + 4 files changed, 39 insertions(+) create mode 100644 app/controllers/new_administrateur/mail_templates_controller.rb diff --git a/app/controllers/new_administrateur/mail_templates_controller.rb b/app/controllers/new_administrateur/mail_templates_controller.rb new file mode 100644 index 000000000..73d5ed18c --- /dev/null +++ b/app/controllers/new_administrateur/mail_templates_controller.rb @@ -0,0 +1,33 @@ +module NewAdministrateur + class MailTemplatesController < AdministrateurController + include ActionView::Helpers::SanitizeHelper + + def preview + @procedure = procedure + mail_template = find_mail_template_by_slug(params[:id]) + @dossier = Dossier.new(id: 0) + + render(html: sanitize(mail_template.body), layout: 'mailers/notification') + end + + private + + def procedure + @procedure = current_administrateur.procedures.find(params[:procedure_id]) + end + + def mail_templates + [ + @procedure.initiated_mail_template, + @procedure.received_mail_template, + @procedure.closed_mail_template, + @procedure.refused_mail_template, + @procedure.without_continuation_mail_template + ] + end + + def find_mail_template_by_slug(slug) + mail_templates.find { |template| template.class.const_get(:SLUG) == slug } + end + end +end diff --git a/app/views/admin/mail_templates/edit.html.haml b/app/views/admin/mail_templates/edit.html.haml index a00c116f6..c423fe418 100644 --- a/app/views/admin/mail_templates/edit.html.haml +++ b/app/views/admin/mail_templates/edit.html.haml @@ -15,6 +15,7 @@ .text-right = link_to "Annuler", admin_procedure_mail_templates_path(@procedure), class: "btn btn-default" = f.button :submit, 'Mettre à jour', class: "btn-success" + = link_to "Prévisualiser", preview_procedure_mail_template_path(@procedure, @mail_template.class.const_get(:SLUG)), class: "btn btn-primary", target: "_blank" .row .col-md-12 diff --git a/config/routes.rb b/config/routes.rb index 409795dce..20cd28d8a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -378,6 +378,10 @@ Rails.application.routes.draw do patch :move end end + + resources :mail_templates, only: [] do + get 'preview', on: :member + end end resources :services, except: [:show] do diff --git a/spec/views/admin/mail_templates/edit.html.haml_spec.rb b/spec/views/admin/mail_templates/edit.html.haml_spec.rb index f41f6087b..a381a79d9 100644 --- a/spec/views/admin/mail_templates/edit.html.haml_spec.rb +++ b/spec/views/admin/mail_templates/edit.html.haml_spec.rb @@ -10,6 +10,7 @@ describe 'admin/mail_templates/edit.html.haml', type: :view do allow(view).to receive(:admin_procedure_mail_templates_path).and_return("/toto") assign(:mail_template, mail_template) + assign(:procedure, procedure) end context "Champs are listed in the page" do From b3970a5e6f183dacb843bfa10437f1070f20ccbd Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 14 Mar 2019 16:01:09 +0100 Subject: [PATCH 06/12] [Fix #3064] Change default signature --- app/views/notification_mailer/_signature.html.haml | 4 ++++ app/views/notification_mailer/closed_mail.html.haml | 2 +- .../closed_mail_with_attestation.html.haml | 2 +- app/views/notification_mailer/initiated_mail.html.haml | 2 +- app/views/notification_mailer/received_mail.html.haml | 2 +- app/views/notification_mailer/refused_mail.html.haml | 2 +- .../notification_mailer/without_continuation_mail.html.haml | 2 +- 7 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 app/views/notification_mailer/_signature.html.haml diff --git a/app/views/notification_mailer/_signature.html.haml b/app/views/notification_mailer/_signature.html.haml new file mode 100644 index 000000000..132bfafa4 --- /dev/null +++ b/app/views/notification_mailer/_signature.html.haml @@ -0,0 +1,4 @@ +%p + Bonne journée, + +%p --nom du service-- diff --git a/app/views/notification_mailer/closed_mail.html.haml b/app/views/notification_mailer/closed_mail.html.haml index 080b1071a..dcaf366be 100644 --- a/app/views/notification_mailer/closed_mail.html.haml +++ b/app/views/notification_mailer/closed_mail.html.haml @@ -7,4 +7,4 @@ %p À tout moment, vous pouvez consulter votre dossier et les éventuels messages de l'administration à cette adresse : --lien dossier-- -= render partial: "layouts/mailers/signature" += render partial: "notification_mailer/signature" diff --git a/app/views/notification_mailer/closed_mail_with_attestation.html.haml b/app/views/notification_mailer/closed_mail_with_attestation.html.haml index d8b646f57..22dce3d5a 100644 --- a/app/views/notification_mailer/closed_mail_with_attestation.html.haml +++ b/app/views/notification_mailer/closed_mail_with_attestation.html.haml @@ -10,4 +10,4 @@ %p À tout moment, vous pouvez consulter votre dossier et les éventuels messages de l'administration à cette adresse : --lien dossier-- -= render partial: "layouts/mailers/signature" += render partial: "notification_mailer/signature" diff --git a/app/views/notification_mailer/initiated_mail.html.haml b/app/views/notification_mailer/initiated_mail.html.haml index 796695603..91007a340 100644 --- a/app/views/notification_mailer/initiated_mail.html.haml +++ b/app/views/notification_mailer/initiated_mail.html.haml @@ -7,4 +7,4 @@ %p À tout moment, vous pouvez consulter votre dossier et les éventuels messages de l'administration à cette adresse : --lien dossier-- -= render partial: "layouts/mailers/signature" += render partial: "notification_mailer/signature" diff --git a/app/views/notification_mailer/received_mail.html.haml b/app/views/notification_mailer/received_mail.html.haml index a774789c1..d006d6271 100644 --- a/app/views/notification_mailer/received_mail.html.haml +++ b/app/views/notification_mailer/received_mail.html.haml @@ -4,4 +4,4 @@ %p Votre administration vous confirme la bonne réception de votre dossier nº --numéro du dossier--. Celui-ci sera instruit dans le délai légal déclaré par votre interlocuteur. -= render partial: "layouts/mailers/signature" += render partial: "notification_mailer/signature" diff --git a/app/views/notification_mailer/refused_mail.html.haml b/app/views/notification_mailer/refused_mail.html.haml index 1ed19b296..f45054ca2 100644 --- a/app/views/notification_mailer/refused_mail.html.haml +++ b/app/views/notification_mailer/refused_mail.html.haml @@ -10,4 +10,4 @@ %p Pour en savoir plus sur le motif du refus, vous pouvez consulter votre dossier et les éventuels messages de l'administration à cette adresse : --lien dossier-- -= render partial: "layouts/mailers/signature" += render partial: "notification_mailer/signature" diff --git a/app/views/notification_mailer/without_continuation_mail.html.haml b/app/views/notification_mailer/without_continuation_mail.html.haml index 3033f61cc..c397c1adc 100644 --- a/app/views/notification_mailer/without_continuation_mail.html.haml +++ b/app/views/notification_mailer/without_continuation_mail.html.haml @@ -10,4 +10,4 @@ %p Pour en savoir plus sur les raisons de ce classement sans suite, vous pouvez consulter votre dossier et les éventuels messages de l'administration à cette adresse : --lien dossier-- -= render partial: "layouts/mailers/signature" += render partial: "notification_mailer/signature" From 7e551a9d8dbdb0bc2cc87c9e0267237e077ac44f Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 14 Mar 2019 16:01:30 +0100 Subject: [PATCH 07/12] [Fix #3064] If procedure has logo, then display it in emails --- app/mailers/notification_mailer.rb | 5 +++++ app/views/layouts/mailers/notification.html.haml | 7 +++++++ app/views/layouts/mailers/notifications_layout.html.erb | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 8b855662d..939cb9a88 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -38,6 +38,11 @@ class NotificationMailer < ApplicationMailer @dossier = dossier + if dossier.procedure.logo? + @logo_filename = dossier.procedure.logo.filename + attachments.inline[@logo_filename] = dossier.procedure.logo.read + end + mail(subject: subject, to: email) do |format| # rubocop:disable Rails/OutputSafety format.html { render(html: body.html_safe, layout: 'mailers/notification') } diff --git a/app/views/layouts/mailers/notification.html.haml b/app/views/layouts/mailers/notification.html.haml index 65d748cd1..77cffee7a 100644 --- a/app/views/layouts/mailers/notification.html.haml +++ b/app/views/layouts/mailers/notification.html.haml @@ -1,3 +1,10 @@ +- if @logo_filename.present? + - content_for :procedure_logo do + %table{ width: "100%", border: "0", cellspacing: "0", cellpadding: "0" } + %tr + %td{ align: "center" } + = image_tag attachments[@logo_filename].url, style: "height: 150px;" + - content_for :footer do %strong Merci de ne pas répondre à cet email. Pour vous adresser à votre administration, passez directement par votre diff --git a/app/views/layouts/mailers/notifications_layout.html.erb b/app/views/layouts/mailers/notifications_layout.html.erb index 0fe399670..7c9ea03f9 100644 --- a/app/views/layouts/mailers/notifications_layout.html.erb +++ b/app/views/layouts/mailers/notifications_layout.html.erb @@ -86,10 +86,10 @@
+ <%= yield(:procedure_logo) %> From 60d66f0422b54ade06ac9d5ade89265354561c96 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 14 Mar 2019 16:15:55 +0100 Subject: [PATCH 08/12] [Fix #3064] Add logo and cancel link on preview --- .../new_administrateur/mail_templates_controller.rb | 3 ++- app/mailers/notification_mailer.rb | 5 +++-- app/views/layouts/mailers/notification.html.haml | 10 +++++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/controllers/new_administrateur/mail_templates_controller.rb b/app/controllers/new_administrateur/mail_templates_controller.rb index 73d5ed18c..515b80435 100644 --- a/app/controllers/new_administrateur/mail_templates_controller.rb +++ b/app/controllers/new_administrateur/mail_templates_controller.rb @@ -4,8 +4,9 @@ module NewAdministrateur def preview @procedure = procedure - mail_template = find_mail_template_by_slug(params[:id]) @dossier = Dossier.new(id: 0) + mail_template = find_mail_template_by_slug(params[:id]) + @logo_url = procedure.logo.url render(html: sanitize(mail_template.body), layout: 'mailers/notification') end diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 939cb9a88..aafa91665 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -39,8 +39,9 @@ class NotificationMailer < ApplicationMailer @dossier = dossier if dossier.procedure.logo? - @logo_filename = dossier.procedure.logo.filename - attachments.inline[@logo_filename] = dossier.procedure.logo.read + logo_filename = dossier.procedure.logo.filename + attachments.inline[logo_filename] = dossier.procedure.logo.read + @logo_url = attachments[logo_filename].url end mail(subject: subject, to: email) do |format| diff --git a/app/views/layouts/mailers/notification.html.haml b/app/views/layouts/mailers/notification.html.haml index 77cffee7a..89d3a5c29 100644 --- a/app/views/layouts/mailers/notification.html.haml +++ b/app/views/layouts/mailers/notification.html.haml @@ -1,14 +1,18 @@ -- if @logo_filename.present? +- if @logo_url.present? - content_for :procedure_logo do %table{ width: "100%", border: "0", cellspacing: "0", cellpadding: "0" } %tr %td{ align: "center" } - = image_tag attachments[@logo_filename].url, style: "height: 150px;" + = image_tag @logo_url, style: "height: 150px;" - content_for :footer do + - if @dossier.present? + - messagerie_url = messagerie_dossier_url(@dossier) + - else + - messagerie_url = "#" %strong Merci de ne pas répondre à cet email. Pour vous adresser à votre administration, passez directement par votre = succeed '.' do - = link_to 'messagerie', messagerie_dossier_url(@dossier), target: '_blank', rel: 'noopener' + = link_to 'messagerie', messagerie_url, target: '_blank', rel: 'noopener' = render template: 'layouts/mailers/notifications_layout' From 9c6c11027cc17042d271520bc0a5e7896ff9f499 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 21 Mar 2019 15:39:37 +0100 Subject: [PATCH 09/12] [Fix #3064] Add service footer on notification emails --- .../mail_templates_controller.rb | 5 ++-- app/mailers/notification_mailer.rb | 5 ++-- .../layouts/mailers/notification.html.haml | 24 +++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/controllers/new_administrateur/mail_templates_controller.rb b/app/controllers/new_administrateur/mail_templates_controller.rb index 515b80435..7bc7dfba6 100644 --- a/app/controllers/new_administrateur/mail_templates_controller.rb +++ b/app/controllers/new_administrateur/mail_templates_controller.rb @@ -4,9 +4,10 @@ module NewAdministrateur def preview @procedure = procedure - @dossier = Dossier.new(id: 0) - mail_template = find_mail_template_by_slug(params[:id]) @logo_url = procedure.logo.url + @service = procedure.service + + mail_template = find_mail_template_by_slug(params[:id]) render(html: sanitize(mail_template.body), layout: 'mailers/notification') end diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index aafa91665..767a521b3 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -36,14 +36,15 @@ class NotificationMailer < ApplicationMailer create_commentaire_for_notification(dossier, subject, body) - @dossier = dossier - if dossier.procedure.logo? logo_filename = dossier.procedure.logo.filename attachments.inline[logo_filename] = dossier.procedure.logo.read @logo_url = attachments[logo_filename].url end + @dossier = dossier + @service = dossier.procedure.service + mail(subject: subject, to: email) do |format| # rubocop:disable Rails/OutputSafety format.html { render(html: body.html_safe, layout: 'mailers/notification') } diff --git a/app/views/layouts/mailers/notification.html.haml b/app/views/layouts/mailers/notification.html.haml index 89d3a5c29..16d307003 100644 --- a/app/views/layouts/mailers/notification.html.haml +++ b/app/views/layouts/mailers/notification.html.haml @@ -15,4 +15,28 @@ = succeed '.' do = link_to 'messagerie', messagerie_url, target: '_blank', rel: 'noopener' + - if @service.present? + %table{ width: "100%", border: "0", cellspacing: "0", cellpadding: "0", style: "cursor:auto;color:#55575d;font-family:Helvetica, Arial, sans-serif;font-size:11px;line-height:22px;text-align:left;" } + %tr + %td{ width: "50%", valign: "top" } + %p + %strong Cette démarche est gérée par : + %br + = @service.nom + %br + = @service.organisme + %br + = @service.adresse + %td{ width: "50%", valign: "top" } + %p + %strong Poser une question sur votre dossier : + %br + = link_to 'Par la messagerie', messagerie_url, target: '_blank', rel: 'noopener' + %br + Par téléphone : + = link_to @service.telephone, "tel:#{@service.telephone}" + %br + Horaires : #{ formatted_horaires(@service.horaires) } + + = render template: 'layouts/mailers/notifications_layout' From b3f3106888fb89cff06077a046aa0826b9b2003e Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 21 Mar 2019 15:39:37 +0100 Subject: [PATCH 10/12] [Fix #3064] Change logo size --- app/views/layouts/mailers/notification.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/mailers/notification.html.haml b/app/views/layouts/mailers/notification.html.haml index 16d307003..b267a0fc5 100644 --- a/app/views/layouts/mailers/notification.html.haml +++ b/app/views/layouts/mailers/notification.html.haml @@ -3,7 +3,7 @@ %table{ width: "100%", border: "0", cellspacing: "0", cellpadding: "0" } %tr %td{ align: "center" } - = image_tag @logo_url, style: "height: 150px;" + = image_tag @logo_url, height: "150", style: "display:block; max-height: 150px; max-width: 150px;" - content_for :footer do - if @dossier.present? From 28f9208ce8e2dc61ec5b2758f42dad0a539738fd Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 21 Mar 2019 15:05:30 +0100 Subject: [PATCH 11/12] When mail template is updated, stay on edit page to easily preview it --- app/controllers/admin/mail_templates_controller.rb | 3 ++- spec/controllers/admin/mail_templates_controller_spec.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/mail_templates_controller.rb b/app/controllers/admin/mail_templates_controller.rb index bc7c948ff..3ed7f277d 100644 --- a/app/controllers/admin/mail_templates_controller.rb +++ b/app/controllers/admin/mail_templates_controller.rb @@ -12,7 +12,8 @@ class Admin::MailTemplatesController < AdminController def update mail_template = find_mail_template_by_slug(params[:id]) mail_template.update(update_params) - redirect_to admin_procedure_mail_templates_path + flash.notice = "Email mis à jour" + redirect_to edit_admin_procedure_mail_template_path(mail_template.procedure_id, params[:id]) end private diff --git a/spec/controllers/admin/mail_templates_controller_spec.rb b/spec/controllers/admin/mail_templates_controller_spec.rb index e9c35576f..d34ef2684 100644 --- a/spec/controllers/admin/mail_templates_controller_spec.rb +++ b/spec/controllers/admin/mail_templates_controller_spec.rb @@ -31,7 +31,7 @@ describe Admin::MailTemplatesController, type: :controller do } end - it { expect(response).to redirect_to admin_procedure_mail_templates_path(procedure) } + it { expect(response).to redirect_to edit_admin_procedure_mail_template_path(procedure, initiated_mail.class.const_get(:SLUG)) } context 'the mail template' do subject { procedure.reload; procedure.initiated_mail_template } From c550d40e3a5bf69db36b80b0cc0823f76762bf12 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 27 Mar 2019 12:32:38 +0100 Subject: [PATCH 12/12] [Fix #3064] Add preview test --- .../mail_templates_controller_spec.rb | 21 +++++++++++++++++++ spec/factories/procedure.rb | 4 ++++ 2 files changed, 25 insertions(+) create mode 100644 spec/controllers/new_administrateur/mail_templates_controller_spec.rb diff --git a/spec/controllers/new_administrateur/mail_templates_controller_spec.rb b/spec/controllers/new_administrateur/mail_templates_controller_spec.rb new file mode 100644 index 000000000..2a8673f77 --- /dev/null +++ b/spec/controllers/new_administrateur/mail_templates_controller_spec.rb @@ -0,0 +1,21 @@ +describe NewAdministrateur::MailTemplatesController, type: :controller do + render_views + + let(:admin) { create(:administrateur) } + + describe '#preview' do + let(:procedure) { create(:procedure, :with_logo, :with_service, administrateur: admin) } + + before do + sign_in admin + get :preview, params: { id: "initiated_mail", procedure_id: procedure.id } + end + + it { expect(response).to have_http_status(:ok) } + + it { expect(response.body).to have_css("img[src*='#{procedure.logo.filename}']") } + + it { expect(response.body).to include(procedure.service.nom) } + it { expect(response.body).to include(procedure.service.telephone) } + end +end diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index e45f1c2aa..98488e884 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -41,6 +41,10 @@ FactoryBot.define do end end + trait :with_logo do + logo { Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'application/pdf') } + end + trait :with_path do path { generate(:published_path) } end
-

<%= yield(:title) %>

<%= yield %>