Collection Access Control
Collection Access Control is Access Control used to restrict access to Documents within a Collection, as well as what they can and cannot see within the Admin Panel as it relates to that Collection.
To add Access Control to a Collection, use the access property in your Collection Config:
Config Options
Access Control is specific to the operation of the request.
To add Access Control to a Collection, use the access property in your Collection Config:
The following options are available:
Function | Allows/Denies Access |
|---|---|
| Used in the |
| Used in the |
| Used in the |
| Used in the |
| Optionally overrides |
If a Collection supports Authentication, the following additional options are available:
Function | Allows/Denies Access |
|---|---|
| Used to restrict access to the Admin Panel. More details. |
| Used to restrict which users can access the |
If a Collection supports Versions, the following additional options are available:
Function | Allows/Denies Access |
|---|---|
| Used to control who can read versions, and who can't. Will automatically restrict the Admin UI version viewing access. More details. |
Create
Returns a boolean which allows/denies access to the create request.
To add create Access Control to a Collection, use the create property in the Collection Config:
The following arguments are provided to the create function:
Option | Description |
|---|---|
| The Request object containing the currently authenticated |
| The data passed to create the document with. |
| The slug of the Collection being accessed. |
Read
Returns a boolean which allows/denies access to the read request.
To add read Access Control to a Collection, use the read property in the Collection Config:
As your application becomes more complex, you may want to define your function in a separate file and import them into your Collection Config:
The following arguments are provided to the read function:
Option | Description |
|---|---|
| The Request object containing the currently authenticated |
| |
| The slug of the Collection being accessed. |
Update
Returns a boolean which allows/denies access to the update request.
To add update Access Control to a Collection, use the update property in the Collection Config:
As your application becomes more complex, you may want to define your function in a separate file and import them into your Collection Config:
The following arguments are provided to the update function:
Option | Description |
|---|---|
| The Request object containing the currently authenticated |
| |
| The data passed to update the document with. |
| The slug of the Collection being accessed. |
Delete
Similarly to the Update function, returns a boolean or a query constraint to limit which documents can be deleted by which users.
To add delete Access Control to a Collection, use the delete property in the Collection Config:
As your application becomes more complex, you may want to define your function in a separate file and import them into your Collection Config:
The following arguments are provided to the delete function:
Option | Description |
|---|---|
| The Request object with additional |
| |
| The data being set on the document. For Trash-enabled collections, check |
| The slug of the Collection being accessed. |
Admin
If the Collection is used to access the Admin Panel, the Admin Access Control function determines whether or not the currently logged in user can access the admin UI.
To add Admin Access Control to a Collection, use the admin property in the Collection Config:
The following arguments are provided to the admin function:
Option | Description |
|---|---|
| The Request object containing the currently authenticated |
| The slug of the Collection being accessed. |
Unlock
Determines which users can unlock other users who may be blocked from authenticating successfully due to failing too many login attempts.
To add Unlock Access Control to a Collection, use the unlock property in the Collection Config:
The following arguments are provided to the unlock function:
Option | Description |
|---|---|
| The Request object containing the currently authenticated |
| The slug of the Collection being accessed. |
Read Versions
If the Collection has Versions enabled, the readVersions Access Control function determines whether or not the currently logged in user can access the version history of a Document.
If readVersions is not configured, Payload uses the Collection's read Access Control. Boolean results are preserved, and query constraints are automatically adjusted to target fields within the stored version document.
For findVersionByID, the inherited read function receives the parent Document's id, not the version record's id.
To add Read Versions Access Control to a Collection, use the readVersions property in the Collection Config:
The following arguments are provided to the readVersions function:
Option | Description |
|---|---|
| The Request object containing the currently authenticated |
| The slug of the Collection being accessed. |
Was this page helpful?