Class: Parse::Constraint::NotWriteableByConstraint

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 the internal _wperm field.

ACL NOT Writable By Constraint Query objects that are NOT writable by the specified users/roles.

Examples:

Find objects NOT writable by a user

Song.query.where(:acl.not_writeable_by => current_user)

Direct Known Subclasses

NotWritableByConstraint

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



3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
# File 'lib/parse/query/constraints.rb', line 3266

def build
  keys = ACLPermissions.collect_for_negation(@value)
  return { "__aggregation_pipeline" => [] } if keys.empty?

  # See {NotReadableByConstraint#build}: the `$exists: true` guard
  # prevents a missing `_wperm` (publicly writable per Parse Server)
  # from matching `$nin`, which would otherwise make
  # #not_publicly_writable report write-exposed objects as safe.
  pipeline = [
    {
      "$match" => {
        "_wperm" => { "$exists" => true, "$nin" => keys },
      },
    },
  ]

  { "__aggregation_pipeline" => pipeline }
end