Skip to content

Instantly share code, notes, and snippets.

@stabenfeldt
Created February 9, 2016 18:33
Show Gist options
  • Save stabenfeldt/220eeb8dd8d403d0ba52 to your computer and use it in GitHub Desktop.
Save stabenfeldt/220eeb8dd8d403d0ba52 to your computer and use it in GitHub Desktop.
module Spree
class MultiVendorAbility
include CanCan::Ability
def initialize(user)
user ||= Spree::User.new # guest user (not logged in)
if user.admin?
can :manage, :all
puts "IS admin"
else
can :read, :all
puts "NOT admin"
end
can :manage, Spree::StockItem, :stock_location_id => user.stock_locations.present? && user.stock_locations.first.id
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment