Only show connected apps in enterprise settings, if system setting is enabled

This commit is contained in:
David Cook
2024-08-01 11:17:46 +10:00
committed by Rachel Arnould
parent 8716b75d3d
commit fcea437d7e
4 changed files with 28 additions and 2 deletions

View File

@@ -26,7 +26,8 @@ module Admin
show_enterprise_fees = can?(:manage_enterprise_fees,
enterprise) && (is_shop || enterprise.is_primary_producer)
show_connected_apps = can?(:manage_connected_apps, enterprise) &&
feature?(:connected_apps, spree_current_user, enterprise)
feature?(:connected_apps, spree_current_user, enterprise) &&
Spree::Config.connected_apps_enabled.present?
build_enterprise_side_menu_items(
is_shop:,

View File

@@ -139,5 +139,8 @@ module Spree
# Available units
preference :available_units, :string, default: "g,kg,T,mL,L,kL"
# Connected Apps
preference :connected_apps_enabled, :string, default: nil
end
end

View File

@@ -28,6 +28,8 @@ RSpec.describe Admin::EnterprisesHelper, type: :helper do
end
it "lists enabled features when allowed", feature: :connected_apps do
allow(Spree::Config).to receive(:connected_apps_enabled).and_return "discover_regen"
user.enterprises << enterprise
expect(visible_items.pluck(:name)).to include "connected_apps"
end

View File

@@ -9,7 +9,10 @@ RSpec.describe "Connected Apps", feature: :connected_apps, vcr: true do
login_as enterprise.owner
end
it "is only visible when enabled" do
it "is only visible when feature is enabled" do
allow(Spree::Config).to receive(:connected_apps_enabled).
and_return("discover_regen,affiliate_sales_data")
# Assuming that this feature will be the default one day, I'm treating this
# as special case and disable the feature. I don't want to wrap all other
# test cases in a context block for the feature toggle which will need
@@ -28,7 +31,21 @@ RSpec.describe "Connected Apps", feature: :connected_apps, vcr: true do
expect(page).to have_content "CONNECTED APPS"
end
it "is only visible when setting is enabled" do
allow(Spree::Config).to receive(:connected_apps_enabled).and_return(nil)
visit edit_admin_enterprise_path(enterprise)
expect(page).not_to have_content "CONNECTED APPS"
allow(Spree::Config).to receive(:connected_apps_enabled).
and_return("discover_regen,affiliate_sales_data")
visit edit_admin_enterprise_path(enterprise)
expect(page).to have_content "CONNECTED APPS"
end
describe "Discover Regenerative" do
before do
allow(Spree::Config).to receive(:connected_apps_enabled).and_return("discover_regen")
end
let(:section_heading) { self.class.description }
it "can be enabled and disabled" do
@@ -76,6 +93,9 @@ RSpec.describe "Connected Apps", feature: :connected_apps, vcr: true do
end
describe "Affiliate Sales Data" do
before do
allow(Spree::Config).to receive(:connected_apps_enabled).and_return("affiliate_sales_data")
end
let(:section_heading) { "INRAE / UFC QUE CHOISIR Research" }
it "can be enabled and disabled" do