Class: ForestLiana::ScopeValidator
- Inherits:
-
Object
- Object
- ForestLiana::ScopeValidator
- Defined in:
- app/services/forest_liana/scope_validator.rb
Instance Method Summary collapse
-
#initialize(scope_permissions, users_variable_values) ⇒ ScopeValidator
constructor
A new instance of ScopeValidator.
- #is_scope_in_request?(scope_request) ⇒ Boolean
Constructor Details
#initialize(scope_permissions, users_variable_values) ⇒ ScopeValidator
Returns a new instance of ScopeValidator.
3 4 5 6 |
# File 'app/services/forest_liana/scope_validator.rb', line 3 def initialize(, users_variable_values) @scope_filters = @users_variable_values = users_variable_values end |
Instance Method Details
#is_scope_in_request?(scope_request) ⇒ Boolean
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/services/forest_liana/scope_validator.rb', line 8 def is_scope_in_request?(scope_request) begin filters = JSON.parse(scope_request[:filters]) rescue JSON::ParserError raise ForestLiana::Errors::HTTP422Error.new('Invalid filters JSON format') end @computed_scope = compute_condition_filters_from_scope(scope_request[:user_id]) # NOTICE: Perfom a travel in the request condition filters tree to find the scope tagged_scope_filters = get_scope_found_in_request(filters) # NOTICE: Permission system always send an aggregator even if there is only one condition # In that case, if the condition is valid, then request was not edited return !tagged_scope_filters.nil? if @scope_filters['conditions'].length == 1 # NOTICE: If there is more than one condition, do a final validation on the condition filters return tagged_scope_filters != nil && tagged_scope_filters[:aggregator] == @scope_filters['aggregator'] && tagged_scope_filters[:conditions] && tagged_scope_filters[:conditions].length == @scope_filters['conditions'].length end |