ParseCLP

Parse~ ParseCLP

Creates a new CLP. If no argument is given, the CLP has no permissions for anyone. If the argument is a Parse.User or Parse.Role, the CLP will have read and write permission for only that user or role. If the argument is any other JSON object, that object will be interpretted as a serialized CLP created with toJSON().

A CLP, or Class Level Permissions can be added to any Parse.Schema to restrict access to only a subset of users of your application.

For get/count/find/create/update/delete/addField using the following functions:

Entity is type Parse.User or Parse.Role or string Role is type Parse.Role or Name of Parse.Role

getGetRequiresAuthentication() setGetRequiresAuthentication(allowed: boolean) getGetPointerFields() setGetPointerFields(pointerFields: string[]) getGetAccess(entity: Entity) setGetAccess(entity: Entity, allowed: boolean) getPublicGetAccess() setPublicGetAccess(allowed: boolean) getRoleGetAccess(role: Role) setRoleGetAccess(role: Role, allowed: boolean) getFindRequiresAuthentication() setFindRequiresAuthentication(allowed: boolean) getFindPointerFields() setFindPointerFields(pointerFields: string[]) getFindAccess(entity: Entity) setFindAccess(entity: Entity, allowed: boolean) getPublicFindAccess() setPublicFindAccess(allowed: boolean) getRoleFindAccess(role: Role) setRoleFindAccess(role: Role, allowed: boolean) getCountRequiresAuthentication() setCountRequiresAuthentication(allowed: boolean) getCountPointerFields() setCountPointerFields(pointerFields: string[]) getCountAccess(entity: Entity) setCountAccess(entity: Entity, allowed: boolean) getPublicCountAccess() setPublicCountAccess(allowed: boolean) getRoleCountAccess(role: Role) setRoleCountAccess(role: Role, allowed: boolean) getCreateRequiresAuthentication() setCreateRequiresAuthentication(allowed: boolean) getCreatePointerFields() setCreatePointerFields(pointerFields: string[]) getCreateAccess(entity: Entity) setCreateAccess(entity: Entity, allowed: boolean) getPublicCreateAccess() setPublicCreateAccess(allowed: Boolean) getRoleCreateAccess(role: Role) setRoleCreateAccess(role: Role, allowed: boolean) getUpdateRequiresAuthentication() setUpdateRequiresAuthentication(allowed: boolean) getUpdatePointerFields() setUpdatePointerFields(pointerFields: string[]) getUpdateAccess(entity: Entity) setUpdateAccess(entity: Entity, allowed: boolean) getPublicUpdateAccess() setPublicUpdateAccess(allowed: boolean) getRoleUpdateAccess(role: Role) setRoleUpdateAccess(role: Role, allowed: boolean) getDeleteRequiresAuthentication() setDeleteRequiresAuthentication(allowed: boolean) getDeletePointerFields() setDeletePointerFields(pointerFields: string[]) getDeleteAccess(entity: Entity) setDeleteAccess(entity: Entity, allowed: boolean) getPublicDeleteAccess() setPublicDeleteAccess(allowed: boolean) getRoleDeleteAccess(role: Role) setRoleDeleteAccess(role: Role, allowed: boolean) getAddFieldRequiresAuthentication() setAddFieldRequiresAuthentication(allowed: boolean) getAddFieldPointerFields() setAddFieldPointerFields(pointerFields: string[]) getAddFieldAccess(entity: Entity) setAddFieldAccess(entity: Entity, allowed: boolean) getPublicAddFieldAccess() setPublicAddFieldAccess(allowed: boolean) getRoleAddFieldAccess(role: Role) setRoleAddFieldAccess(role: Role, allowed: boolean)

Constructor

new ParseCLP(userId)

Parameters:
Name Type Description
userId Parse.User | Parse.Role | object

The user to initialize the CLP for

Methods

equals(other) → {boolean}

Returns whether this CLP is equal to another object

Parameters:
Name Type Description
other

The other object to compare to

Returns:
Type:
boolean

getProtectedFields(userId) → {Array.<string>}

Returns array of fields are accessable to this user.

Parameters:
Name Type Description
userId

An instance of Parse.User or its objectId, or a Parse.Role.

Returns:
Type:
Array.<string>

getPublicProtectedFields() → {Array.<string>}

Gets whether the public is allowed to read fields from this class.

Returns:
Type:
Array.<string>

getPublicReadAccess() → {boolean}

Gets whether the public is allowed to read from this class.

Returns:
Type:
boolean

getPublicWriteAccess() → {boolean}

Gets whether the public is allowed to write to this class.

Returns:
Type:
boolean

getReadAccess(userId) → {boolean}

Get whether the given user id is explicitly allowed to read from this class. Even if this returns false, the user may still be able to access it if getPublicReadAccess returns true or a role that the user belongs to has write access.

Parameters:
Name Type Description
userId

An instance of Parse.User or its objectId, or a Parse.Role.

Returns:
Type:
boolean

getReadUserFields() → {Array.<string>}

Returns:
Type:
Array.<string>

User pointer fields

getRoleProtectedFields(role) → {Array.<string>}

Gets whether users belonging to the given role are allowed to count to this user. Even if this returns false, the role may still be able to count it if a parent role has count access.

Parameters:
Name Type Description
role

The name of the role, or a Parse.Role object.

Throws:

If role is neither a Parse.Role nor a String.

Type
TypeError
Returns:
Type:
Array.<string>

getRoleReadAccess(role) → {boolean}

Gets whether users belonging to the given role are allowed to read from this class. Even if this returns false, the role may still be able to write it if a parent role has read access.

Parameters:
Name Type Description
role

The name of the role, or a Parse.Role object.

Throws:

If role is neither a Parse.Role nor a String.

Type
TypeError
Returns:
Type:
boolean

true if the role has read access. false otherwise.

getRoleWriteAccess(role) → {boolean}

Gets whether users belonging to the given role are allowed to write to this user. Even if this returns false, the role may still be able to write it if a parent role has write access.

Parameters:
Name Type Description
role

The name of the role, or a Parse.Role object.

Throws:

If role is neither a Parse.Role nor a String.

Type
TypeError
Returns:
Type:
boolean

true if the role has write access. false otherwise.

getWriteAccess(userId) → {boolean}

Gets whether the given user id is explicitly allowed to write to this class. Even if this returns false, the user may still be able to write it if getPublicWriteAccess returns true or a role that the user belongs to has write access.

Parameters:
Name Type Description
userId

An instance of Parse.User or its objectId, or a Parse.Role.

Returns:
Type:
boolean

getWriteUserFields() → {Array.<string>}

Returns:
Type:
Array.<string>

User pointer fields

setProtectedFields(userId, fields)

Sets whether the given user is allowed to retrieve fields from this class.

Parameters:
Name Type Description
userId

An instance of Parse.User or its objectId.

fields Array.<string>

fields to be protected

setPublicProtectedFields(fields)

Sets whether the public is allowed to protect fields in this class.

Parameters:
Name Type Description
fields Array.<string>

setPublicReadAccess(allowed)

Sets whether the public is allowed to read from this class.

Parameters:
Name Type Description
allowed boolean

setPublicWriteAccess(allowed)

Sets whether the public is allowed to write to this class.

Parameters:
Name Type Description
allowed boolean

setReadAccess(userId, allowed)

Sets whether the given user is allowed to read from this class.

Parameters:
Name Type Description
userId

An instance of Parse.User or its objectId.

allowed boolean

whether that user should have read access.

setReadUserFields(pointerFields)

Sets user pointer fields to allow permission for get/count/find operations.

Parameters:
Name Type Description
pointerFields Array.<string>

User pointer fields

setRoleProtectedFields(role, fields)

Sets whether users belonging to the given role are allowed to set access field in this class.

Parameters:
Name Type Description
role

The name of the role, or a Parse.Role object.

fields Array.<string>

Fields to be protected by Role.

Throws:

If role is neither a Parse.Role nor a String.

Type
TypeError

setRoleReadAccess(role, allowed)

Sets whether users belonging to the given role are allowed to read from this class.

Parameters:
Name Type Description
role

The name of the role, or a Parse.Role object.

allowed boolean

Whether the given role can read this object.

Throws:

If role is neither a Parse.Role nor a String.

Type
TypeError

setRoleWriteAccess(role, allowed)

Sets whether users belonging to the given role are allowed to write to this class.

Parameters:
Name Type Description
role

The name of the role, or a Parse.Role object.

allowed boolean

Whether the given role can write this object.

Throws:

If role is neither a Parse.Role nor a String.

Type
TypeError

setWriteAccess(userId, allowed)

Sets whether the given user id is allowed to write to this class.

Parameters:
Name Type Description
userId

An instance of Parse.User or its objectId, or a Parse.Role..

allowed boolean

Whether that user should have write access.

setWriteUserFields(pointerFields)

Sets user pointer fields to allow permission for create/delete/update/addField operations

Parameters:
Name Type Description
pointerFields Array.<string>

User pointer fields

toJSON() → {object}

Returns a JSON-encoded version of the CLP.

Returns:
Type:
object