Move the parameter wrapper code to the ActionController::Railtie class
This commit is contained in:
parent
1b0c914133
commit
4db42073cd
|
@ -12,6 +12,7 @@ module ActionController
|
|||
config.action_controller = ActiveSupport::OrderedOptions.new
|
||||
config.action_controller.raise_on_open_redirects = false
|
||||
config.action_controller.log_query_tags_around_actions = true
|
||||
config.action_controller.wrap_parameters_by_default = false
|
||||
|
||||
config.eager_load_namespaces << ActionController
|
||||
|
||||
|
@ -62,15 +63,18 @@ module ActionController
|
|||
extend ::AbstractController::Railties::RoutesHelpers.with(app.routes)
|
||||
extend ::ActionController::Railties::Helpers
|
||||
|
||||
wrap_parameters format: [:json] if options.wrap_parameters_by_default
|
||||
|
||||
# Configs used in other initializers
|
||||
options = options.except(
|
||||
filtered_options = options.except(
|
||||
:log_query_tags_around_actions,
|
||||
:permit_all_parameters,
|
||||
:action_on_unpermitted_parameters,
|
||||
:always_permitted_parameters
|
||||
:always_permitted_parameters,
|
||||
:wrap_parameters_by_default
|
||||
)
|
||||
|
||||
options.each do |k, v|
|
||||
filtered_options.each do |k, v|
|
||||
k = "#{k}="
|
||||
if respond_to?(k)
|
||||
send(k, v)
|
||||
|
|
|
@ -889,6 +889,11 @@ Raises an `ArgumentError` when an unpermitted open redirect occurs. The default
|
|||
Determines whether controller context for query tags will be automatically
|
||||
updated via an `around_filter`. The default value is `true`.
|
||||
|
||||
#### `config.action_controller.wrap_parameters_by_default`
|
||||
|
||||
Configures the [`ParamsWrapper`](https://api.rubyonrails.org/classes/ActionController/ParamsWrapper.html) to wrap json
|
||||
request by default.
|
||||
|
||||
#### `ActionController::Base.wrap_parameters`
|
||||
|
||||
Configures the [`ParamsWrapper`](https://api.rubyonrails.org/classes/ActionController/ParamsWrapper.html). This can be called at
|
||||
|
@ -1690,7 +1695,7 @@ Accepts a string for the HTML tag used to wrap attachments. Defaults to `"action
|
|||
- `config.active_storage.video_preview_arguments`: `"-vf 'select=eq(n\\,0)+eq(key\\,1)+gt(scene\\,0.015),loop=loop=-1:size=2,trim=start_frame=1' -frames:v 1 -f image2"`
|
||||
- `config.active_record.verify_foreign_keys_for_fixtures`: `true`
|
||||
- `config.active_storage.variant_processor`: `:vips`
|
||||
- `ActionController::Base.wrap_parameters`: `format: [:json]`
|
||||
- `config.action_controller.wrap_parameters_by_default`: `true`
|
||||
|
||||
#### For '6.1', defaults from previous versions below and:
|
||||
|
||||
|
@ -1773,6 +1778,7 @@ Accepts a string for the HTML tag used to wrap attachments. Defaults to `"action
|
|||
- `config.action_mailer.smtp_timeout`: `nil`
|
||||
- `config.active_storage.video_preview_arguments`: `"-y -vframes 1 -f image2"`
|
||||
- `config.active_storage.variant_processor`: `:mini_magick`
|
||||
- `config.action_controller.wrap_parameters_by_default`: `false`
|
||||
|
||||
### Configuring a Database
|
||||
|
||||
|
|
|
@ -238,11 +238,7 @@ module Rails
|
|||
if respond_to?(:action_controller)
|
||||
action_controller.raise_on_open_redirects = true
|
||||
|
||||
# This can't use the standard configuration pattern because you can call
|
||||
# wrap_parameters at the top level or on any controller.
|
||||
ActiveSupport.on_load(:action_controller) do
|
||||
ActionController::Base.wrap_parameters format: [:json]
|
||||
end
|
||||
action_controller.wrap_parameters_by_default = true
|
||||
end
|
||||
else
|
||||
raise "Unknown version #{target_version.to_s.inspect}"
|
||||
|
|
|
@ -86,5 +86,5 @@
|
|||
|
||||
# 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.
|
||||
# To disable parameter wrapping entirely, call `ActionController::Base.wrap_parameters false` in an initializer.
|
||||
# ActionController::Base.wrap_parameters format: [:json]
|
||||
# To disable parameter wrapping entirely, set this config to `false`.
|
||||
# Rails.application.config.action_controller.wrap_parameters_by_default = true
|
||||
|
|
|
@ -3415,7 +3415,7 @@ module ApplicationTests
|
|||
add_to_config 'config.load_defaults "6.1"'
|
||||
|
||||
app_file "config/initializers/new_framework_defaults_7_0.rb", <<-RUBY
|
||||
ActionController::Base.wrap_parameters format: [:json]
|
||||
Rails.application.config.action_controller.wrap_parameters_by_default = true
|
||||
RUBY
|
||||
|
||||
app "production"
|
||||
|
@ -3423,17 +3423,11 @@ module ApplicationTests
|
|||
assert_equal [:json], ActionController::Base._wrapper_options.format
|
||||
end
|
||||
|
||||
test "ParamsWrapper can be changed from the default" do
|
||||
add_to_config "ActionController::Base.wrap_parameters format: [:xml]"
|
||||
|
||||
app "production"
|
||||
|
||||
assert_equal [:xml], ActionController::Base._wrapper_options.format
|
||||
end
|
||||
|
||||
test "ParamsWrapper can be changed from the default in the initializer that was created prior to Rails 7" do
|
||||
app_file "config/initializers/wrap_parameters.rb", <<-RUBY
|
||||
ActionController::Base.wrap_parameters format: [:xml]
|
||||
ActiveSupport.on_load(:action_controller) do
|
||||
wrap_parameters format: [:xml]
|
||||
end
|
||||
RUBY
|
||||
|
||||
app "production"
|
||||
|
@ -3442,7 +3436,7 @@ module ApplicationTests
|
|||
end
|
||||
|
||||
test "ParamsWrapper can be turned off" do
|
||||
add_to_config "ActionController::Base.wrap_parameters false"
|
||||
add_to_config "Rails.application.config.action_controller.wrap_parameters_by_default = false"
|
||||
|
||||
app "production"
|
||||
|
||||
|
|
Loading…
Reference in New Issue