Class: Parse::Constraint::NotWriteableByConstraint

Inherits:
Constraint
  • Object
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 Method Summary collapse

Instance Method Details

#build ⇒ Object



4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
# File 'lib/parse/query/constraints.rb', line 4065

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