Class: Parse::Constraint::ACLReadableByConstraint
- Inherits:
-
Parse::Constraint
- Object
- Parse::Constraint
- Parse::Constraint::ACLReadableByConstraint
- Defined in:
- lib/parse/query/constraints.rb
Overview
A constraint for filtering objects based on ACL read permissions. This constraint queries the MongoDB _rperm field directly. Strings are used as exact permission values (user IDs or “role:RoleName” format).
For role-based filtering with automatic “role:” prefix, use readable_by_role instead.
# Find objects readable by a specific user object (fetches user's roles automatically)
Post.where(:ACL.readable_by => user)
# Find objects readable by exact permission strings (no prefix added)
Post.where(:ACL.readable_by => "user123") # User ID
Post.where(:ACL.readable_by => "role:Admin") # Role with explicit prefix
Post.where(:ACL.readable_by => ["user123", "role:Admin"])
Instance Attribute Summary
Attributes inherited from Parse::Constraint
#operand, #operation, #operator, #value
Instance Method Summary collapse
-
#build ⇒ Hash
The compiled constraint using _rperm field.
-
#readable_by ⇒ ACLReadableByConstraint
A registered method on a symbol to create the constraint.
Methods inherited from Parse::Constraint
#as_json, constraint_keyword, create, formatted_value, #formatted_value, #initialize, #key, #precedence, register, #to_s
Constructor Details
This class inherits a constructor from Parse::Constraint
Instance Method Details
#build ⇒ Hash
Returns the compiled constraint using _rperm field.
2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 |
# File 'lib/parse/query/constraints.rb', line 2682 def build # Use @value directly to preserve type information before # formatted_value converts to pointers. value = @value # Special case: "none" matches objects whose _rperm is an empty # array — master-key-only documents. Parse Server writes [] # when no read permission is set, and an absent _rperm is # treated as public (handled by the default predicate path). if value.is_a?(String) && value == "none" pipeline = [{ "$match" => { "_rperm" => { "$eq" => [] } } }] return { "__aggregation_pipeline" => pipeline } end = ACLPermissions.collect(value) ACLPermissions.pipeline(, field: "_rperm") end |
#readable_by ⇒ ACLReadableByConstraint
A registered method on a symbol to create the constraint.
2679 |
# File 'lib/parse/query/constraints.rb', line 2679 register :readable_by |