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
- #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.
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 |
# 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? return true if index_allowed? else return true if action_allowed? method_sym[0..-2].upcase 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
#action_allowed?(action) ⇒ Boolean
40 41 42 43 44 45 46 |
# File 'lib/proxes/policies/request_policy.rb', line 40 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 =~ %r{#{.pattern}} end false end |
#index_allowed? ⇒ Boolean
33 34 35 36 37 38 |
# File 'lib/proxes/policies/request_policy.rb', line 33 def index_allowed? patterns = Permission.for_user(user, 'INDEX').map do || .pattern.gsub(/\{user.(.*)\}/) { |match| user.send(Regexp.last_match[1].to_sym) } end return filter(record.index, patterns).count.positive? end |
#logger ⇒ Object
52 53 54 |
# File 'lib/proxes/policies/request_policy.rb', line 52 def logger @logger ||= ProxES::Services::Logger.instance end |
#respond_to_missing?(name, _include_private = false) ⇒ Boolean
48 49 50 |
# File 'lib/proxes/policies/request_policy.rb', line 48 def respond_to_missing?(name, _include_private = false) name[-1] == '?' end |