Files
payload/docs/Access-Control/collections.mdx
2021-01-04 17:00:55 -05:00

96 lines
3.8 KiB
Plaintext

---
title: Collection Access Control
label: Collections
order: 20
---
Collections access control is specified with functions inside a collection config.
## Available Functions
| Function | Allows/Denies Access |
| ---------- | ----------------------------------------- |
| **create** | creating a collection document |
| **read** | reading a collection document |
| **update** | updating a collection document |
| **delete** | deleting a collection document |
| **admin** | viewing collection in the admin interface |
```js
// Collection config
module.exports = {
slug: "public-user",
// highlight-start
access: {
create: () => true,
read: () => true,
update: () => true,
delete: () => true,
admin: () => true,
},
// highlight-end
};
```
### Create
Create access functions return a boolean result which allows/denies access to create a document
#### Arguments
The function receives one `args` argument that contains the following properties:
| Option | Description |
| --------- | --------------------------------------------------------------------------------------------------- |
| **`req`** | The Express `request` object with additional `user` property, which is the currently logged in user |
### Read
Read access functions can return a boolean result or optionally return a [where constraint](/docs/queries/overview).
#### Arguments
The function receives one `args` argument that contains the following properties:
| Option | Description |
| --------- | --------------------------------------------------------------------------------------------------- |
| **`req`** | The Express `request` object with additional `user` property, which is the currently logged in user |
| **`id`** | `id` of document requested. Value is `undefined` if not querying for specific ID |
### Update
Update access functions can return a boolean result or optionally return a [where constraint](/docs/queries/overview).
#### Arguments
The function receives one `args` argument that contains the following properties:
| Option | Description |
| --------- | --------------------------------------------------------------------------------------------------- |
| **`req`** | The Express `request` object with additional `user` property, which is the currently logged in user |
### Delete
Delete access functions can return a boolean result or optionally return a [where constraint](/docs/queries/overview).
#### Arguments
The function receives one `args` argument that contains the following properties:
| Option | Description |
| --------- | --------------------------------------------------------------------------------------------------- |
| **`req`** | The Express `request` object with additional `user` property, which is the currently logged in user |
| **`id`** | `id` of the document being deleted |
### Admin
Admin access functions determine whether or not a user can access the admin UI.
** Only applicable on collections that have auth **
It receives one `args` argument that contains the following properties:
| Option | Description |
| --------- | --------------------------------------------------------------------------------------------------- |
| **`req`** | The Express `request` object with additional `user` property, which is the currently logged in user |