Class: Parse::Constraint::ACLWritableByConstraint

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

Overview

A constraint for filtering objects based on ACL write permissions. This constraint queries the MongoDB _wperm field directly. Strings are used as exact permission values (user IDs or "role:RoleName" format).

For role-based filtering with automatic "role:" prefix, use writable_by_role instead.

Find objects writable by a specific user object (fetches user's roles automatically)

Post.where(:ACL.writable_by => user)

Find objects writable by exact permission strings (no prefix added)

Post.where(:ACL.writable_by => "user123") # User ID Post.where(:ACL.writable_by => "role:Admin") # Role with explicit prefix Post.where(:ACL.writable_by => ["user123", "role:Admin"])

Instance Method Summary collapse

Instance Method Details

#buildHash

Returns the compiled constraint using _wperm field.

Returns:

  • (Hash)

    the compiled constraint using _wperm field.



2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
# File 'lib/parse/query/constraints.rb', line 2995

def build
  # Use @value directly to preserve type information before
  # formatted_value converts to pointers.
  value = @value

  # "No permissions" intent (nil / [] / "none" / :none) — see
  # {ACLReadableByConstraint#build}.
  return ACLPermissions.empty_pipeline(field: "_wperm") if ACLPermissions.empty_intent?(value)

  permissions = ACLPermissions.collect(value)
  ACLPermissions.pipeline(permissions, field: "_wperm", strict: strict?)
end

#strict?Boolean

Returns whether to compile an EXACT match. Overridden by Parse::Constraint::ACLWritableByExactConstraint.

Returns:



2990
2991
2992
# File 'lib/parse/query/constraints.rb', line 2990

def strict?
  false
end

#writable_byACLWritableByConstraint

A registered method on a symbol to create the constraint.

Examples:

q.where :ACL.writable_by => user_or_permission_strings

Returns:



2986
# File 'lib/parse/query/constraints.rb', line 2986

register :writable_by