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 c2869deb3f..71ab6e6301 100644 --- a/app/views/admin/products_v3/_product_variant_row.html.haml +++ b/app/views/admin/products_v3/_product_variant_row.html.haml @@ -23,7 +23,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 7d2750a5a9..1f5fbf1ebe 100644 --- a/app/views/admin/products_v3/_table.html.haml +++ b/app/views/admin/products_v3/_table.html.haml @@ -27,13 +27,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" } @@ -65,7 +65,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 46bdc4ed47..3e245dda3d 100644 --- a/app/views/admin/products_v3/_variant_row.html.haml +++ b/app/views/admin/products_v3/_variant_row.html.haml @@ -79,7 +79,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/db/migrate/20251105020336_enable_variant_tags_for_new_enterprises.rb b/db/migrate/20251105020336_enable_variant_tags_for_new_enterprises.rb new file mode 100644 index 0000000000..7e67da339e --- /dev/null +++ b/db/migrate/20251105020336_enable_variant_tags_for_new_enterprises.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class EnableVariantTagsForNewEnterprises < ActiveRecord::Migration[7.1] + # rubocop:disable Naming/VariableNumber + def up + Flipper.enable_group(:variant_tag, :enterprise_created_after_2025_08_11) + end + + def down + Flipper.disable_group(:variant_tag, :enterprise_created_after_2025_08_11) + end + # rubocop:enable Naming/VariableNumber +end 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