Sha256: 98a1fcb56314f189c43ba276c5623222103bb67e604d2f0fad0d1fc2f6dc29bf

Contents?: true

Size: 1.03 KB

Versions: 33

Compression:

Stored size: 1.03 KB

Contents

module Ddr::Auth
  # @abstract
  class AbstractAbility
    include CanCan::Ability

    class_attribute :ability_definitions
    self.ability_definitions = []

    # CanCan default aliases:
    #
    #   alias_action :index, :show, :to => :read
    #   alias_action :new, :to => :create
    #   alias_action :edit, :to => :update
    #
    class_attribute :exclude_default_aliases
    self.exclude_default_aliases = false

    attr_reader :auth_context

    delegate :anonymous?, :authenticated?, :metadata_manager?,
             :user, :groups, :agents, :member_of?,
             :authorized_to_act_as_superuser?,
             to: :auth_context

    def initialize(auth_context)
      @auth_context = auth_context
      if exclude_default_aliases
        clear_aliased_actions
      end
      apply_ability_definitions
    end

    def cache
      @cache ||= {}
    end

    private

    def apply_ability_definitions
      ability_definitions.reduce(self, :apply)
    end

    def apply(ability_def)
      ability_def.call(self)
    end

  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
ddr-models-2.11.0 lib/ddr/auth/abstract_ability.rb
ddr-models-2.10.2 lib/ddr/auth/abstract_ability.rb
ddr-models-2.10.1 lib/ddr/auth/abstract_ability.rb
ddr-models-2.10.0 lib/ddr/auth/abstract_ability.rb
ddr-models-2.10.0.rc2 lib/ddr/auth/abstract_ability.rb
ddr-models-2.10.0.rc1 lib/ddr/auth/abstract_ability.rb
ddr-models-2.9.2 lib/ddr/auth/abstract_ability.rb
ddr-models-2.9.1 lib/ddr/auth/abstract_ability.rb
ddr-models-2.9.0 lib/ddr/auth/abstract_ability.rb
ddr-models-2.9.0.rc1 lib/ddr/auth/abstract_ability.rb
ddr-models-2.8.0 lib/ddr/auth/abstract_ability.rb
ddr-models-2.8.0.rc1 lib/ddr/auth/abstract_ability.rb
ddr-models-2.7.6 lib/ddr/auth/abstract_ability.rb
ddr-models-2.7.5 lib/ddr/auth/abstract_ability.rb
ddr-models-2.7.4 lib/ddr/auth/abstract_ability.rb
ddr-models-2.7.3 lib/ddr/auth/abstract_ability.rb
ddr-models-2.7.2 lib/ddr/auth/abstract_ability.rb
ddr-models-2.7.1 lib/ddr/auth/abstract_ability.rb
ddr-models-2.7.0 lib/ddr/auth/abstract_ability.rb
ddr-models-2.7.0.rc1 lib/ddr/auth/abstract_ability.rb