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, register, #to_s

Constructor Details

This class inherits a constructor from Parse::Constraint

Instance Method Details

#buildObject



3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
# File 'lib/parse/query/constraints.rb', line 3267

def build
  is_private = @value == true

  if is_private
    # Match objects with empty or missing _rperm AND _wperm
    pipeline = [
      {
        "$match" => {
          "$and" => [
            {
              "$or" => [
                { "_rperm" => { "$exists" => true, "$eq" => [] } },
                { "_rperm" => { "$exists" => false } },
              ],
            },
            {
              "$or" => [
                { "_wperm" => { "$exists" => true, "$eq" => [] } },
                { "_wperm" => { "$exists" => false } },
              ],
            },
          ],
        },
      },
    ]
  else
    # Match objects that have SOME permissions (either read or write)
    pipeline = [
      {
        "$match" => {
          "$or" => [
            { "_rperm" => { "$exists" => true, "$ne" => [] } },
            { "_wperm" => { "$exists" => true, "$ne" => [] } },
          ],
        },
      },
    ]
  end

  { "__aggregation_pipeline" => pipeline }
end