correctif(dolist): utilise des liens vers les logos des procedures plutôt que des attachements.inlined
This commit is contained in:
parent
28de1a7453
commit
a3c6a2c46f
8 changed files with 33 additions and 21 deletions
1
Gemfile
1
Gemfile
|
@ -59,6 +59,7 @@ gem 'lograge'
|
|||
gem 'logstash-event'
|
||||
gem 'mailjet', require: false
|
||||
gem 'matrix' # needed by prawn and not default in ruby 3.1
|
||||
gem 'mini_magick'
|
||||
gem 'net-imap', require: false # See https://github.com/mikel/mail/pull/1439
|
||||
gem 'net-pop', require: false # same
|
||||
gem 'net-smtp', require: false # same
|
||||
|
|
|
@ -868,6 +868,7 @@ DEPENDENCIES
|
|||
matrix
|
||||
memory_profiler
|
||||
mina
|
||||
mini_magick
|
||||
net-imap
|
||||
net-pop
|
||||
net-smtp
|
||||
|
|
|
@ -8,18 +8,4 @@ class ApplicationMailer < ActionMailer::Base
|
|||
layout 'mailer'
|
||||
|
||||
before_action -> { Sentry.set_tags(mailer: mailer_name, action: action_name) }
|
||||
|
||||
# Attach the procedure logo to the email (if any).
|
||||
# Returns the attachment url.
|
||||
def attach_logo(procedure)
|
||||
if procedure.logo.attached?
|
||||
logo_filename = procedure.logo.filename.to_s
|
||||
attachments.inline[logo_filename] = procedure.logo.download
|
||||
attachments[logo_filename].url
|
||||
end
|
||||
rescue StandardError => e
|
||||
# A problem occured when reading logo, maybe the logo is missing and we should clean the procedure to remove logo reference ?
|
||||
Sentry.capture_exception(e, extra: { procedure_id: procedure.id })
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ class DossierMailer < ApplicationMailer
|
|||
@dossier = params[:dossier]
|
||||
I18n.with_locale(@dossier.user_locale) do
|
||||
@service = @dossier.procedure.service
|
||||
@logo_url = attach_logo(@dossier.procedure)
|
||||
@logo_url = @dossier.procedure.email_logo_url
|
||||
@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 = attach_logo(dossier.procedure)
|
||||
@logo_url = @dossier.procedure.email_logo_url
|
||||
@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 = attach_logo(dossier.procedure)
|
||||
@logo_url = @dossier.procedure.email_logo_url
|
||||
@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 = attach_logo(dossier.procedure)
|
||||
@logo_url = @dossier.procedure.email_logo_url
|
||||
@subject = default_i18n_subject(dossier_id: dossier.id, libelle_demarche: dossier.procedure.libelle)
|
||||
|
||||
mail(to: dossier.user_email_for(:notification), subject: @subject) do |format|
|
||||
|
|
|
@ -17,7 +17,7 @@ class NotificationMailer < ApplicationMailer
|
|||
|
||||
def send_notification
|
||||
@service = @dossier.procedure.service
|
||||
@logo_url = attach_logo(@dossier.procedure)
|
||||
@logo_url = @dossier.procedure.email_logo_url
|
||||
attachments[@attachment[:filename]] = @attachment[:content] if @attachment.present?
|
||||
I18n.with_locale(@dossier.user_locale) do
|
||||
mail(subject: @subject, to: @email, template_name: 'send_notification')
|
||||
|
|
|
@ -158,7 +158,9 @@ class Procedure < ApplicationRecord
|
|||
|
||||
belongs_to :defaut_groupe_instructeur, class_name: 'GroupeInstructeur', inverse_of: false, optional: true
|
||||
|
||||
has_one_attached :logo
|
||||
has_one_attached :logo do |attachable|
|
||||
attachable.variant :email, resize_to_limit: [150, 150]
|
||||
end
|
||||
has_one_attached :notice
|
||||
has_one_attached :deliberation
|
||||
|
||||
|
@ -633,6 +635,14 @@ 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)
|
||||
|
|
|
@ -73,7 +73,7 @@ Rails.application.config.action_controller.raise_on_open_redirects = true
|
|||
# generate variants to use image processing macros and ruby-vips
|
||||
# operations. See the upgrading guide for detail on the changes required.
|
||||
# The `:mini_magick` option is not deprecated; it's fine to keep using it.
|
||||
Rails.application.config.active_storage.variant_processor = :vips
|
||||
Rails.application.config.active_storage.variant_processor = :mini_magick
|
||||
|
||||
# Enable parameter wrapping for JSON.
|
||||
# Previously this was set in an initializer. It's fine to keep using that initializer if you've customized it.
|
||||
|
|
|
@ -1446,6 +1446,20 @@ 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) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue