From 5a471b6d8f73b15f6fd864a4d9f863f416144a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Thu, 13 May 2021 14:14:24 -0400 Subject: [PATCH] Keep process_action private when redefined AbstractController::Base defines process_action as private, but modules included after redefine it as a public method. --- .../lib/abstract_controller/callbacks.rb | 17 +++--- .../metal/instrumentation.rb | 54 +++++++++---------- .../action_controller/metal/params_wrapper.rb | 14 ++--- .../lib/action_controller/metal/rendering.rb | 12 ++--- 4 files changed, 49 insertions(+), 48 deletions(-) diff --git a/actionpack/lib/abstract_controller/callbacks.rb b/actionpack/lib/abstract_controller/callbacks.rb index 3084886ec5..3da475d5a8 100644 --- a/actionpack/lib/abstract_controller/callbacks.rb +++ b/actionpack/lib/abstract_controller/callbacks.rb @@ -35,14 +35,6 @@ module AbstractController skip_after_callbacks_if_terminated: true end - # Override AbstractController::Base#process_action to run the - # process_action callbacks around the normal behavior. - def process_action(*) - run_callbacks(:process_action) do - super - end - end - module ClassMethods # If +:only+ or +:except+ are used, convert the options into the # +:if+ and +:unless+ options of ActiveSupport::Callbacks. @@ -220,5 +212,14 @@ module AbstractController alias_method :"append_#{callback}_action", :"#{callback}_action" end end + + private + # Override AbstractController::Base#process_action to run the + # process_action callbacks around the normal behavior. + def process_action(*) + run_callbacks(:process_action) do + super + end + end end end diff --git a/actionpack/lib/action_controller/metal/instrumentation.rb b/actionpack/lib/action_controller/metal/instrumentation.rb index 62e0c351fc..a009a796fd 100644 --- a/actionpack/lib/action_controller/metal/instrumentation.rb +++ b/actionpack/lib/action_controller/metal/instrumentation.rb @@ -16,33 +16,6 @@ module ActionController attr_internal :view_runtime - def process_action(*) - raw_payload = { - controller: self.class.name, - action: action_name, - request: request, - params: request.filtered_parameters, - headers: request.headers, - format: request.format.ref, - method: request.request_method, - path: request.fullpath - } - - ActiveSupport::Notifications.instrument("start_processing.action_controller", raw_payload) - - ActiveSupport::Notifications.instrument("process_action.action_controller", raw_payload) do |payload| - result = super - payload[:response] = response - payload[:status] = response.status - result - rescue => error - payload[:status] = ActionDispatch::ExceptionWrapper.status_code_for_exception(error.class.name) - raise - ensure - append_info_to_payload(payload) - end - end - def render(*) render_output = nil self.view_runtime = cleanup_view_runtime do @@ -74,6 +47,33 @@ module ActionController end private + def process_action(*) + raw_payload = { + controller: self.class.name, + action: action_name, + request: request, + params: request.filtered_parameters, + headers: request.headers, + format: request.format.ref, + method: request.request_method, + path: request.fullpath + } + + ActiveSupport::Notifications.instrument("start_processing.action_controller", raw_payload) + + ActiveSupport::Notifications.instrument("process_action.action_controller", raw_payload) do |payload| + result = super + payload[:response] = response + payload[:status] = response.status + result + rescue => error + payload[:status] = ActionDispatch::ExceptionWrapper.status_code_for_exception(error.class.name) + raise + ensure + append_info_to_payload(payload) + end + end + # A hook invoked every time a before callback is halted. def halted_callback_hook(filter, _) ActiveSupport::Notifications.instrument("halted_callback.action_controller", filter: filter) diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index 5724c5ea40..349edde0d7 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -242,14 +242,14 @@ module ActionController end end - # Performs parameters wrapping upon the request. Called automatically - # by the metal call stack. - def process_action(*) - _perform_parameter_wrapping if _wrapper_enabled? - super - end - private + # Performs parameters wrapping upon the request. Called automatically + # by the metal call stack. + def process_action(*) + _perform_parameter_wrapping if _wrapper_enabled? + super + end + # Returns the wrapper key which will be used to store wrapped parameters. def _wrapper_key _wrapper_options.name diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb index 5d65a11b48..28c70832fc 100644 --- a/actionpack/lib/action_controller/metal/rendering.rb +++ b/actionpack/lib/action_controller/metal/rendering.rb @@ -24,12 +24,6 @@ module ActionController end end - # Before processing, set the request formats in current controller formats. - def process_action(*) #:nodoc: - self.formats = request.formats.filter_map(&:ref) - super - end - # Check for double render errors and set the content_type after rendering. def render(*args) #:nodoc: raise ::AbstractController::DoubleRenderError if response_body @@ -53,6 +47,12 @@ module ActionController end private + # Before processing, set the request formats in current controller formats. + def process_action(*) #:nodoc: + self.formats = request.formats.filter_map(&:ref) + super + end + def _process_variant(options) if defined?(request) && !request.nil? && request.variant.present? options[:variant] = request.variant