chore: generate variant for procedure logo in background

This commit is contained in:
Eric Leroy-Terquem 2024-07-03 18:07:33 +02:00
parent 7693d216d8
commit 00c905a615
No known key found for this signature in database
GPG key ID: 53D8FAECEF207605
4 changed files with 16 additions and 7 deletions

View file

@ -5,7 +5,12 @@ class ProceduresController < ApplicationController
def logo
if @procedure.logo.attached?
redirect_to url_for(@procedure.logo.variant(:email))
logo_variant = @procedure.logo.variant(resize_to_limit: [400, 400])
if logo_variant.key.present?
redirect_to url_for(logo_variant.processed)
else
redirect_to url_for(@procedure.logo)
end
else
redirect_to ActionController::Base.helpers.image_url(PROCEDURE_DEFAULT_LOGO_SRC)
end

View file

@ -106,7 +106,8 @@ class AttestationTemplate < ApplicationRecord
def logo_url
if logo.attached?
Rails.application.routes.url_helpers.url_for(logo)
logo_variant = logo.variant(resize_to_limit: [400, 400])
logo_variant.key.present? ? logo_variant.processed.url : Rails.application.routes.url_helpers.url_for(logo)
end
end

View file

@ -10,7 +10,7 @@ module BlobImageProcessorConcern
end
def representation_required?
from_champ? || from_messagerie?
from_champ? || from_messagerie? || is_a_logo?
end
private
@ -23,6 +23,10 @@ module BlobImageProcessorConcern
attachments.any? { _1.record.class == Commentaire }
end
def logo?
attachments.any? { _1.name == 'logo' }
end
def watermark_required?
attachments.any? { _1.record.class == Champs::TitreIdentiteChamp }
end

View file

@ -176,9 +176,7 @@ class Procedure < ApplicationRecord
belongs_to :defaut_groupe_instructeur, class_name: 'GroupeInstructeur', inverse_of: false, optional: true
has_one_attached :logo do |attachable|
attachable.variant :email, resize_to_limit: [450, 450]
end
has_one_attached :logo
has_one_attached :notice
has_one_attached :deliberation
@ -705,7 +703,8 @@ class Procedure < ApplicationRecord
def logo_url
if logo.attached?
Rails.application.routes.url_helpers.url_for(logo)
logo_variant = logo.variant(resize_to_limit: [400, 400])
logo_variant.key.present? ? logo_variant.processed.url : Rails.application.routes.url_helpers.url_for(logo)
else
ActionController::Base.helpers.image_url(PROCEDURE_DEFAULT_LOGO_SRC)
end