amelioration(mailer.logo): utilise procedure_logo_url pour afficher le logo dans les mails

This commit is contained in:
Martin 2023-08-14 11:09:00 +02:00 committed by mfo
parent a3c6a2c46f
commit bf6b5ea963
4 changed files with 5 additions and 27 deletions

View file

@ -12,7 +12,7 @@ class DossierMailer < ApplicationMailer
@dossier = params[:dossier]
I18n.with_locale(@dossier.user_locale) do
@service = @dossier.procedure.service
@logo_url = @dossier.procedure.email_logo_url
@logo_url = procedure_logo_url(@dossier.procedure)
@subject = default_i18n_subject(libelle_demarche: @dossier.procedure.libelle)
mail(to: @dossier.user_email_for(:notification), subject: @subject) do |format|
@ -27,7 +27,7 @@ class DossierMailer < ApplicationMailer
I18n.with_locale(dossier.user_locale) do
@dossier = dossier
@service = dossier.procedure.service
@logo_url = @dossier.procedure.email_logo_url
@logo_url = procedure_logo_url(@dossier.procedure)
@body = commentaire.body
@subject = default_i18n_subject(dossier_id: dossier.id, libelle_demarche: dossier.procedure.libelle)
@ -52,7 +52,7 @@ class DossierMailer < ApplicationMailer
I18n.with_locale(dossier.user_locale) do
@dossier = dossier
@service = dossier.procedure.service
@logo_url = @dossier.procedure.email_logo_url
@logo_url = procedure_logo_url(@dossier.procedure)
@correction = commentaire.dossier_correction
@subject = default_i18n_subject(dossier_id: dossier.id, libelle_demarche: dossier.procedure.libelle)
@ -85,7 +85,7 @@ class DossierMailer < ApplicationMailer
I18n.with_locale(dossier.user_locale) do
@dossier = dossier
@service = dossier.procedure.service
@logo_url = @dossier.procedure.email_logo_url
@logo_url = procedure_logo_url(@dossier.procedure)
@subject = default_i18n_subject(dossier_id: dossier.id, libelle_demarche: dossier.procedure.libelle)
mail(to: dossier.user_email_for(:notification), subject: @subject) do |format|

View file

@ -17,7 +17,7 @@ class NotificationMailer < ApplicationMailer
def send_notification
@service = @dossier.procedure.service
@logo_url = @dossier.procedure.email_logo_url
@logo_url = procedure_logo_url(@dossier.procedure)
attachments[@attachment[:filename]] = @attachment[:content] if @attachment.present?
I18n.with_locale(@dossier.user_locale) do
mail(subject: @subject, to: @email, template_name: 'send_notification')

View file

@ -635,14 +635,6 @@ class Procedure < ApplicationRecord
result
end
def email_logo_url
if logo.attached?
logo.variant(:email).processed.blob.url(expires_in: 1.year)
else
ActionController::Base.helpers.image_url(PROCEDURE_DEFAULT_LOGO_SRC)
end
end
def logo_url
if logo.attached?
Rails.application.routes.url_helpers.url_for(logo)

View file

@ -1446,20 +1446,6 @@ describe Procedure do
end
end
describe '#email_logo_url' do
context 'with logo' do
let!(:procedure) { create(:procedure, :with_logo) }
it 'creates a blob synchronously one time' do
expect { procedure.email_logo_url }.to change { ActiveStorage::Blob.count }.by(1)
end
it 'creates the blob only the first time' do
procedure.email_logo_url
expect { procedure.email_logo_url }.not_to change { ActiveStorage::Blob.count }
end
end
end
describe '#average_dossier_weight' do
let(:procedure) { create(:procedure, :published) }