Sha256: f82fc1668490652a4acfe77cbd531958022a31e3759bbd6be8e70b3caa904c4e

Contents?: true

Size: 944 Bytes

Versions: 20

Compression:

Stored size: 944 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

20 entries across 20 versions & 1 rubygems

Version Path
enju_message-0.1.14.pre24 app/models/enju_message/ability.rb
enju_message-0.1.14.pre23 app/models/enju_message/ability.rb
enju_message-0.1.14.pre22 app/models/enju_message/ability.rb
enju_message-0.1.14.pre21 app/models/enju_message/ability.rb
enju_message-0.1.14.pre20 app/models/enju_message/ability.rb
enju_message-0.1.14.pre19 app/models/enju_message/ability.rb
enju_message-0.1.14.pre18 app/models/enju_message/ability.rb
enju_message-0.1.14.pre17 app/models/enju_message/ability.rb
enju_message-0.1.14.pre16 app/models/enju_message/ability.rb
enju_message-0.1.14.pre15 app/models/enju_message/ability.rb
enju_message-0.1.14.pre14 app/models/enju_message/ability.rb
enju_message-0.1.14.pre13 app/models/enju_message/ability.rb
enju_message-0.1.14.pre12 app/models/enju_message/ability.rb
enju_message-0.1.14.pre11 app/models/enju_message/ability.rb
enju_message-0.1.14.pre10 app/models/enju_message/ability.rb
enju_message-0.1.14.pre9 app/models/enju_message/ability.rb
enju_message-0.1.14.pre8 app/models/enju_message/ability.rb
enju_message-0.1.14.pre7 app/models/enju_message/ability.rb
enju_message-0.1.14.pre6 app/models/enju_message/ability.rb
enju_message-0.1.14.pre5 app/models/enju_message/ability.rb