Sha256: e0500f75b9bfc645487b8ad0eb2d441dd583df86c48bb2c0fdb599940a0f71e3

Contents?: true

Size: 1.57 KB

Versions: 16

Compression:

Stored size: 1.57 KB

Contents

# See http://github.com/ryanb/cancan for more details on cancan.
require 'cancan'

module Gaku
  class Ability
    include CanCan::Ability

    class_attribute :abilities
    self.abilities = Set.new

    # Allows us to go beyond the standard cancan initialize method which
    # makes it difficult for engines to modify the default +Ability+ of an app.
    # The +ability+ argument must be a class that includes
    # the +CanCan::Ability+ module.  The registered ability should
    # behave properly as a stand-alone class and therefore should
    # be easy to test in isolation.
    def self.register_ability(ability)
      abilities.add ability
    end

    def self.remove_ability(ability)
      abilities.delete ability
    end

    def initialize(user)
      clear_aliased_actions

      # override cancan default aliasing
      # (we don't want to differentiate between read and index)
      alias_action :edit, to: :update
      alias_action :new,  to: :create
      alias_action :new_action, to: :create
      alias_action :show, to: :read

      user ||= User.new

      if user.role? :admin
        can :manage, :all
      else
        if user.role? :student
          can :index, Gaku::Student
        else
          can :manage, Gaku::Student
          can :manage, Gaku::Address
          can :manage, Gaku::Contact
          can :manage, Gaku::Note
        end
      end

      # include any abilities registered by extensions, etc.
      Ability.abilities.each do |clazz|
        ability = clazz.send(:new, user)
        @rules = rules + ability.send(:rules)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
gaku_core-0.3.0 app/models/gaku/ability.rb
gaku_core-0.3.0.pre.4 app/models/gaku/ability.rb
gaku_core-0.3.0.pre.3 app/models/gaku/ability.rb
gaku_core-0.3.0.pre.2 app/models/gaku/ability.rb
gaku_core-0.3.0.pre.1 app/models/gaku/ability.rb
gaku_core-0.3.0.pre.0 app/models/gaku/ability.rb
gaku-0.2.4 core/app/models/gaku/ability.rb
gaku_core-0.2.4 app/models/gaku/ability.rb
gaku-0.2.3 core/app/models/gaku/ability.rb
gaku_core-0.2.3 app/models/gaku/ability.rb
gaku-0.2.2 core/app/models/gaku/ability.rb
gaku_core-0.2.2 app/models/gaku/ability.rb
gaku-0.2.1 core/app/models/gaku/ability.rb
gaku_core-0.2.1 app/models/gaku/ability.rb
gaku-0.2.0 core/app/models/gaku/ability.rb
gaku_core-0.2.0 app/models/gaku/ability.rb