diff --git a/core/app/models/spree/ability.rb b/core/app/models/spree/ability.rb index f7de6d15479..f1fb428fec9 100644 --- a/core/app/models/spree/ability.rb +++ b/core/app/models/spree/ability.rb @@ -51,6 +51,8 @@ def model_adapter(model_class, action) private def normalize_args(action, *other_args) + return [action, *other_args] unless Spree::Config.use_custom_cancancan_actions + if action == :read Spree::Deprecation.warn <<~WARN The behavior of CanCanCan `:read` action alias will be changing in Solidus 3.0. diff --git a/core/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt b/core/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt index f8c9dc8aad5..ca2d1f792f1 100644 --- a/core/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +++ b/core/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt @@ -28,6 +28,9 @@ Spree.config do |config| config.image_attachment_module = 'Spree::Image::PaperclipAttachment' config.taxon_attachment_module = 'Spree::Taxon::PaperclipAttachment' + # Disable legacy Solidus custom CanCanCan actions aliases + config.use_custom_cancancan_actions = false + # Defaults # Set this configuration to `true` to raise an exception when diff --git a/core/lib/spree/app_configuration.rb b/core/lib/spree/app_configuration.rb index ba5a000de96..63ddfc47706 100644 --- a/core/lib/spree/app_configuration.rb +++ b/core/lib/spree/app_configuration.rb @@ -156,6 +156,10 @@ class AppConfiguration < Preferences::Configuration # @return [String] Two-letter ISO code of a {Spree::Country} to assumed as the country of an unidentified customer (default: "US") preference :default_country_iso, :string, default: 'US' + # @!attribute [rw] use_custom_cancancan_actions + # @return [Boolean] Allow to use legacy Solidus custom CanCanCan action aliases (default: +true+) + preference :use_custom_cancancan_actions, :boolean, default: true + # @!attribute [rw] generate_api_key_for_all_roles # @return [Boolean] Allow generating api key automatically for user # at role_user creation for all roles. (default: +false+) diff --git a/core/lib/spree/testing_support/dummy_app.rb b/core/lib/spree/testing_support/dummy_app.rb index 6c11f7a188e..b2b1c167fa3 100644 --- a/core/lib/spree/testing_support/dummy_app.rb +++ b/core/lib/spree/testing_support/dummy_app.rb @@ -121,6 +121,7 @@ class Application < ::Rails::Application config.run_order_validations_on_order_updater = true config.use_combined_first_and_last_name_in_address = true config.use_legacy_order_state_machine = false + config.use_custom_cancancan_actions = false if ENV['ENABLE_ACTIVE_STORAGE'] config.image_attachment_module = 'Spree::Image::ActiveStorageAttachment' diff --git a/core/spec/models/spree/ability_spec.rb b/core/spec/models/spree/ability_spec.rb index 016bc4ec899..90a79759e8b 100644 --- a/core/spec/models/spree/ability_spec.rb +++ b/core/spec/models/spree/ability_spec.rb @@ -281,6 +281,8 @@ def initialize(_user) describe 'legacy aliases deprecation' do before do + allow(Spree::Config).to receive(:use_custom_cancancan_actions) + .and_return(true) allow(Spree::Deprecation).to receive(:warn) end