Add feature toggle for DFC dev platform

This commit is contained in:
Maikel Linke
2025-07-03 14:40:03 +10:00
parent 52aeec5ac4
commit f65e4797cf
6 changed files with 31 additions and 6 deletions

View File

@@ -26,8 +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) &&
Spree::Config.connected_apps_enabled.present?
(connected_apps_enabled(enterprise).present? ||
dfc_platforms_available?)
show_inventory_settings = feature?(:inventory, spree_current_user.enterprises) && is_shop
show_options = {
@@ -42,11 +42,19 @@ module Admin
build_enterprise_side_menu_items(is_shop:, show_options:)
end
def connected_apps_enabled
def connected_apps_enabled(enterprise)
return [] unless feature?(:connected_apps, spree_current_user, enterprise)
connected_apps_enabled = Spree::Config.connected_apps_enabled&.split(',') || []
ConnectedApp::TYPES & connected_apps_enabled
end
def dfc_platforms_available?
DfcProvider::PlatformsController::PLATFORM_IDS.keys.any? do |id|
feature?(id)
end
end
def enterprise_attachment_removal_modal_id
attachment_removal_parameter # remove_logo|remove_promo_image|remove_white_label_logo
end

View File

@@ -1,5 +1,5 @@
- connected_apps_enabled.each do |type|
- connected_apps_enabled(enterprise).each do |type|
= render partial: "/admin/enterprises/form/connected_apps/#{type}",
locals: { enterprise:, connected_app: enterprise.connected_apps.public_send(type).first }
= render partial: "/admin/enterprises/form/dfc_permissions"
= render partial: "/admin/enterprises/form/dfc_permissions" if dfc_platforms_available?

View File

@@ -63,5 +63,10 @@ module DfcProvider
def import
DfcIo.import(request.body)
end
# Checks weather a feature is enabled for any of the given actors.
def feature?(feature, *actors)
OpenFoodNetwork::FeatureToggle.enabled?(feature, *actors)
end
end
end

View File

@@ -57,7 +57,7 @@ module DfcProvider
def platforms
id = DfcProvider::Engine.routes.url_helpers.enterprise_platforms_url(current_enterprise.id)
platforms = PLATFORM_IDS.keys.map(&method(:platform))
platforms = available_platforms.map(&method(:platform))
{
'@context': "https://cdn.startinblox.com/owl/context-bis.jsonld",
@@ -69,6 +69,10 @@ module DfcProvider
}
end
def available_platforms
PLATFORM_IDS.keys.select(&method(:feature?))
end
def platform(key)
{
'@type': "dfc-t:Platform",

View File

@@ -64,6 +64,9 @@ module OpenFoodNetwork
"hub_address" => <<~DESC,
Show the hub's address as shipping address on pickup orders.
DESC
"cqcm-dev" => <<~DESC,
Show DFC Permissions interface to share data with CQCM dev platform.
DESC
}.merge(conditional_features).freeze;
# Features you would like to be enabled to start with.

View File

@@ -38,5 +38,10 @@ RSpec.describe Admin::EnterprisesHelper do
expect(visible_items.pluck(:name)).to include "inventory_settings"
end
end
it "hides Connected Apps by default" do
user.enterprises << enterprise
expect(visible_items.pluck(:name)).not_to include "connected_apps"
end
end
end