On enterprise edit page, do not show side menu links we don't have permission to

This commit is contained in:
Rohan Mitchell
2015-01-15 12:39:16 +11:00
parent 83754a01ef
commit dcc04ea538
5 changed files with 39 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
angular.module("admin.enterprises")
.controller "sideMenuCtrl", ($scope, $parse, Enterprise, SideMenu) ->
.controller "sideMenuCtrl", ($scope, $parse, Enterprise, SideMenu, enterprisePermissions) ->
$scope.Enterprise = Enterprise.enterprise
$scope.menu = SideMenu
$scope.select = SideMenu.select
@@ -12,10 +12,10 @@ angular.module("admin.enterprises")
{ name: 'About', icon_class: "icon-pencil" }
{ name: 'Business Details', icon_class: "icon-briefcase" }
{ name: 'Images', icon_class: "icon-picture" }
{ name: "Shipping Methods", icon_class: "icon-truck", show: "showExtraPrefs()" }
{ name: "Payment Methods", icon_class: "icon-money", show: "showExtraPrefs()" }
{ name: "Shipping Methods", icon_class: "icon-truck", show: "showShippingMethods()" }
{ name: "Payment Methods", icon_class: "icon-money", show: "showPaymentMethods()" }
{ name: "Enterprise Fees", icon_class: "icon-tasks", show: "showEnterpriseFees()" }
{ name: "Shop Preferences", icon_class: "icon-shopping-cart", show: "showExtraPrefs()" }
{ name: "Shop Preferences", icon_class: "icon-shopping-cart", show: "showShopPreferences()" }
]
$scope.select(0)
@@ -27,8 +27,15 @@ angular.module("admin.enterprises")
else
true
$scope.showExtraPrefs = ->
$scope.Enterprise.sells != "none"
$scope.showShippingMethods = ->
enterprisePermissions.can_manage_shipping_methods && $scope.Enterprise.sells != "none"
$scope.showPaymentMethods = ->
enterprisePermissions.can_manage_payment_methods && $scope.Enterprise.sells != "none"
$scope.showEnterpriseFees = ->
$scope.Enterprise.sells != "none" || $scope.Enterprise.is_primary_producer
enterprisePermissions.can_manage_enterprise_fees && ($scope.Enterprise.sells != "none" || $scope.Enterprise.is_primary_producer)
$scope.showShopPreferences = ->
$scope.Enterprise.sells != "none"

View File

@@ -33,6 +33,15 @@ module Admin
admin_inject_json_ams_array "ofn.admin", "producers", @producers, Api::Admin::IdNameSerializer
end
def admin_inject_enterprise_permissions
permissions =
{can_manage_shipping_methods: can?(:manage_shipping_methods, @enterprise),
can_manage_payment_methods: can?(:manage_payment_methods, @enterprise),
can_manage_enterprise_fees: can?(:manage_enterprise_fees, @enterprise)}
render partial: "admin/json/injection_ams", locals: {ngModule: "admin.enterprises", name: "enterprisePermissions", json: permissions.to_json}
end
def admin_inject_hub_permissions
render partial: "admin/json/injection_ams", locals: {ngModule: "ofn.admin", name: "hubPermissions", json: @hub_permissions.to_json}
end

View File

@@ -1,4 +1,5 @@
= admin_inject_enterprise
= admin_inject_taxons
= admin_inject_payment_methods
= admin_inject_shipping_methods
= admin_inject_shipping_methods
= admin_inject_enterprise_permissions

View File

@@ -442,11 +442,22 @@ feature %q{
distributor3.reload.name.should == 'Eaterprises'
end
it "does not show links to manage payment methods, shipping methods or enterprise fees" do
it "does not show links to manage shipping methods, payment methods or enterprise fees" do
click_link 'Enterprises'
within("#listing_enterprises tr.enterprise-#{distributor3.id}") do
page.should_not have_link 'Payment Methods'
page.should_not have_link 'Shipping Methods'
page.should_not have_link 'Payment Methods'
page.should_not have_link 'Enterprise Fees'
end
end
it "does not show links to manage shipping methods, payment methods or enterprise fees on the edit page", js: true do
click_link 'Enterprises'
within("#listing_enterprises tr.enterprise-#{distributor3.id}") { click_link 'Edit Profile' }
within(".side_menu") do
page.should_not have_link 'Shipping Methods'
page.should_not have_link 'Payment Methods'
page.should_not have_link 'Enterprise Fees'
end
end

View File

@@ -20,7 +20,7 @@ describe "menuCtrl", ->
SideMenu = _SideMenu_
spyOn(SideMenu, "select").andCallThrough()
spyOn(SideMenu, "setItems").andCallThrough()
ctrl = $controller 'sideMenuCtrl', {$scope: scope, Enterprise: Enterprise, SideMenu: SideMenu}
ctrl = $controller 'sideMenuCtrl', {$scope: scope, Enterprise: Enterprise, SideMenu: SideMenu, enterprisePermissions: {}}
describe "initialisation", ->
it "stores enterprise", ->