Sha256: 764ef8e62f65ef2692841e7ff22362c7abc9d4f56ecdc5a563f2d5fe992edca2

Contents?: true

Size: 910 Bytes

Versions: 18

Compression:

Stored size: 910 Bytes

Contents

module ThecoreAuthCommonsCanCanCanConcern
  extend ActiveSupport::Concern

  included do
    def initialize(user)
      # This will always be the first Ability, since the abilities are "last wins"
      self.merge Abilities::ThecoreAuthCommons.new user
      # Other Abilities
      Abilities.constants(false).each do |ability|
        unless ability.to_s == "ThecoreAuthCommons"
          const = Abilities.const_get(ability) 
          self.merge const.new(user) if const.is_a? Class
        end
      end
      # Overrides from the database defined permissions
      ::Permission.joins(roles: :users).where(users: {id: user.id}).order(:id).each do |permission|
        # E.g. can :manage, :all
        self.send(permission.predicate.name.to_sym, permission.action.name.to_sym, (permission.target.name.classify.constantize rescue permission.target.name.to_sym))
      end unless user.blank?
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
thecore_auth_commons-3.2.2 config/initializers/concern_cancancan.rb
thecore_auth_commons-3.2.1 config/initializers/concern_cancancan.rb
thecore_auth_commons-3.1.7 config/initializers/concern_cancancan.rb
thecore_auth_commons-3.1.5 config/initializers/concern_cancancan.rb
thecore_auth_commons-3.1.4 config/initializers/concern_cancancan.rb
thecore_auth_commons-3.1.3 config/initializers/concern_cancancan.rb
thecore_auth_commons-3.1.2 config/initializers/concern_cancancan.rb
thecore_auth_commons-3.1.1 config/initializers/concern_cancancan.rb
thecore_auth_commons-3.1.0 config/initializers/concern_cancancan.rb
thecore_auth_commons-3.0.13 config/initializers/concern_cancancan.rb
thecore_auth_commons-3.0.12 config/initializers/concern_cancancan.rb
thecore_auth_commons-3.0.11 config/initializers/concern_cancancan.rb
thecore_auth_commons-3.0.10 config/initializers/concern_cancancan.rb
thecore_auth_commons-3.0.9 config/initializers/concern_cancancan.rb
thecore_auth_commons-3.0.8 config/initializers/concern_cancancan.rb
thecore_auth_commons-3.0.7 config/initializers/concern_cancancan.rb
thecore_auth_commons-3.0.6 config/initializers/concern_cancancan.rb
thecore_auth_commons-3.0.5 config/initializers/concern_cancancan.rb