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

Allow stock transfer permissions to view stock transfers to/from from viewable stock locations. #504

Merged
merged 1 commit into from
Nov 19, 2015
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
18 changes: 5 additions & 13 deletions backend/app/controllers/spree/admin/stock_transfers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class StockTransfersController < ResourceController
{ translation_key: :name, attr_name: :name }
]

before_filter :load_transferable_stock_locations, only: :index
before_filter :load_viewable_stock_locations, only: :index
before_filter :load_variant_display_attributes, only: [:receive, :edit, :show, :tracking_info]
before_filter :load_source_stock_locations, only: :new
before_filter :load_destination_stock_locations, only: :edit
Expand Down Expand Up @@ -100,16 +100,16 @@ def authorize_transfer_attributes!
authorize! :create, duplicate
end

def load_transferable_stock_locations
@stock_locations = accessible_source_stock_locations | accessible_destination_stock_locations
def load_viewable_stock_locations
@stock_locations = Spree::StockLocation.accessible_by(current_ability, :read)
end

def load_source_stock_locations
@source_stock_locations = accessible_source_stock_locations
@source_stock_locations ||= Spree::StockLocation.accessible_by(current_ability, :transfer_from)
end

def load_destination_stock_locations
@destination_stock_locations = accessible_destination_stock_locations.where.not(id: @stock_transfer.source_location_id)
@destination_stock_locations ||= Spree::StockLocation.accessible_by(current_ability, :transfer_to).where.not(id: @stock_transfer.source_location_id)
end

def load_variant_display_attributes
Expand Down Expand Up @@ -142,14 +142,6 @@ def adjust_inventory
@stock_transfer.destination_location.move(transfer_item.variant, transfer_item.received_quantity, @stock_transfer)
end
end

def accessible_source_stock_locations
@source_locations ||= Spree::StockLocation.accessible_by(current_ability, :transfer_from)
end

def accessible_destination_stock_locations
@destination_locations ||= Spree::StockLocation.accessible_by(current_ability, :transfer_to)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ module Spree

before do
ability.cannot :manage, Spree::StockLocation
ability.can :transfer_from, Spree::StockLocation, id: [warehouse.id]
ability.can :transfer_to, Spree::StockLocation, id: [ny_store.id, la_store.id]
ability.can :display, Spree::StockLocation, id: [warehouse.id]
ability.can :display, Spree::StockLocation, id: [ny_store.id, la_store.id]

allow_any_instance_of(Spree::Admin::BaseController).to receive(:spree_current_user).and_return(user)
allow_any_instance_of(Spree::Admin::BaseController).to receive(:current_ability).and_return(ability)
Expand Down