Class: Parse::Constraint::NotReadableByConstraint

Inherits:
Constraint
  • Object
show all
Includes:
AclConstraintHelpers
Defined in:
lib/parse/query/constraints.rb

Overview

Note:

This constraint uses aggregation pipeline because Parse Server restricts direct queries on the internal _rperm field.

ACL NOT Readable By Constraint Query objects that are NOT readable by the specified users/roles. Useful for finding objects hidden from specific users.

Examples:

Find objects NOT readable by a user (hidden from them)

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

Find objects NOT publicly readable

Song.query.where(:acl.not_readable_by => "*")
Song.query.where(:acl.not_readable_by => :public)

Instance Method Summary collapse

Instance Method Details

#buildObject



3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
# File 'lib/parse/query/constraints.rb', line 3171

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

  # Find objects where _rperm does NOT contain any of the keys
  pipeline = [
    {
      "$match" => {
        "_rperm" => { "$nin" => keys },
      },
    },
  ]

  { "__aggregation_pipeline" => pipeline }
end