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 |
# 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 [:admin, :create], Spree::StockTransfer can :display, Spree::StockTransfer, source_location_id: source_location_ids can :display, Spree::StockTransfer, destination_location_id: destination_location_ids can :manage, Spree::StockTransfer, source_location_id: source_location_ids, destination_location_id: destination_location_ids_with_undefined_destination can :transfer_from, Spree::StockLocation, id: source_location_ids can :transfer_to, Spree::StockLocation, id: destination_location_ids can :manage, Spree::TransferItem, stock_transfer: { source_location_id: source_location_ids, destination_location_id: destination_location_ids_with_undefined_destination } end end |