Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable adjust stock field when user does not have the correct permission #3163

Merged
merged 1 commit into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</colgroup>
<% variant.stock_items.each do |item| %>
<% if @stock_item_stock_locations.include?(item.stock_location) %>
<tr class="js-edit-stock-item stock-item-edit-row" data-variant-id="<%= variant.id %>" data-stock-item="<%= item.to_json %>" data-stock-location-name="<%= item.stock_location.name %>" data-track-inventory="<%= variant.should_track_inventory? %>">
<tr class="js-edit-stock-item stock-item-edit-row" data-variant-id="<%= variant.id %>" data-stock-item="<%= item.to_json %>" data-stock-location-name="<%= item.stock_location.name %>" data-track-inventory="<%= variant.should_track_inventory? %>" data-can-edit="<%= can?(:admin, Spree::StockItem) %>">
<%# This is rendered in JS %>
</tr>
<% end %>
Expand Down