Sha256: 22f94e6ad43009d4404ada444ff5b7b1634ffda09933dcf3df9e246212a433c5

Contents?: true

Size: 1.45 KB

Versions: 6

Compression:

Stored size: 1.45 KB

Contents

class Ability
  include CanCan::Ability

  def initialize(user, ip_address = nil)
    case user.try(:role).try(:name)
    when 'Administrator'
      can :manage, Accept
      can [:read, :create, :update], Bookstore
      can :manage, BudgetType
      can :destroy, Bookstore do |bookstore|
        if defined?(EnjuPurchaseRequest)
          bookstore.order_lists.empty? and bookstore.items.empty?
        else
          bookstore.items.empty?
        end
      end
      can [:read, :create, :update], Library
      can :destroy, Library do |library|
        library.shelves.empty? and !library.web?
      end
      can [:read, :update], LibraryGroup
      can [:read, :update], RequestStatusType
      can [:read, :update], RequestType
      can [:read, :create, :update], Shelf
      can :destroy, Shelf do |shelf|
        shelf.items.empty?
      end
      can :manage, SearchEngine
      can :manage, Subscribe
      can :manage, Subscription
    when 'Librarian'
      can :manage, Accept
      can :read, Bookstore
      can :read, BudgetType
      can :read, Library
      can :read, LibraryGroup
      can :read, RequestStatusType
      can :read, RequestType
      can :read, Shelf
      can :read, SearchEngine
      can :manage, Subscribe
      can :manage, Subscription
    when 'User'
      can :read, Shelf
      can :read, Library
      can :read, LibraryGroup
    else
      can :read, Library
      can :read, LibraryGroup
      can :read, Shelf
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
enju_library-0.1.0.pre12 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre11 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre10 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre9 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre8 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre7 spec/dummy/app/models/ability.rb