Class: ProxES::RequestPolicy
- Inherits:
-
Object
- Object
- ProxES::RequestPolicy
- Includes:
- Helpers::Indices
- Defined in:
- lib/proxes/policies/request_policy.rb
Direct Known Subclasses
ProxES::Request::CatPolicy, 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
- #action_allowed?(action) ⇒ Boolean
- #index_allowed? ⇒ Boolean
-
#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.
14 15 16 17 |
# File 'lib/proxes/policies/request_policy.rb', line 14 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
19 20 21 22 23 24 25 |
# File 'lib/proxes/policies/request_policy.rb', line 19 def method_missing(method_sym, *arguments, &block) return super if method_sym.to_s[-1] != '?' return false if user.nil? return true if record.indices? && index_allowed? action_allowed? method_sym[0..-2].upcase end |
Instance Attribute Details
#record ⇒ Object (readonly)
Returns the value of attribute record.
12 13 14 |
# File 'lib/proxes/policies/request_policy.rb', line 12 def record @record end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
12 13 14 |
# File 'lib/proxes/policies/request_policy.rb', line 12 def user @user end |
Instance Method Details
#action_allowed?(action) ⇒ Boolean
34 35 36 37 38 39 40 |
# File 'lib/proxes/policies/request_policy.rb', line 34 def action_allowed?(action) # Give me all the user's permissions that match the verb Permission.for_user(user, action).each do || return true if record.path =~ /#{.pattern}/ end false end |
#index_allowed? ⇒ Boolean
27 28 29 30 31 32 |
# File 'lib/proxes/policies/request_policy.rb', line 27 def index_allowed? patterns = Permission.for_user(user, 'INDEX').map do || .pattern.gsub(/\{user.(.*)\}/) { |_match| user.send(Regexp.last_match[1].to_sym) } end filter(record.index, patterns).count > 0 end |
#logger ⇒ Object
46 47 48 |
# File 'lib/proxes/policies/request_policy.rb', line 46 def logger @logger ||= ProxES::Services::Logger.instance end |
#respond_to_missing?(name, _include_private = false) ⇒ Boolean
42 43 44 |
# File 'lib/proxes/policies/request_policy.rb', line 42 def respond_to_missing?(name, _include_private = false) name[-1] == '?' end |