Sha256: 5c7282c303f17fdce707d9c455c3feddb1229dc047dcf949c3716eb907a04188

Contents?: true

Size: 1.57 KB

Versions: 15

Compression:

Stored size: 1.57 KB

Contents

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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
enju_library-0.1.0.pre27 app/models/enju_library/ability.rb
enju_library-0.1.0.pre26 app/models/enju_library/ability.rb
enju_library-0.1.0.pre25 app/models/enju_library/ability.rb
enju_library-0.1.0.pre24 app/models/enju_library/ability.rb
enju_library-0.1.0.pre23 app/models/enju_library/ability.rb
enju_library-0.1.0.pre22 app/models/enju_library/ability.rb
enju_library-0.1.0.pre21 app/models/enju_library/ability.rb
enju_library-0.1.0.pre20 app/models/enju_library/ability.rb
enju_library-0.1.0.pre19 app/models/enju_library/ability.rb
enju_library-0.1.0.pre18 app/models/enju_library/ability.rb
enju_library-0.1.0.pre17 app/models/enju_library/ability.rb
enju_library-0.1.0.pre16 app/models/enju_library/ability.rb
enju_library-0.1.0.pre15 app/models/enju_library/ability.rb
enju_library-0.1.0.pre14 app/models/enju_library/ability.rb
enju_library-0.1.0.pre13 app/models/enju_library/ability.rb