Skip to content

Commit

Permalink
Merge pull request solidusio#5549 from nebulab/rainerd/admin/introduc…
Browse files Browse the repository at this point in the history
…e-enable-alpha-features-config

[Admin] Implement `enable_alpha_features?` preference config for selective feature access
  • Loading branch information
elia committed Dec 15, 2023
2 parents 6820333 + 965e8ab commit 6d60e18
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
16 changes: 11 additions & 5 deletions admin/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@
get 'states', to: 'countries#states'
end

# Needs a constraint to avoid interpreting "new" as a product's slug
admin_resources :products, only: [
:index, :show, :edit, :update, :destroy
], constraints: ->{ _1.path != "/admin/products/new" } do
admin_resources :products, only: [:index, :update, :destroy] do
collection do
put :discontinue
put :activate
end
end

admin_resources :orders, except: [:destroy] do
# Needs a constraint to avoid interpreting "new" as a product's slug
admin_resources :products, only: [
:show, :edit
], constraints: ->{ SolidusAdmin::Config.enable_alpha_features? && _1.path != "/admin/products/new" }

admin_resources :orders, only: [:index]

admin_resources :orders, except: [
:destroy, :index
], constraints: ->{ SolidusAdmin::Config.enable_alpha_features? } do
resources :line_items, only: [:destroy, :create, :update]
resource :customer
resource :ship_address, only: [:show, :edit, :update], controller: "addresses", type: "ship"
Expand Down
7 changes: 7 additions & 0 deletions admin/lib/solidus_admin/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ class Configuration < Spree::Preferences::Configuration
# Default: 10
preference :low_stock_value, :integer, default: 10

# @!attribute [rw] enable_alpha_features?
# @return [Boolean] Determines whether alpha features are enabled or disabled in the application.
# Setting this to `true` enables access to alpha stage features that might still be in testing or development.
# Use with caution, as these features may not be fully stable or complete.
# Default: false
preference :enable_alpha_features?, :boolean, default: false

preference :storefront_product_path_proc, :proc, default: ->(_version) {
->(product) { "/products/#{product.slug}" }
}
Expand Down
5 changes: 4 additions & 1 deletion admin/spec/features/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
require 'spec_helper'

describe "Order", :js, type: :feature do
before { sign_in create(:admin_user, email: '[email protected]') }
before do
allow(SolidusAdmin::Config).to receive(:enable_alpha_features?) { true }
sign_in create(:admin_user, email: '[email protected]')
end

it "allows detaching a customer from an order" do
order = create(:order, number: "R123456789", user: create(:user))
Expand Down
5 changes: 4 additions & 1 deletion admin/spec/features/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
require 'spec_helper'

describe "Product", type: :feature do
before { sign_in create(:admin_user, email: '[email protected]') }
before do
allow(SolidusAdmin::Config).to receive(:enable_alpha_features?) { true }
sign_in create(:admin_user, email: '[email protected]')
end

it "lists products", :js do
create(:product, name: "Just a product", slug: 'just-a-prod', price: 19.99)
Expand Down
5 changes: 4 additions & 1 deletion admin/spec/features/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
require 'spec_helper'

describe "Products", type: :feature do
before { sign_in create(:admin_user, email: '[email protected]') }
before do
allow(SolidusAdmin::Config).to receive(:enable_alpha_features?) { true }
sign_in create(:admin_user, email: '[email protected]')
end

it "lists products", :js do
create(:product, name: "Just a product", slug: 'just-a-prod', price: 19.99)
Expand Down

0 comments on commit 6d60e18

Please sign in to comment.