Class: Spree::PermissionSets::RestrictedTransferManagement

Inherits:
Base
  • Object
show all
Defined in:
app/models/spree/permission_sets/restricted_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.

See Also:

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Spree::PermissionSets::Base

Instance Method Details

#activate!Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/spree/permission_sets/restricted_transfer_management.rb', line 12

def activate!
  can [:display, :admin], Spree::StockItem
  can [:display, :admin], Spree::StockTransfer

  if user.stock_locations.any?
    can :transfer, Spree::StockLocation, id: location_ids
    can :update, Spree::StockItem, stock_location_id: location_ids
    can :manage, Spree::StockTransfer, source_location_id: location_ids, destination_location_id: location_ids
    can :manage, Spree::TransferItem, stock_transfer: {
      source_location_id: location_ids,
      destination_location_id: location_ids
    }
  end
end