Sha256: feb0130f59bca991676c114a3a785cb61c25987e124b00c7fe422c5b74aef21b

Contents?: true

Size: 886 Bytes

Versions: 30

Compression:

Stored size: 886 Bytes

Contents

class Ability
  include CanCan::Ability

  def initialize(user)
    case user.try(:role).try(:name)
    when 'Administrator'
      can :manage, [
        Bookmark,
        BookmarkStat,
        BookmarkStatHasManifestation,
        Tag
      ]
    when 'Librarian'
      can [:read, :create, :update], BookmarkStat
      can :read, BookmarkStatHasManifestation
      can :manage, [
        Bookmark,
        Tag
      ]
    when 'User'
      can [:index, :create], Bookmark
      can :show, Bookmark do |bookmark|
        if bookmark.user == user
          true
        elsif user.share_bookmarks
          true
        else
          false
        end
      end
      can [:update, :destroy], Bookmark do |bookmark|
        bookmark.user == user
      end
      can :read, BookmarkStat
      can :read, Tag
    else
      can :read, BookmarkStat
      can :read, Tag
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
enju_bookmark-0.1.2.pre7 spec/dummy/app/models/ability.rb
enju_bookmark-0.1.2.pre6 spec/dummy/app/models/ability.rb
enju_bookmark-0.1.2.pre5 spec/dummy/app/models/ability.rb
enju_bookmark-0.1.2.pre4 spec/dummy/app/models/ability.rb
enju_bookmark-0.1.2.pre3 spec/dummy/app/models/ability.rb
enju_bookmark-0.1.2.pre2 spec/dummy/app/models/ability.rb
enju_bookmark-0.1.2.pre spec/dummy/app/models/ability.rb
enju_bookmark-0.1.1 spec/dummy/app/models/ability.rb
enju_bookmark-0.1.0.pre spec/dummy/app/models/ability.rb
enju_bookmark-0.1.0 spec/dummy/app/models/ability.rb
enju_bookmark-0.0.22 spec/dummy/app/models/ability.rb
enju_bookmark-0.0.21 spec/dummy/app/models/ability.rb
enju_bookmark-0.0.20 spec/dummy/app/models/ability.rb
enju_bookmark-0.0.19 spec/dummy/app/models/ability.rb
enju_bookmark-0.0.18 spec/dummy/app/models/ability.rb
enju_bookmark-0.0.17 spec/dummy/app/models/ability.rb
enju_bookmark-0.0.16 spec/dummy/app/models/ability.rb
enju_bookmark-0.0.15 spec/dummy/app/models/ability.rb
enju_bookmark-0.0.14 spec/dummy/app/models/ability.rb
enju_bookmark-0.0.13 spec/dummy/app/models/ability.rb