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