diff --git a/app/decorators/decidim/attachment_patch.rb b/app/decorators/decidim/attachment_patch.rb new file mode 100644 index 0000000..8bfb59d --- /dev/null +++ b/app/decorators/decidim/attachment_patch.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +# Patch pour corriger la méthode file_type dans Decidim::Attachment +# afin d'afficher le bon type MIME sans les query params AWS S3. + +# app/decorators/decidim/attachment_patch.rb + +module Decidim + module AttachmentPatch + end +end + +Rails.logger.info "Patch chargé : Decidim::Attachment#file_type" + +Decidim::Attachment.class_eval do + def file_type + return file.blob.content_type.split("/").last.upcase if file.attached? && file.respond_to?(:blob) + + return content_type.split("/").last.upcase if respond_to?(:content_type) && content_type.present? + + "UNKNOWN" + rescue StandardError => e + Rails.logger.warn("[Attachment#file_type patch] #{e.class}: #{e.message}") + "UNKNOWN" + end +end diff --git a/config/application.rb b/config/application.rb index 40d45c3..bf20334 100644 --- a/config/application.rb +++ b/config/application.rb @@ -20,6 +20,10 @@ class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 6.1 + # Empêche Zeitwerk d'autoload le dossier decorators + config.autoload_paths -= Rails.root.glob("app/decorators") + config.eager_load_paths -= Rails.root.glob("app/decorators") + # Configuration for the application, engines, and railties goes here. # # These settings can be overridden in specific environments using the files @@ -33,5 +37,14 @@ class Application < Rails::Application require "extends/controllers/decidim/devise/omniauth_registrations_controller_extends" require "extends/controllers/decidim/errors_controller_extends" end + # --- FORCE LE CHARGEMENT DES DÉCORATEURS --- + # Chargement après initialisation complète de Rails + config.after_initialize do + decorators_path = Rails.root.join("app/decorators/**/*.rb") + Dir[decorators_path].each do |decorator| + Rails.logger.info "💡 Chargement manuel du décorateur : #{File.basename(decorator)}" + require decorator + end + end end end diff --git a/lib/tasks/decidim-app.rake b/lib/tasks/decidim_app.rake similarity index 100% rename from lib/tasks/decidim-app.rake rename to lib/tasks/decidim_app.rake