mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Disable link to inventory related settings for enterprise
Metrics/CyclomaticComplexity is disabled on `enterprise_side_menu_items` because even though there is a lot of branching it's still readable
This commit is contained in:
@@ -18,7 +18,7 @@ module Admin
|
||||
enterprise.in?(spree_current_user.enterprises)
|
||||
end
|
||||
|
||||
def enterprise_side_menu_items(enterprise)
|
||||
def enterprise_side_menu_items(enterprise) # rubocop:disable Metrics/CyclomaticComplexity
|
||||
is_shop = enterprise.sells != "none"
|
||||
show_properties = !!enterprise.is_primary_producer
|
||||
show_shipping_methods = can?(:manage_shipping_methods, enterprise) && is_shop
|
||||
@@ -28,15 +28,18 @@ module Admin
|
||||
show_connected_apps = can?(:manage_connected_apps, enterprise) &&
|
||||
feature?(:connected_apps, spree_current_user, enterprise) &&
|
||||
Spree::Config.connected_apps_enabled.present?
|
||||
show_inventory_settings = feature?(:inventory, spree_current_user.enterprises) && is_shop
|
||||
|
||||
build_enterprise_side_menu_items(
|
||||
is_shop:,
|
||||
show_options = {
|
||||
show_properties:,
|
||||
show_shipping_methods:,
|
||||
show_payment_methods:,
|
||||
show_enterprise_fees:,
|
||||
show_connected_apps:,
|
||||
)
|
||||
show_inventory_settings:,
|
||||
}
|
||||
|
||||
build_enterprise_side_menu_items(is_shop:, show_options:)
|
||||
end
|
||||
|
||||
def connected_apps_enabled
|
||||
@@ -62,14 +65,7 @@ module Admin
|
||||
|
||||
private
|
||||
|
||||
def build_enterprise_side_menu_items(
|
||||
is_shop:,
|
||||
show_properties:,
|
||||
show_shipping_methods:,
|
||||
show_payment_methods:,
|
||||
show_enterprise_fees:,
|
||||
show_connected_apps:
|
||||
)
|
||||
def build_enterprise_side_menu_items(is_shop:, show_options: ) # rubocop:disable Metrics/MethodLength
|
||||
[
|
||||
{ name: 'primary_details', icon_class: "icon-home", show: true, selected: 'selected' },
|
||||
{ name: 'address', icon_class: "icon-map-marker", show: true },
|
||||
@@ -78,19 +74,24 @@ module Admin
|
||||
{ name: 'about', icon_class: "icon-pencil", show: true, form_name: "about_us" },
|
||||
{ name: 'business_details', icon_class: "icon-briefcase", show: true },
|
||||
{ name: 'images', icon_class: "icon-picture", show: true },
|
||||
{ name: 'properties', icon_class: "icon-tags", show: show_properties },
|
||||
{ name: 'shipping_methods', icon_class: "icon-truck", show: show_shipping_methods },
|
||||
{ name: 'payment_methods', icon_class: "icon-money", show: show_payment_methods },
|
||||
{ name: 'enterprise_fees', icon_class: "icon-tasks", show: show_enterprise_fees },
|
||||
{ name: 'properties', icon_class: "icon-tags", show: show_options[:show_properties] },
|
||||
{ name: 'shipping_methods', icon_class: "icon-truck",
|
||||
show: show_options[:show_shipping_methods] },
|
||||
{ name: 'payment_methods', icon_class: "icon-money",
|
||||
show: show_options[:show_payment_methods] },
|
||||
{ name: 'enterprise_fees', icon_class: "icon-tasks",
|
||||
show: show_options[:show_enterprise_fees] },
|
||||
{ name: 'vouchers', icon_class: "icon-ticket", show: is_shop },
|
||||
{ name: 'enterprise_permissions', icon_class: "icon-plug", show: true,
|
||||
href: admin_enterprise_relationships_path },
|
||||
{ name: 'inventory_settings', icon_class: "icon-list-ol", show: is_shop },
|
||||
{ name: 'inventory_settings', icon_class: "icon-list-ol",
|
||||
show: show_options[:show_inventory_settings] },
|
||||
{ name: 'tag_rules', icon_class: "icon-random", show: is_shop },
|
||||
{ name: 'shop_preferences', icon_class: "icon-shopping-cart", show: is_shop },
|
||||
{ name: 'white_label', icon_class: "icon-leaf", show: true },
|
||||
{ name: 'users', icon_class: "icon-user", show: true },
|
||||
{ name: 'connected_apps', icon_class: "icon-puzzle-piece", show: show_connected_apps },
|
||||
{ name: 'connected_apps', icon_class: "icon-puzzle-piece",
|
||||
show: show_options[:show_connected_apps] },
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,8 +22,7 @@ RSpec.describe Admin::EnterprisesHelper do
|
||||
it "lists default items" do
|
||||
expect(visible_items.pluck(:name)).to eq %w[
|
||||
primary_details address contact social about business_details images
|
||||
vouchers enterprise_permissions inventory_settings tag_rules
|
||||
shop_preferences white_label users
|
||||
vouchers enterprise_permissions tag_rules shop_preferences white_label users
|
||||
]
|
||||
end
|
||||
|
||||
@@ -33,5 +32,11 @@ RSpec.describe Admin::EnterprisesHelper do
|
||||
user.enterprises << enterprise
|
||||
expect(visible_items.pluck(:name)).to include "connected_apps"
|
||||
end
|
||||
|
||||
context "with inventory enabled", feature: :inventory do
|
||||
it "lists inventory_settings" do
|
||||
expect(visible_items.pluck(:name)).to include "inventory_settings"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user