Class: ProxES::RequestPolicy
- Inherits:
-
Object
- Object
- ProxES::RequestPolicy
- Includes:
- Helpers::Indices
- Defined in:
- lib/proxes/policies/request_policy.rb
Direct Known Subclasses
ProxES::Request::RootPolicy, ProxES::Request::SearchPolicy, ProxES::Request::SnapshotPolicy, ProxES::Request::StatsPolicy
Defined Under Namespace
Classes: Scope
Instance Attribute Summary collapse
-
#record ⇒ Object
readonly
Returns the value of attribute record.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(user, record) ⇒ RequestPolicy
constructor
A new instance of RequestPolicy.
- #logger ⇒ Object
- #method_missing(method_sym, *arguments, &block) ⇒ Object
- #respond_to_missing?(name, _include_private = false) ⇒ Boolean
Methods included from Helpers::Indices
Constructor Details
#initialize(user, record) ⇒ RequestPolicy
Returns a new instance of RequestPolicy.
13 14 15 16 |
# File 'lib/proxes/policies/request_policy.rb', line 13 def initialize(user, record) @user = user @record = record end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/proxes/policies/request_policy.rb', line 18 def method_missing(method_sym, *arguments, &block) if method_sym.to_s[-1] == '?' return false if user.nil? if record.indices? patterns = ProxES::Permission.where(verb: 'INDEX', role: user.roles).map do || .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 ProxES::Permission.where(verb: method_sym[0..-2].upcase, role: user.roles).each do || return true if record.path =~ %r{#{permission.pattern}} end end false else super end end |
Instance Attribute Details
#record ⇒ Object (readonly)
Returns the value of attribute record.
11 12 13 |
# File 'lib/proxes/policies/request_policy.rb', line 11 def record @record end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
11 12 13 |
# File 'lib/proxes/policies/request_policy.rb', line 11 def user @user end |
Instance Method Details
#logger ⇒ Object
43 44 45 |
# File 'lib/proxes/policies/request_policy.rb', line 43 def logger @logger ||= ProxES::Services::Logger.instance end |
#respond_to_missing?(name, _include_private = false) ⇒ Boolean
39 40 41 |
# File 'lib/proxes/policies/request_policy.rb', line 39 def respond_to_missing?(name, _include_private = false) name[-1] == '?' end |