From 9967ba2d067a3a971a4a36ea81507c4afb16f397 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Fri, 12 Dec 2025 12:38:22 +1100 Subject: [PATCH 1/2] Allow managing inventory and variant tag at the same time For users with enterprise with inventory and enterpises with variant tag, allow access to the inventory page and display variant tag only for the enterprises its enabled for. --- app/models/product_import/product_importer.rb | 7 +------ app/views/admin/product_import/_upload_form.html.haml | 2 +- app/views/admin/product_import/_upload_sidebar.html.haml | 2 +- app/views/admin/products_v3/_variant_row.html.haml | 2 +- app/views/spree/admin/shared/_product_sub_menu.html.haml | 2 +- config/initializers/flipper.rb | 8 ++++---- 6 files changed, 9 insertions(+), 14 deletions(-) diff --git a/app/models/product_import/product_importer.rb b/app/models/product_import/product_importer.rb index 3f1185ee50..37e8031ecd 100644 --- a/app/models/product_import/product_importer.rb +++ b/app/models/product_import/product_importer.rb @@ -185,16 +185,11 @@ module ProductImport order('is_primary_producer ASC, name'). map { |e| @editable_enterprises[e.name] = e.id } - return unless inventory_enabled? + return unless OpenFoodNetwork::FeatureToggle.enabled?(:inventory, *@current_user.enterprises) @inventory_permissions = permissions.variant_override_enterprises_per_hub end - def inventory_enabled? - !OpenFoodNetwork::FeatureToggle.enabled?(:variant_tag, *@current_user.enterprises) && - OpenFoodNetwork::FeatureToggle.enabled?(:inventory, *@current_user.enterprises) - end - def open_spreadsheet if accepted_mimetype Roo::Spreadsheet.open(@file, extension: accepted_mimetype, encoding: Encoding::UTF_8) diff --git a/app/views/admin/product_import/_upload_form.html.haml b/app/views/admin/product_import/_upload_form.html.haml index c1cce83e18..a8a853f556 100644 --- a/app/views/admin/product_import/_upload_form.html.haml +++ b/app/views/admin/product_import/_upload_form.html.haml @@ -5,7 +5,7 @@ %h6= t('admin.product_import.index.choose_import_type') %br - options = { "#{t('admin.product_import.index.product_list')}" => :product_list } - - options = options.merge("#{t('admin.product_import.index.inventories')}" => :inventories) if inventory_enabled?(spree_current_user.enterprises) + - options = options.merge("#{t('admin.product_import.index.inventories')}" => :inventories) if feature?(:inventory, *spree_current_user.enterprises) = select_tag "settings[import_into]", options_for_select(options), { "data-controller": "tom-select", class: "primary inline no-search", "ng-model": "settings.import_into" } diff --git a/app/views/admin/product_import/_upload_sidebar.html.haml b/app/views/admin/product_import/_upload_sidebar.html.haml index d089c84497..fc0c22f7c4 100644 --- a/app/views/admin/product_import/_upload_sidebar.html.haml +++ b/app/views/admin/product_import/_upload_sidebar.html.haml @@ -5,7 +5,7 @@ %i.icon-external-link = t('admin.product_import.index.product_list_template') - - if inventory_enabled?(spree_current_user.enterprises) + - if feature?(:inventory, *spree_current_user.enterprises) %a.download{href: '/inventory_template.csv'} %i.icon-external-link = t('admin.product_import.index.inventory_template') diff --git a/app/views/admin/products_v3/_variant_row.html.haml b/app/views/admin/products_v3/_variant_row.html.haml index 3e245dda3d..02424a501f 100644 --- a/app/views/admin/products_v3/_variant_row.html.haml +++ b/app/views/admin/products_v3/_variant_row.html.haml @@ -81,7 +81,7 @@ = error_message_on variant, :tax_category - 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')) + = 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')) if feature?(:variant_tag, variant.supplier) %td.col-inherits_properties.align-left -# empty %td.align-right diff --git a/app/views/spree/admin/shared/_product_sub_menu.html.haml b/app/views/spree/admin/shared/_product_sub_menu.html.haml index 194825593c..c24f0da781 100644 --- a/app/views/spree/admin/shared/_product_sub_menu.html.haml +++ b/app/views/spree/admin/shared/_product_sub_menu.html.haml @@ -2,5 +2,5 @@ %ul#sub_nav.inline-menu = tab :products, :products_v3, url: admin_products_path = tab :properties - = tab :variant_overrides, url: main_app.admin_inventory_path, match_path: '/inventory' if inventory_enabled?(spree_current_user.enterprises) + = tab :variant_overrides, url: main_app.admin_inventory_path, match_path: '/inventory' if feature?(:inventory, *spree_current_user.enterprises) = tab :import, url: main_app.admin_product_import_path, match_path: '/product_import' diff --git a/config/initializers/flipper.rb b/config/initializers/flipper.rb index 0c6c82d624..e569c92859 100644 --- a/config/initializers/flipper.rb +++ b/config/initializers/flipper.rb @@ -44,7 +44,7 @@ Flipper.register(: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 - # Uses 2025-08-11 as filter because variant tag did not exist before that, enterprise created + # Uses 2025-08-11 as filter because variant tag did not exist before that, enterprise created # after never had access to the inventory enterprise_with_variant_override = Enterprise .where(id: VariantOverride.joins(:hub).select(:hub_id)) @@ -60,17 +60,17 @@ Flipper.register(:enterprise_with_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 - # Uses 2025-08-11 as filter because variant tag did not exist before that, enterprise created + # Uses 2025-08-11 as filter because variant tag did not exist before that, enterprise created # after never had access to the inventory enterprise_with_variant_override = Enterprise .where(id: VariantOverride.joins(:hub).select(:hub_id)) .where(created_at: ..."2025-08-11") .distinct - enterprise_with_variant_override.exists?(actor.id) + # Entperprise with inventory and with variant tag not manually enabled. + enterprise_with_variant_override.exists?(actor.id) && !Flipper.enabled?(:variant_tag, actor) end - Flipper::UI.configure do |config| config.descriptions_source = ->(_keys) do # return has to be hash of {String key => String description} From bcf4507795cde7dfec36633e2caf6f8e0eee9025 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Fri, 12 Dec 2025 13:04:44 +1100 Subject: [PATCH 2/2] Only show hub with inventory enabled --- app/controllers/admin/variant_overrides_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/admin/variant_overrides_controller.rb b/app/controllers/admin/variant_overrides_controller.rb index a437d9b368..a398e4f93c 100644 --- a/app/controllers/admin/variant_overrides_controller.rb +++ b/app/controllers/admin/variant_overrides_controller.rb @@ -44,6 +44,8 @@ module Admin def load_data @hubs = OpenFoodNetwork::Permissions.new(spree_current_user). variant_override_hubs.by_name + # Only display the ones with inventory enabled + @hubs = @hubs.select { |p| helpers.feature?(:inventory, p) } # Used in JS to look up the name of the producer of each product @producers = OpenFoodNetwork::Permissions.new(spree_current_user).