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

Use runtime configuration for admin_path #290

Merged
merged 1 commit into from
Nov 27, 2023
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
2 changes: 1 addition & 1 deletion app/views/spree/admin/shared/_version.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% if can?(:admin, current_store) && Spree::Backend::Config[:admin_show_version] %>
<% if can?(:admin, current_store) && Spree::Backend::RuntimeConfig[:admin_show_version] %>
<p
class="spree-version ml-3 my-3"
aria-label="Spree Commerce version">
Expand Down
2 changes: 0 additions & 2 deletions lib/spree/backend/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
module Spree
module Backend
class Configuration < Preferences::Configuration
preference :admin_path, :string, default: '/admin'
preference :admin_products_per_page, :integer, default: Kaminari.config.default_per_page
preference :admin_orders_per_page, :integer, default: Kaminari.config.default_per_page
preference :admin_properties_per_page, :integer, default: Kaminari.config.default_per_page
preference :admin_promotions_per_page, :integer, default: Kaminari.config.default_per_page
preference :admin_customer_returns_per_page, :integer, default: Kaminari.config.default_per_page
preference :admin_users_per_page, :integer, default: Kaminari.config.default_per_page
preference :admin_show_version, :boolean, default: true
preference :locale, :string
preference :variants_per_page, :integer, default: Kaminari.config.default_per_page
preference :menus_per_page, :integer, default: Kaminari.config.default_per_page
Expand Down
2 changes: 2 additions & 0 deletions lib/spree/backend/engine.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require_relative 'configuration'
require_relative 'runtime_configuration'

module Spree
module Backend
Expand All @@ -9,6 +10,7 @@ class Engine < ::Rails::Engine

initializer 'spree.backend.environment', before: :load_config_initializers do |app|
Spree::Backend::Config = Spree::Backend::Configuration.new
Spree::Backend::RuntimeConfig = Spree::Backend::RuntimeConfiguration.new
app.config.spree_backend = Environment.new
end

Expand Down
8 changes: 8 additions & 0 deletions lib/spree/backend/runtime_configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Spree
module Backend
class RuntimeConfiguration < ::Spree::Preferences::RuntimeConfiguration
preference :admin_path, :string, default: '/admin'
preference :admin_show_version, :boolean, default: true
end
end
end
4 changes: 2 additions & 2 deletions lib/spree_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Spree
def self.admin_path
Spree::Backend::Config[:admin_path]
Spree::Backend::RuntimeConfig[:admin_path]
end

# Used to configure admin_path for Spree
Expand All @@ -13,6 +13,6 @@ def self.admin_path
# Spree.admin_path = '/custom-path'

def self.admin_path=(path)
Spree::Backend::Config[:admin_path] = path
Spree::Backend::RuntimeConfig[:admin_path] = path
end
end
2 changes: 1 addition & 1 deletion spec/features/admin/homepage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
end

context 'if turned off' do
before { Spree::Backend::Config[:admin_show_version] = false }
before { Spree::Backend::RuntimeConfig[:admin_show_version] = false }

it 'is not displayed' do
visit spree.admin_path
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/spree/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe Spree do
describe '.admin_path' do
it { expect(described_class.admin_path).to eq(Spree::Backend::Config[:admin_path]) }
it { expect(described_class.admin_path).to eq(Spree::Backend::RuntimeConfig[:admin_path]) }
end

describe '.admin_path=' do
Expand All @@ -18,6 +18,6 @@
end

it { expect(described_class.admin_path).to eq(new_admin_path) }
it { expect(Spree::Backend::Config[:admin_path]).to eq(new_admin_path) }
it { expect(Spree::Backend::RuntimeConfig[:admin_path]).to eq(new_admin_path) }
end
end
Loading