From 7d20eb4fea5012219fa0cdc7832f42a66071414b Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Thu, 13 Nov 2025 09:31:14 +1100 Subject: [PATCH] Add group to enable variant tag for old enterprise It will allow enterprises with inventory enabled but which are not using the inventory to have variant tag enable. --- config/initializers/flipper.rb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/config/initializers/flipper.rb b/config/initializers/flipper.rb index c660d993a9..d4aa27141f 100644 --- a/config/initializers/flipper.rb +++ b/config/initializers/flipper.rb @@ -38,6 +38,24 @@ Flipper.register(:enterprise_created_after_2025_08_11) do |actor| actor.respond_to?(:created_at?) && actor.created_at >= "2025-08-11".to_time end +# This is group is to be used to turn on variant tags for enterprises with inventory enabled but +# are not using it +Flipper.register(:old_enterprise_with_no_inventory) do |actor| + # This group applies to enterprises only, so we return false if the actor is not an Enterprise + next false unless actor.actor.instance_of? Enterprise + + enterprise_with_variant_override = Enterprise + .where(id: VariantOverride.joins(:hub).select(:hub_id)) + .where("created_at < ?", "2025-08-11") + .distinct + enterprise_with_no_variant_override = Enterprise + .where.not(id: enterprise_with_variant_override) + .where("created_at < ?", "2025-08-11") + .pluck(:id) + + enterprise_with_no_variant_override.include?(actor.id) +end + Flipper::UI.configure do |config| config.descriptions_source = ->(_keys) do # return has to be hash of {String key => String description} @@ -59,4 +77,8 @@ Flipper::UI.configure do |config| end # Add known feature toggles. This may fail if the database isn't setup yet. -OpenFoodNetwork::FeatureToggle.setup! rescue ActiveRecord::StatementInvalid +begin + OpenFoodNetwork::FeatureToggle.setup! +rescue StandardError + ActiveRecord::StatementInvalid +end