Sha256: 9c4a3a62ec21c2ad05e4ee033b59eed654f488525034883cdfe18f8d57f1939e

Contents?: true

Size: 696 Bytes

Versions: 2

Compression:

Stored size: 696 Bytes

Contents

# frozen_string_literal: true

require 'proxes/db'
require 'proxes/models/permission'
require 'proxes/policies/request_policy'

module ProxES
  class Request
    class IndexPolicy < RequestPolicy
      class Scope < RequestPolicy::Scope
        def resolve
          return [] if user.nil?

          patterns = Permission.for_user(user, 'INDEX').map do |permission|
            permission.pattern.gsub(/\{user.(.*)\}/) { |_match| user.send(Regexp.last_match[1].to_sym) }
          end
          result = filter(scope.index, patterns)
          return [] unless result.count > 0
          %w[POST PUT].include?(scope.request_method) ? scope.index : result
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
proxes-0.7.1 lib/proxes/policies/request/index_policy.rb
proxes-0.7.0 lib/proxes/policies/request/index_policy.rb