From 0745028c06d739a79d5e8cb1ae24931d04a89468 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Wed, 5 Nov 2025 11:33:47 +1100 Subject: [PATCH] Fix checking if variant tag is enabled variant_tag feature check should happen per enterprise basis, but we still want super admin to so see variant tag. To do so we check if the user is amdin or if any of the current user enterprise has variant tag enable. --- app/helpers/admin/products_helper.rb | 6 ++++++ app/views/admin/products_v3/_filters.html.haml | 2 +- app/views/admin/products_v3/_product_row.html.haml | 2 +- app/views/admin/products_v3/_product_variant_row.html.haml | 2 +- app/views/admin/products_v3/_table.html.haml | 6 +++--- app/views/admin/products_v3/_variant_row.html.haml | 2 +- config/initializers/flipper.rb | 6 ++++++ lib/open_food_network/column_preference_defaults.rb | 3 ++- spec/views/admin/products_v3/_filters.html.haml_spec.rb | 2 ++ 9 files changed, 23 insertions(+), 8 deletions(-) diff --git a/app/helpers/admin/products_helper.rb b/app/helpers/admin/products_helper.rb index d7b8a2086f..90480e371f 100644 --- a/app/helpers/admin/products_helper.rb +++ b/app/helpers/admin/products_helper.rb @@ -41,5 +41,11 @@ module Admin def hide_producer_column?(producer_options) spree_current_user.column_preferences.bulk_edit_product.empty? && producer_options.one? end + + # check if the user is in the "admins" group or if it's enabled for any of + # the enterprises the user manages + def variant_tag_enabled?(user) + feature?(:variant_tag, user) || feature?(:variant_tag, *user.enterprises) + end end end diff --git a/app/views/admin/products_v3/_filters.html.haml b/app/views/admin/products_v3/_filters.html.haml index c2e0d5cf73..fc07b83b46 100644 --- a/app/views/admin/products_v3/_filters.html.haml +++ b/app/views/admin/products_v3/_filters.html.haml @@ -17,7 +17,7 @@ = select_tag :category_id, options_for_select(category_options, category_id), include_blank: t('.all_categories'), class: "fullwidth", data: { "controller": "tom-select", 'tom-select-placeholder-value': t('.search_for_categories')} - -if feature?(:variant_tag, spree_current_user) + -if variant_tag_enabled?(spree_current_user) .tags = label_tag :tags_name_in, t('.tags.label') - select_tag_options = { class: "fullwidth", diff --git a/app/views/admin/products_v3/_product_row.html.haml b/app/views/admin/products_v3/_product_row.html.haml index 0b47dd3dfe..b9a2fbf905 100644 --- a/app/views/admin/products_v3/_product_row.html.haml +++ b/app/views/admin/products_v3/_product_row.html.haml @@ -18,7 +18,7 @@ %td.col-category.align-left -# empty %td.col-tax_category.align-left -- if feature?(:variant_tag, spree_current_user) +- if variant_tag_enabled?(spree_current_user) %td.col-tags.align-left -# empty %td.col-inherits_properties.align-left diff --git a/app/views/admin/products_v3/_product_variant_row.html.haml b/app/views/admin/products_v3/_product_variant_row.html.haml index f49c756078..dd14f8a7d2 100644 --- a/app/views/admin/products_v3/_product_variant_row.html.haml +++ b/app/views/admin/products_v3/_product_variant_row.html.haml @@ -19,7 +19,7 @@ %tr{ 'data-nested-form-target': "target" } %tr.condensed %td - - colspan = feature?(:variant_tag, spree_current_user) ? 12 : 11 + - colspan = variant_tag_enabled?(spree_current_user) ? 12 : 11 %td{ colspan: "#{colspan}" } %button.secondary.condensed.naked.icon-plus{ 'data-action': "nested-form#add", 'aria-label': t('.new_variant') } diff --git a/app/views/admin/products_v3/_table.html.haml b/app/views/admin/products_v3/_table.html.haml index 003194a3fb..44aaa4d12a 100644 --- a/app/views/admin/products_v3/_table.html.haml +++ b/app/views/admin/products_v3/_table.html.haml @@ -26,13 +26,13 @@ %col.col-producer{ style:"min-width: 6em" }= # (grow to fill) %col.col-category{ width:"8%" } %col.col-tax_category{ width:"8%" } - - if feature?(:variant_tag, spree_current_user) + - if variant_tag_enabled?(spree_current_user) %col.col-tags{ width:"8%" } %col.col-inherits_properties{ width:"5%" } %col{ width:"5%", style:"min-width: 3em"}= # Actions %thead %tr - - colspan = feature?(:variant_tag, spree_current_user) ? 13 : 12 + - colspan = variant_tag_enabled?(spree_current_user) ? 13 : 12 %td.form-actions-wrapper{ colspan: "#{colspan}" } .form-actions-wrapper2 %fieldset.form-actions{ class: ("hidden" unless defined?(@error_counts)), 'data-bulk-form-target': "actions" } @@ -64,7 +64,7 @@ %th.align-left.col-producer= t('admin.products_page.columns.producer') %th.align-left.col-category= t('admin.products_page.columns.category') %th.align-left.col-tax_category= t('admin.products_page.columns.tax_category') - - if feature?(:variant_tag, spree_current_user) + - if variant_tag_enabled?(spree_current_user) %th.align-left.col-tags= t('admin.products_page.columns.tags') %th.align-left.col-inherits_properties= t('admin.products_page.columns.inherits_properties') %th.align-right= t('admin.products_page.columns.actions') diff --git a/app/views/admin/products_v3/_variant_row.html.haml b/app/views/admin/products_v3/_variant_row.html.haml index 9d8fbeb999..53af9be7f2 100644 --- a/app/views/admin/products_v3/_variant_row.html.haml +++ b/app/views/admin/products_v3/_variant_row.html.haml @@ -78,7 +78,7 @@ aria_label: t('.tax_category_field_name'), placeholder_value: t('.search_for_tax_categories'))) = error_message_on variant, :tax_category -- if feature?(:variant_tag, spree_current_user) +- if variant_tag_enabled?(spree_current_user) %td.col-tags.field.naked_inputs = render TagListInputComponent.new(name: f.field_name(:tag_list), tags: variant.tag_list, autocomplete_url: variant_tag_rules_admin_tag_rules_path(enterprise_id: variant.supplier_id), placeholder: t('.add_a_tag'), aria_label: t('admin.products_page.columns.tags')) %td.col-inherits_properties.align-left diff --git a/config/initializers/flipper.rb b/config/initializers/flipper.rb index fa67ffbdab..c660d993a9 100644 --- a/config/initializers/flipper.rb +++ b/config/initializers/flipper.rb @@ -31,6 +31,12 @@ Flipper.register(:enterprise_created_before_2025_08_11) do |actor| actor.respond_to?(:created_at?) && actor.created_at < "2025-08-11".to_time end +Flipper.register(:enterprise_created_after_2025_08_11) 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 + + actor.respond_to?(:created_at?) && actor.created_at >= "2025-08-11".to_time +end Flipper::UI.configure do |config| config.descriptions_source = ->(_keys) do diff --git a/lib/open_food_network/column_preference_defaults.rb b/lib/open_food_network/column_preference_defaults.rb index 9eca6be307..ae651ec171 100644 --- a/lib/open_food_network/column_preference_defaults.rb +++ b/lib/open_food_network/column_preference_defaults.rb @@ -93,7 +93,8 @@ module OpenFoodNetwork category: { name: t(:category), visible: true }, tax_category: { name: t(:tax_category), visible: true }, } - if OpenFoodNetwork::FeatureToggle.enabled?(:variant_tag, user) + if OpenFoodNetwork::FeatureToggle.enabled?(:variant_tag, user) || + OpenFoodNetwork::FeatureToggle.enabled?(:variant_tag, *user.enterprises) columns[:tags] = { name: t(:tags), visible: true } end diff --git a/spec/views/admin/products_v3/_filters.html.haml_spec.rb b/spec/views/admin/products_v3/_filters.html.haml_spec.rb index a43dc0ef9c..9c01add0ac 100644 --- a/spec/views/admin/products_v3/_filters.html.haml_spec.rb +++ b/spec/views/admin/products_v3/_filters.html.haml_spec.rb @@ -3,6 +3,8 @@ require "spec_helper" RSpec.describe "admin/products_v3/_filters.html.haml" do + helper Admin::ProductsHelper + subject { render } let(:locals) do