Class: Parse::Constraint::PrivateAclConstraint

Inherits:
Parse::Constraint show all
Defined in:
lib/parse/query/constraints.rb

Overview

Note:

This constraint uses aggregation pipeline because Parse Server restricts direct queries on internal ACL fields.

ACL Private/Master-Key-Only Constraint Query objects with completely empty ACL (no read or write permissions). These objects can only be accessed with the master key.

Examples:

Find all private objects

Song.query.where(:acl.private_acl => true)

Find all non-private objects (have some permissions)

Song.query.where(:acl.private_acl => false)

Instance Attribute Summary

Attributes inherited from Parse::Constraint

#operand, #operation, #operator, #value

Instance Method Summary collapse

Methods inherited from Parse::Constraint

#as_json, constraint_keyword, create, formatted_value, #formatted_value, #initialize, #key, #precedence, #regex_unicode_option, register, #to_s

Constructor Details

This class inherits a constructor from Parse::Constraint

Instance Method Details

#buildObject



3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
# File 'lib/parse/query/constraints.rb', line 3307

def build
  # A truly private (master-key-only) object has an EXPLICIT empty
  # _rperm AND an explicit empty _wperm. A MISSING _rperm/_wperm is
  # treated by Parse Server as PUBLIC — the opposite of private — so
  # the `$exists: true` guards are required and the missing-field
  # branch must NOT be matched (this is the bug-fixed shape: the
  # previous version OR'd in `{$exists: false}`, wrongly classifying
  # the most-public rows as private).
  private_match = {
    "$and" => [
      { "_rperm" => { "$exists" => true, "$eq" => [] } },
      { "_wperm" => { "$exists" => true, "$eq" => [] } },
    ],
  }

  # `private_acl => false` is the exact complement: every object that
  # is NOT fully master-key-only — those with any read/write grant AND
  # those with a missing (public) _rperm/_wperm.
  match = @value == true ? private_match : { "$nor" => [private_match] }

  { "__aggregation_pipeline" => [{ "$match" => match }] }
end