From 06b4991be3485a170e4f284c19409b376ca20645 Mon Sep 17 00:00:00 2001 From: Sean Date: Fri, 5 Apr 2019 17:13:40 -0500 Subject: [PATCH] Disabling adjust stock field when user does not have the correct permission --- .../assets/javascripts/spree/backend/stock_management.js | 9 +++++++++ .../spree/admin/stock_items/_stock_management.html.erb | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/app/assets/javascripts/spree/backend/stock_management.js b/backend/app/assets/javascripts/spree/backend/stock_management.js index 917d21dbb7d..60bc2996d1b 100644 --- a/backend/app/assets/javascripts/spree/backend/stock_management.js +++ b/backend/app/assets/javascripts/spree/backend/stock_management.js @@ -3,6 +3,7 @@ Spree.ready(function() { var $el = $(this); var model = new Spree.Models.StockItem($el.data('stock-item')); var trackInventory = $el.data('track-inventory'); + var canEdit = $el.data('can-edit') new Spree.Views.Stock.EditStockItemRow({ el: $el, stockLocationName: $el.data('stock-location-name'), @@ -16,6 +17,14 @@ Spree.ready(function() { title: '"Track inventory" option disabled for this variant' }); } + + if (canEdit == false) { + $('.js-edit-stock-item input').attr({ + disabled: true, + class: 'with-tip', + title: 'You do not have permission to manage stock' + }); + } }); $('.js-add-stock-item').each(function() { diff --git a/backend/app/views/spree/admin/stock_items/_stock_management.html.erb b/backend/app/views/spree/admin/stock_items/_stock_management.html.erb index c5d21f1c5f9..b358016b294 100644 --- a/backend/app/views/spree/admin/stock_items/_stock_management.html.erb +++ b/backend/app/views/spree/admin/stock_items/_stock_management.html.erb @@ -72,7 +72,7 @@ <% variant.stock_items.each do |item| %> <% if @stock_item_stock_locations.include?(item.stock_location) %> - + <%# This is rendered in JS %> <% end %>