Skip to content

Commit c92e13a

Browse files
Add a preference to drive CanCanCan standard actions adoption
1 parent c25c417 commit c92e13a

File tree

5 files changed

+12
-0
lines changed

5 files changed

+12
-0
lines changed

core/app/models/spree/ability.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ def model_adapter(model_class, action)
5151
private
5252

5353
def normalize_action(action)
54+
return action unless Spree::Config.use_custom_cancancan_actions
55+
5456
if action == :read
5557
Spree::Deprecation.warn <<~WARN
5658
The behavior of CanCanCan `:read` action alias will be changing in Solidus 3.0.

core/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ Spree.config do |config|
2828
config.image_attachment_module = 'Spree::Image::PaperclipAttachment'
2929
config.taxon_attachment_module = 'Spree::Taxon::PaperclipAttachment'
3030

31+
# Disable legacy Solidus custom CanCanCan actions aliases
32+
config.use_custom_cancancan_actions = false
33+
3134
# Defaults
3235

3336
# Set this configuration to `true` to raise an exception when

core/lib/spree/app_configuration.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ class AppConfiguration < Preferences::Configuration
156156
# @return [String] Two-letter ISO code of a {Spree::Country} to assumed as the country of an unidentified customer (default: "US")
157157
preference :default_country_iso, :string, default: 'US'
158158

159+
# @!attribute [rw] use_custom_cancancan_actions
160+
# @return [Boolean] Allow to use legacy Solidus custom CanCanCan action aliases (default: +true+)
161+
preference :use_custom_cancancan_actions, :boolean, default: true
162+
159163
# @!attribute [rw] generate_api_key_for_all_roles
160164
# @return [Boolean] Allow generating api key automatically for user
161165
# at role_user creation for all roles. (default: +false+)

core/lib/spree/testing_support/dummy_app.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class Application < ::Rails::Application
121121
config.run_order_validations_on_order_updater = true
122122
config.use_combined_first_and_last_name_in_address = true
123123
config.use_legacy_order_state_machine = false
124+
config.use_custom_cancancan_actions = false
124125

125126
if ENV['ENABLE_ACTIVE_STORAGE']
126127
config.image_attachment_module = 'Spree::Image::ActiveStorageAttachment'

core/spec/models/spree/ability_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ def initialize(_user)
281281

282282
describe 'legacy aliases deprecation' do
283283
before do
284+
allow(Spree::Config).to receive(:use_custom_cancancan_actions)
285+
.and_return(true)
284286
allow(Spree::Deprecation).to receive(:warn)
285287
end
286288

0 commit comments

Comments
 (0)