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



3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
# File 'lib/parse/query/constraints.rb', line 3236

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