Class: ProxES::RequestPolicy
- Inherits:
-
Object
- Object
- ProxES::RequestPolicy
- Includes:
- Helpers::Indices
- Defined in:
- lib/proxes/policies/request_policy.rb
Direct Known Subclasses
ProxES::Request::BulkPolicy, ProxES::Request::CatPolicy, ProxES::Request::CreatePolicy, ProxES::Request::IndexPolicy, ProxES::Request::RootPolicy, ProxES::Request::SearchPolicy, ProxES::Request::SnapshotPolicy, ProxES::Request::StatsPolicy
Defined Under Namespace
Classes: Scope
Instance Attribute Summary collapse
-
#record ⇒ Object
(also: #request)
readonly
Returns the value of attribute record.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #action_allowed?(action) ⇒ Boolean
- #index_allowed? ⇒ Boolean
-
#initialize(user, record) ⇒ RequestPolicy
constructor
A new instance of RequestPolicy.
- #method_missing(method_sym, *arguments, &block) ⇒ Object
- #respond_to_missing?(name, _include_private = false) ⇒ Boolean
Methods included from Helpers::Indices
#filter, #patterns, #patterns_for
Constructor Details
#initialize(user, record) ⇒ RequestPolicy
Returns a new instance of RequestPolicy.
16 17 18 19 |
# File 'lib/proxes/policies/request_policy.rb', line 16 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
21 22 23 24 25 26 27 |
# File 'lib/proxes/policies/request_policy.rb', line 21 def method_missing(method_sym, *arguments, &block) return super if method_sym.to_s[-1] != '?' return true if user && user.super_admin? return false if request.indices? && !index_allowed? action_allowed? method_sym[0..-2].upcase end |
Instance Attribute Details
#record ⇒ Object (readonly) Also known as: request
Returns the value of attribute record.
13 14 15 |
# File 'lib/proxes/policies/request_policy.rb', line 13 def record @record end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
13 14 15 |
# File 'lib/proxes/policies/request_policy.rb', line 13 def user @user end |
Instance Method Details
#action_allowed?(action) ⇒ Boolean
41 42 43 44 |
# File 'lib/proxes/policies/request_policy.rb', line 41 def action_allowed?(action) # Give me all the user's permissions that match the verb !!patterns_for(action).find { || (request.path =~ /#{.pattern}/) } end |
#index_allowed? ⇒ Boolean
33 34 35 36 37 38 39 |
# File 'lib/proxes/policies/request_policy.rb', line 33 def index_allowed? patterns = patterns_for('INDEX').map do || return nil if .pattern.blank? .pattern.gsub(/\{user.(.*)\}/) { |_match| user.send(Regexp.last_match[1].to_sym) } end.compact filter(request.index, patterns).count > 0 end |
#respond_to_missing?(name, _include_private = false) ⇒ Boolean
29 30 31 |
# File 'lib/proxes/policies/request_policy.rb', line 29 def respond_to_missing?(name, _include_private = false) name[-1] == '?' end |