From 32fdb4e7967d1f192a035fa31e790c92273b3a53 Mon Sep 17 00:00:00 2001 From: jazzari Date: Tue, 21 Nov 2023 15:45:42 +0100 Subject: [PATCH 1/2] fix: cambiado metodo blob_for para lanzar excepcion y disk_controller_decorator.rb para devolver not_found si no encuentra el blob #14378 --- app/controllers/active_storage/disk_controller_decorator.rb | 3 ++- app/lib/active_storage/service/jekyll_service.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/active_storage/disk_controller_decorator.rb b/app/controllers/active_storage/disk_controller_decorator.rb index 14366a15..aaaa9357 100644 --- a/app/controllers/active_storage/disk_controller_decorator.rb +++ b/app/controllers/active_storage/disk_controller_decorator.rb @@ -6,6 +6,7 @@ module ActiveStorage extend ActiveSupport::Concern included do + rescue_from ActiveRecord::RecordNotFound, with: :page_not_found # Asociar el archivo subido al sitio correspondiente. Cada sitio # tiene su propio servicio de subida de archivos. def update @@ -13,7 +14,7 @@ module ActiveStorage if acceptable_content?(token) named_disk_service(token[:service_name]).upload token[:key], request.body, checksum: token[:checksum] - blob = ActiveStorage::Blob.find_by_key token[:key] + blob = ActiveStorage::Blob.find_by! token[:key] site = Site.find_by_name token[:service_name] site.static_files.attach(blob) diff --git a/app/lib/active_storage/service/jekyll_service.rb b/app/lib/active_storage/service/jekyll_service.rb index e6c5fda6..b33ccf4d 100644 --- a/app/lib/active_storage/service/jekyll_service.rb +++ b/app/lib/active_storage/service/jekyll_service.rb @@ -96,7 +96,7 @@ module ActiveStorage end def blob_for(key) - ActiveStorage::Blob.find_by(key: key, service_name: name) + ActiveStorage::Blob.find_by!(key: key, service_name: name) end end end From c86507e62806e565890ae3746dd398bcafdefb7f Mon Sep 17 00:00:00 2001 From: jazzari Date: Wed, 22 Nov 2023 15:15:49 +0100 Subject: [PATCH 2/2] fix: agregado metodo page_not_found en disk_controller_decorator.rb #14378 --- .../active_storage/disk_controller_decorator.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/active_storage/disk_controller_decorator.rb b/app/controllers/active_storage/disk_controller_decorator.rb index aaaa9357..0ec76c28 100644 --- a/app/controllers/active_storage/disk_controller_decorator.rb +++ b/app/controllers/active_storage/disk_controller_decorator.rb @@ -14,7 +14,7 @@ module ActiveStorage if acceptable_content?(token) named_disk_service(token[:service_name]).upload token[:key], request.body, checksum: token[:checksum] - blob = ActiveStorage::Blob.find_by! token[:key] + blob = ActiveStorage::Blob.find_by_key! token[:key] site = Site.find_by_name token[:service_name] site.static_files.attach(blob) @@ -27,6 +27,12 @@ module ActiveStorage rescue ActiveStorage::IntegrityError head :unprocessable_entity end + + private + def page_not_found(exception) + head :not_found + ExceptionNotifier.notify_exception(exception, data: {params: params.to_hash}) + end end end end