Skip to content

Commit

Permalink
Add a preference to drive CanCanCan standard actions adoption
Browse files Browse the repository at this point in the history
  • Loading branch information
filippoliverani committed Aug 21, 2020
1 parent 21889db commit d114b81
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/app/models/spree/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions core/lib/spree/app_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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+)
Expand Down
1 change: 1 addition & 0 deletions core/lib/spree/testing_support/dummy_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions core/spec/models/spree/ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d114b81

Please sign in to comment.