Sha256: fa74a5285a6727361041bf307e29d0adededadf9a82fe0a67af405c24313870e

Contents?: true

Size: 948 Bytes

Versions: 27

Compression:

Stored size: 948 Bytes

Contents

#module EnjuMessage
  class Ability
    include CanCan::Ability
      
    def initialize(user, ip_address = nil)
      case user.try(:role).try(:name)
      when 'Administrator'
        can :manage, Message
        can [:read, :update, :destroy, :delete], MessageRequest
        can [:read, :update], MessageTemplate
      when 'Librarian'
        can [:index, :create], Message
        can [:update], Message do |message|
          message.sender == user
        end
        can [:show, :destroy, :delete], Message do |message|
          message.receiver == user
        end
        can [:read, :update, [:destroy, :delete]], MessageRequest
        can :read, MessageTemplate
      when 'User'
        can [:read, :destroy, :delete], Message do |message|
          message.receiver == user
        end
        can :index, Message
        can :show, Message do |message|
          message.receiver == user
        end
      end
    end
  end
#end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
enju_message-0.2.0.beta.2 spec/dummy/app/models/ability.rb
enju_message-0.2.0.beta.1 spec/dummy/app/models/ability.rb
enju_message-0.1.16 spec/dummy/app/models/ability.rb
enju_message-0.1.15 spec/dummy/app/models/ability.rb
enju_message-0.1.14 spec/dummy/app/models/ability.rb
enju_message-0.1.14.pre26 spec/dummy/app/models/ability.rb
enju_message-0.1.14.pre25 spec/dummy/app/models/ability.rb
enju_message-0.1.14.pre24 spec/dummy/app/models/ability.rb
enju_message-0.1.14.pre23 spec/dummy/app/models/ability.rb
enju_message-0.1.14.pre22 spec/dummy/app/models/ability.rb
enju_message-0.1.14.pre21 spec/dummy/app/models/ability.rb
enju_message-0.1.14.pre20 spec/dummy/app/models/ability.rb
enju_message-0.1.14.pre19 spec/dummy/app/models/ability.rb
enju_message-0.1.14.pre18 spec/dummy/app/models/ability.rb
enju_message-0.1.14.pre17 spec/dummy/app/models/ability.rb
enju_message-0.1.14.pre16 spec/dummy/app/models/ability.rb
enju_message-0.1.14.pre15 spec/dummy/app/models/ability.rb
enju_message-0.1.14.pre14 spec/dummy/app/models/ability.rb
enju_message-0.1.14.pre13 spec/dummy/app/models/ability.rb
enju_message-0.1.14.pre12 spec/dummy/app/models/ability.rb