Class: WishlistAbility

Inherits:
Object
  • Object
show all
Includes:
CanCan::Ability
Defined in:
lib/wishlist_ability.rb

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ WishlistAbility

Returns a new instance of WishlistAbility.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/wishlist_ability.rb', line 7

def initialize(user)
  # Anyone can create a wishlist
  can :index, Spree::Wishlist do
    !user.new_record?
  end

  can :create, Spree::Wishlist
  # You can your own wishlists, and everyone cas see public ones
  can :read, Spree::Wishlist do |wishlist|
    wishlist.user == user || wishlist.is_public?
  end
  # You can only change your own wishlist
  can [:read, :move, :update, :edit, :destroy], Spree::Wishlist do |wishlist|
    wishlist.user == user
  end

  can :create, Spree::WishedProduct do |wished_product|
    !user.new_record?
  end

  can :read, Spree::WishedProduct do |wished_product|
    wished_product.wishlist.user == user || wished_product.wishlist.is_public?
  end
  can [:index, :update, :destroy], Spree::WishedProduct do |wished_product|
    wished_product.wishlist.user == user
  end
end