mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-11 18:26:50 +00:00
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.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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" }
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user