mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #12030 from mkllnk/connected-apps-visibility
Show Connected Apps only to enterprise managers
This commit is contained in:
@@ -21,7 +21,8 @@ module Admin
|
||||
show_payment_methods = can?(:manage_payment_methods, enterprise) && is_shop
|
||||
show_enterprise_fees = can?(:manage_enterprise_fees,
|
||||
enterprise) && (is_shop || enterprise.is_primary_producer)
|
||||
show_connected_apps = feature?(:connected_apps, spree_current_user, enterprise)
|
||||
show_connected_apps = can?(:manage_connected_apps, enterprise) &&
|
||||
feature?(:connected_apps, spree_current_user, enterprise)
|
||||
|
||||
build_enterprise_side_menu_items(
|
||||
is_shop:,
|
||||
|
||||
@@ -147,7 +147,8 @@ module Spree
|
||||
end
|
||||
can [:manage_payment_methods,
|
||||
:manage_shipping_methods,
|
||||
:manage_enterprise_fees], Enterprise do |enterprise|
|
||||
:manage_enterprise_fees,
|
||||
:manage_connected_apps], Enterprise do |enterprise|
|
||||
user.enterprises.include? enterprise
|
||||
end
|
||||
|
||||
|
||||
35
spec/helpers/admin/enterprises_helper_spec.rb
Normal file
35
spec/helpers/admin/enterprises_helper_spec.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "spec_helper"
|
||||
|
||||
describe Admin::EnterprisesHelper, type: :helper do
|
||||
let(:user) { build(:user) }
|
||||
|
||||
before do
|
||||
# Enable helper to use `#can?` method.
|
||||
# We could extract this when other helper specs need it.
|
||||
allow_any_instance_of(CanCan::ControllerAdditions).to receive(:current_ability) do
|
||||
Spree::Ability.new(user)
|
||||
end
|
||||
allow(helper).to receive(:spree_current_user) { user }
|
||||
end
|
||||
|
||||
describe "#enterprise_side_menu_items" do
|
||||
let(:enterprise) { build(:enterprise) }
|
||||
let(:menu_items) { helper.enterprise_side_menu_items(enterprise) }
|
||||
let(:visible_items) { menu_items.select { |i| i[:show] } }
|
||||
|
||||
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 users white_label
|
||||
]
|
||||
end
|
||||
|
||||
it "lists enabled features when allowed", feature: :connected_apps do
|
||||
user.enterprises << enterprise
|
||||
expect(visible_items.pluck(:name)).to include "connected_apps"
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user