Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Admin] Implement enable_alpha_features? preference config for selective feature access #5549

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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