Skip to content

Commit 73f418b

Browse files
committed
feat: exposes data arg within create and update access control
1 parent 7e5eeef commit 73f418b

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

docs/access-control/collections.mdx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ Returns a boolean which allows/denies access to the `create` request.
4848

4949
**Available argument properties :**
5050

51-
| Option | Description |
52-
| --------- | ----------- |
53-
| **`req`** | The Express `request` object containing the currently authenticated `user` |
51+
| Option | Description |
52+
| ---------- | ----------- |
53+
| **`req`** | The Express `request` object containing the currently authenticated `user` |
54+
| **`data`** | The data passed to create the document with. |
5455

5556
### Read
5657

@@ -69,10 +70,11 @@ Update access functions can return a boolean result or optionally return a [quer
6970

7071
**Available argument properties :**
7172

72-
| Option | Description |
73-
| --------- | ----------- |
74-
| **`req`** | The Express `request` object containing the currently authenticated `user` |
75-
| **`id`** | `id` of document requested to update |
73+
| Option | Description |
74+
| ---------- | ----------- |
75+
| **`req`** | The Express `request` object containing the currently authenticated `user` |
76+
| **`id`** | `id` of document requested to update |
77+
| **`data`** | The data passed to update the document with. |
7678

7779
### Delete
7880

docs/access-control/globals.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Returns a boolean result or optionally a [query constraint](/docs/queries/overvi
4646

4747
**Available argument properties:**
4848

49-
| Option | Description |
50-
| --------- | ----------- |
51-
| **`req`** | The Express `request` object containing the currently authenticated `user` |
49+
| Option | Description |
50+
| ---------- | ----------- |
51+
| **`req`** | The Express `request` object containing the currently authenticated `user` |
52+
| **`data`** | The data passed to update the global with. |

src/collections/operations/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async function create(this: Payload, incomingArgs: Arguments): Promise<Document>
6767
// /////////////////////////////////////
6868

6969
if (!overrideAccess) {
70-
await executeAccess({ req }, collectionConfig.access.create);
70+
await executeAccess({ req, data }, collectionConfig.access.create);
7171
}
7272

7373
// /////////////////////////////////////

src/collections/operations/update.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ async function update(this: Payload, incomingArgs: Arguments): Promise<Document>
6464
autosave = false,
6565
} = args;
6666

67+
let { data } = args;
68+
6769
if (!id) {
6870
throw new APIError('Missing ID of document to update.', httpStatus.BAD_REQUEST);
6971
}
@@ -74,7 +76,7 @@ async function update(this: Payload, incomingArgs: Arguments): Promise<Document>
7476
// Access
7577
// /////////////////////////////////////
7678

77-
const accessResults = !overrideAccess ? await executeAccess({ req, id }, collectionConfig.access.update) : true;
79+
const accessResults = !overrideAccess ? await executeAccess({ req, id, data }, collectionConfig.access.update) : true;
7880
const hasWherePolicy = hasWhereAccessResult(accessResults);
7981

8082
// /////////////////////////////////////
@@ -120,8 +122,6 @@ async function update(this: Payload, incomingArgs: Arguments): Promise<Document>
120122
showHiddenFields,
121123
});
122124

123-
let { data } = args;
124-
125125
// /////////////////////////////////////
126126
// Upload and resize potential files
127127
// /////////////////////////////////////

src/globals/operations/update.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ async function update<T extends TypeWithID = any>(this: Payload, args): Promise<
2626
autosave,
2727
} = args;
2828

29+
let { data } = args;
30+
2931
const shouldSaveDraft = Boolean(draftArg && globalConfig.versions.drafts);
3032

3133
// /////////////////////////////////////
3234
// 1. Retrieve and execute access
3335
// /////////////////////////////////////
3436

35-
const accessResults = !overrideAccess ? await executeAccess({ req }, globalConfig.access.update) : true;
37+
const accessResults = !overrideAccess ? await executeAccess({ req, data }, globalConfig.access.update) : true;
3638

3739
// /////////////////////////////////////
3840
// Retrieve document
@@ -84,8 +86,6 @@ async function update<T extends TypeWithID = any>(this: Payload, args): Promise<
8486
showHiddenFields,
8587
});
8688

87-
let { data } = args;
88-
8989
// /////////////////////////////////////
9090
// beforeValidate - Fields
9191
// /////////////////////////////////////

0 commit comments

Comments
 (0)