Skip to content
Merged
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
30 changes: 30 additions & 0 deletions pages/dev/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2390,6 +2390,36 @@ describe('Request context is forwarded to nested findByID calls during breadcrum
// The custom context property should be forwarded through to the nested call
expect(reqArg!.context).toHaveProperty('customProperty', 'test-value')
})

test('breadcrumbs include parent data even when access control would deny reading the parent', async () => {
// Create a child page while passing a context flag that restricts read access.
// The pages collection's read access control denies access when restrictPageAccess is true.
// The beforeChange hook internally fetches the parent for breadcrumb computation.
// Because that internal fetch uses overrideAccess: true, it bypasses the restriction
// and breadcrumbs are still computed correctly.
const childPage = await payload.create({
collection: 'pages',
locale: 'de',
data: {
title: 'Access Control Child',
slug: 'access-control-child',
content: 'child',
parent: parentPage.id,
...virtualFields,
},
context: { restrictPageAccess: true },
})

expect(childPage.breadcrumbs).toHaveLength(2)
expect(removeIdsFromArray(childPage.breadcrumbs!)).toEqual([
{ slug: 'context-parent', label: 'Context Parent', path: '/de/context-parent' },
{
slug: 'access-control-child',
label: 'Access Control Child',
path: '/de/context-parent/access-control-child',
},
])
})
})

/**
Expand Down
3 changes: 3 additions & 0 deletions pages/dev/src/collections/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { captureAfterChangeDoc } from '../test/afterChangeCapture'

export const Pages: PageCollectionConfig = {
slug: 'pages',
access: {
read: ({ req }) => (req.context as Record<string, unknown>)?.restrictPageAccess !== true,
},
admin: {
useAsTitle: 'title',
},
Expand Down
1 change: 1 addition & 0 deletions pages/src/utils/getBreadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ async function findByIDCached({
depth: 0,
disableErrors: true,
locale,
overrideAccess: true,
req: {
...req,
context: { ...req.context, [ANCESTOR_CACHE_KEY]: cache },
Expand Down
Loading