From 965e8ab8181947a97bef33695063d0b0fda7117b Mon Sep 17 00:00:00 2001 From: Rainer Dema Date: Thu, 14 Dec 2023 17:15:10 +0100 Subject: [PATCH] Introduce `enable_alpha_features?` config preference Using this config to conditionally disable orders and products routes, restricting them to only index actions unless the config is enabled. This setup was done to manage access to features still in development. --- admin/config/routes.rb | 16 +++++++++++----- admin/lib/solidus_admin/configuration.rb | 7 +++++++ admin/spec/features/order_spec.rb | 5 ++++- admin/spec/features/product_spec.rb | 5 ++++- admin/spec/features/products_spec.rb | 5 ++++- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/admin/config/routes.rb b/admin/config/routes.rb index 08457e6a7dc..49f13e99b67 100644 --- a/admin/config/routes.rb +++ b/admin/config/routes.rb @@ -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" diff --git a/admin/lib/solidus_admin/configuration.rb b/admin/lib/solidus_admin/configuration.rb index 1ac4ea6a6af..840c0898a30 100644 --- a/admin/lib/solidus_admin/configuration.rb +++ b/admin/lib/solidus_admin/configuration.rb @@ -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}" } } diff --git a/admin/spec/features/order_spec.rb b/admin/spec/features/order_spec.rb index 5c94831c190..7b8aebd5479 100644 --- a/admin/spec/features/order_spec.rb +++ b/admin/spec/features/order_spec.rb @@ -3,7 +3,10 @@ require 'spec_helper' describe "Order", :js, type: :feature do - before { sign_in create(:admin_user, email: 'admin@example.com') } + before do + allow(SolidusAdmin::Config).to receive(:enable_alpha_features?) { true } + sign_in create(:admin_user, email: 'admin@example.com') + end it "allows detaching a customer from an order" do order = create(:order, number: "R123456789", user: create(:user)) diff --git a/admin/spec/features/product_spec.rb b/admin/spec/features/product_spec.rb index 1e65811b63b..60b4d3ca617 100644 --- a/admin/spec/features/product_spec.rb +++ b/admin/spec/features/product_spec.rb @@ -3,7 +3,10 @@ require 'spec_helper' describe "Product", type: :feature do - before { sign_in create(:admin_user, email: 'admin@example.com') } + before do + allow(SolidusAdmin::Config).to receive(:enable_alpha_features?) { true } + sign_in create(:admin_user, email: 'admin@example.com') + end it "lists products", :js do create(:product, name: "Just a product", slug: 'just-a-prod', price: 19.99) diff --git a/admin/spec/features/products_spec.rb b/admin/spec/features/products_spec.rb index f450020428f..860780f7427 100644 --- a/admin/spec/features/products_spec.rb +++ b/admin/spec/features/products_spec.rb @@ -3,7 +3,10 @@ require 'spec_helper' describe "Products", type: :feature do - before { sign_in create(:admin_user, email: 'admin@example.com') } + before do + allow(SolidusAdmin::Config).to receive(:enable_alpha_features?) { true } + sign_in create(:admin_user, email: 'admin@example.com') + end it "lists products", :js do create(:product, name: "Just a product", slug: 'just-a-prod', price: 19.99)