Sha256: bcf69d18814a5d04922993699af1801ffa3706f494a5e709d0ce52e8ef47c918
Contents?: true
Size: 1.68 KB
Versions: 3
Compression:
Stored size: 1.68 KB
Contents
# frozen_string_literal: true require 'proxes/db' require 'proxes/models/permission' require 'proxes/services/logger' require 'proxes/helpers/indices' module ProxES class RequestPolicy include Helpers::Indices attr_reader :user, :record def initialize(user, record) @user = user @record = record end def method_missing(method_sym, *arguments, &block) if method_sym.to_s[-1] == '?' return false if user.nil? if record.indices? patterns = Permission.where(verb: 'INDEX', role: user.roles).map do |permission| permission.pattern.gsub(/\{user.(.*)\}/) { |match| user.send(Regexp.last_match[1].to_sym) } end return filter(record.index, patterns).count.positive? else # Give me all the user's permissions that match the verb Permission.where(verb: method_sym[0..-2].upcase, role: user.roles).each do |permission| return true if record.path =~ %r{#{permission.pattern}} end end false else super end end def respond_to_missing?(name, _include_private = false) name[-1] == '?' end def logger @logger ||= ProxES::Services::Logger.instance end class Scope include Helpers::Indices attr_reader :user, :scope def initialize(user, scope) @user = user @scope = scope end def logger @logger ||= ProxES::Services::Logger.instance end end end end require 'proxes/policies/request/root_policy' require 'proxes/policies/request/stats_policy' require 'proxes/policies/request/search_policy' require 'proxes/policies/request/snapshot_policy'
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
proxes-0.3.5 | lib/proxes/policies/request_policy.rb |
proxes-0.3.3 | lib/proxes/policies/request_policy.rb |
proxes-0.3.2 | lib/proxes/policies/request_policy.rb |