Class: Spree::PermissionSets::RestrictedStockTransferManagement
- Defined in:
- lib/spree/permission_sets/restricted_stock_transfer_management.rb
Overview
This is a permission set that offers an alternative to StockManagement.
Instead of allowing management access for all stock transfers and items, only allow the management of stock transfers for locations the user is associated with.
Users can be associated with stock locations via the admin user interface.
The logic here is unfortunately rather complex and boils down to:
-
A user has read only access to all stock locations (including inactive ones)
-
A user can see all stock transfers for their associated stock locations regardless of the fact that they may not be associated with both the destination and the source, as long as they are associated with at least one of the two.
-
A user can manage stock transfers only if they are associated with both the destination and the source, or if the user is associated with the source, and the transfer has not yet been assigned a destination.
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Spree::PermissionSets::Base
Instance Method Details
#activate! ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/spree/permission_sets/restricted_stock_transfer_management.rb', line 20 def activate! if user.stock_locations.any? can :display, Spree::StockLocation, id: user_location_ids can :transfer_from, Spree::StockLocation, id: user_location_ids can :transfer_to, Spree::StockLocation, id: user_location_ids can :display, Spree::StockTransfer, source_location_id: user_location_ids can :manage, Spree::StockTransfer, source_location_id: user_location_ids + [nil], shipped_at: nil can :manage, Spree::StockTransfer, destination_location_id: user_location_ids # Do not allow managing transfers to a permitted destination_location_id from an # unauthorized stock location until it's been shipped to the permitted location. cannot :manage, Spree::StockTransfer, source_location_id: not_permitted_location_ids, shipped_at: nil can :display, Spree::TransferItem, stock_transfer: { source_location_id: user_location_ids } can :manage, Spree::TransferItem, stock_transfer: { source_location_id: user_location_ids + [nil], shipped_at: nil } can :manage, Spree::TransferItem, stock_transfer: { destination_location_id: user_location_ids } cannot :manage, Spree::TransferItem, stock_transfer: { source_location_id: not_permitted_location_ids, shipped_at: nil } end end |