Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/payload/src/collections/operations/updateByID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ export const updateByIDOperation = async <

if (isTrashAttempt && !overrideAccess) {
// Pass data so access function can check data.deletedAt to know it's a trash attempt
const deleteAccessResult = await executeAccess({ data, req }, collectionConfig.access.delete)
const deleteAccessResult = await executeAccess(
{ id, data, req },
collectionConfig.access.delete,
)
fullWhere = combineQueries(fullWhere, deleteAccessResult)
}

Expand Down
11 changes: 10 additions & 1 deletion test/trash/collections/DifferentiatedTrashCollection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import type { CollectionConfig } from 'payload'

export const differentiatedTrashCollectionSlug = 'differentiated-trash-collection'

/**
* Captures the `id` argument received by the `delete` access control function
* on the most recent invocation, so tests can assert it was passed through
* for soft-delete (trash) attempts.
*/
export let lastDeleteAccessID: number | string | undefined

export const DifferentiatedTrashCollection: CollectionConfig = {
slug: differentiatedTrashCollectionSlug,
admin: {
Expand All @@ -19,7 +26,9 @@ export const DifferentiatedTrashCollection: CollectionConfig = {
* - Admins: Can both trash and permanently delete
*/
access: {
delete: ({ req: { user }, data }) => {
delete: ({ id, req: { user }, data }) => {
lastDeleteAccessID = id

// Not logged in - no access
if (!user) {
return false
Expand Down
6 changes: 5 additions & 1 deletion test/trash/int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import type { DifferentiatedTrashCollection, Post, RestrictedCollection } from '
import { idToString } from '../__helpers/shared/idToString.js'
import { initPayloadInt } from '../__helpers/shared/initPayloadInt.js'
import { devUser, regularUser } from '../credentials.js'
import { differentiatedTrashCollectionSlug } from './collections/DifferentiatedTrashCollection/index.js'
import {
differentiatedTrashCollectionSlug,
lastDeleteAccessID,
} from './collections/DifferentiatedTrashCollection/index.js'
import { pagesSlug } from './collections/Pages/index.js'
import { postsSlug } from './collections/Posts/index.js'
import { restrictedCollectionSlug } from './collections/RestrictedCollection/index.js'
Expand Down Expand Up @@ -195,6 +198,7 @@ describe('trash', () => {
})

expect(trashedDoc.deletedAt).toBeDefined()
expect(lastDeleteAccessID).toBe(doc.id)
})

it('should allow admin to trash (soft-delete) a document', async () => {
Expand Down
Loading