class PIM::Authorization::Permission
Attributes
actions[R]
context[R]
data_model[R]
object_type[R]
Public Class Methods
new(allowed, data_model, object_type, *actions, &block)
click to toggle source
# File pim.rb, line 7380 def initialize allowed, data_model, object_type, *actions, &block @allowed = allowed ? true : false @data_model = data_model @object_type = stringified_value(object_type) @actions = stringified_value(actions) @context = build_context(&block) if block end
Public Instance Methods
as_json(opts = {})
click to toggle source
# File pim.rb, line 7438 def as_json opts = {} json = { :allowed => @allowed, :objectType => object_type } json[:actions] = actions if not is_empty?(actions) json[:context] = context if not is_empty?(context) json end
is_allowed?()
click to toggle source
# File pim.rb, line 7388 def is_allowed? return @allowed end
matches?(object_type, action, context = nil)
click to toggle source
# File pim.rb, line 7392 def matches? object_type, action, context = nil object_type = stringified_value(object_type) action = stringified_value(action) # Don't set context to nil if empty! # Otherwise an "exact" match is not possible with an empty context. context = case when context.nil? then nil when context.empty? then context else stringified_value(context) end return false if not matches_value?(@object_type, object_type) return false if not matches_value?(@actions, action) if not @context.nil? and not context.nil? default_value = context[CONTEXT_DEFAULT_VALUE] @context.each_pair do |key, value| test_value = context[key] || default_value return false if not matches_value?(value, test_value) end end return true end
matches_value?(value, test_value)
click to toggle source
# File pim.rb, line 7420 def matches_value? value, test_value if value.nil? or value == ALL or (is_allowed? and test_value == ANY) or test_value == value return true elsif is_array?(value) if value.include?(ALL) return true elsif is_array?(test_value) return (is_allowed? and test_value.include?(ANY)) || !(value & test_value).empty? else return (is_allowed? and test_value == ANY) || value.include?(test_value) end end return false end