Merge pull request #13680 from rioug/13674-enable-variant-tag-new-enterprise

[Variant tags] Enable variant tag for enterprise created after 11th of August and super admins
This commit is contained in:
Filipe
2025-11-17 23:05:11 +00:00
committed by GitHub
10 changed files with 36 additions and 8 deletions

View File

@@ -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

View File

@@ -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",

View File

@@ -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

View File

@@ -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') }

View File

@@ -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')

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -3,6 +3,8 @@
require "spec_helper"
RSpec.describe "admin/products_v3/_filters.html.haml" do
helper Admin::ProductsHelper
subject { render }
let(:locals) do