Created
December 30, 2015 12:52
-
-
Save stabenfeldt/60e5909a79cec0cfddc7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Spree | |
module PermissionSets | |
# A user should only have access to items belonging to the stock locations he belongs to. | |
# He should only see activity belonging to his items. | |
# E.g. Stock managment and orders | |
# | |
# Users can be associated with stock locations via the admin user interface. | |
# | |
# @see Spree::PermissionSets::Base | |
# | |
# https://github.com/CanCanCommunity/cancancan/wiki/defining-abilities | |
class MultiVendor < PermissionSets::Base | |
def activate! | |
puts "\n\n\n MULTI VENDOR \n\n\n" | |
cannot :view, Spree::StockItem | |
#if user_location_ids.include(Spree::StockItem.variant.stock_location_ids) | |
# can :view, Spree::StockItem | |
#end | |
end | |
private | |
def user_location_ids | |
@user_location_ids ||= user.stock_locations.pluck(:id) | |
end | |
def not_permitted_location_ids | |
@not_permitted_location_ids ||= Spree::StockLocation.where.not(id: user_location_ids).pluck(:id) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment