Sha256: 9715f9e87ca61c44488a71be7353808cdf8bc2681c72119874d969aef3c88862

Contents?: true

Size: 769 Bytes

Versions: 12

Compression:

Stored size: 769 Bytes

Contents

#module EnjuPurchaseRequest
  class Ability
    include CanCan::Ability
  
    def initialize(user, ip_address = nil)
      case user.try(:role).try(:name)
      when 'Administrator'
        can [:destroy, :delete], Bookstore do |bookstore|
          bookstore.order_lists.empty? and bookstore.items.empty?
        end
        can :manage, [
          Order,
          OrderList,
          PurchaseRequest
        ]
      when 'Librarian'
        can :manage, [
          Order,
          OrderList,
          PurchaseRequest
        ]
      when 'User'
        can [:index, :create], PurchaseRequest
        can [:show, :update, :destroy, :delete], PurchaseRequest do |purchase_request|
          purchase_request.user == user
        end
      end
    end
  end
#end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
enju_purchase_request-0.1.1 spec/dummy/app/models/ability.rb
enju_purchase_request-0.1.0 spec/dummy/app/models/ability.rb
enju_purchase_request-0.1.0.pre15 spec/dummy/app/models/ability.rb
enju_purchase_request-0.1.0.pre14 spec/dummy/app/models/ability.rb
enju_purchase_request-0.1.0.pre13 spec/dummy/app/models/ability.rb
enju_purchase_request-0.1.0.pre12 spec/dummy/app/models/ability.rb
enju_purchase_request-0.1.0.pre11 spec/dummy/app/models/ability.rb
enju_purchase_request-0.1.0.pre10 spec/dummy/app/models/ability.rb
enju_purchase_request-0.1.0.pre9 spec/dummy/app/models/ability.rb
enju_purchase_request-0.1.0.pre8 spec/dummy/app/models/ability.rb
enju_purchase_request-0.1.0.pre7 spec/dummy/app/models/ability.rb
enju_purchase_request-0.1.0.pre6 spec/dummy/app/models/ability.rb