Sha256: 7e45dfb8f00b754a8895cbf837c50041fbb12a27f23ff3757e498737cb9d32db

Contents?: true

Size: 1.59 KB

Versions: 20

Compression:

Stored size: 1.59 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? and !shelf.web_shelf?
        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

20 entries across 20 versions & 1 rubygems

Version Path
enju_library-0.1.2 spec/dummy/app/models/ability.rb
enju_library-0.1.1 spec/dummy/app/models/ability.rb
enju_library-0.1.0 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre45 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre44 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre43 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre42 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre41 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre40 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre39 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre38 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre37 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre36 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre35 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre34 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre33 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre32 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre31 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre30 spec/dummy/app/models/ability.rb
enju_library-0.1.0.pre29 spec/dummy/app/models/ability.rb