fix: edit join field not rendering (#9971)

In PR #9930 we added `overrideAccess: false` to the find operation and
failed to pass the user. This caused
https://github.com/payloadcms/payload/issues/9974 where any access
control causes the edit view to error.

The fix was to pass the user through.

This change also adds Join Field e2e tests to the CI pipeline which was
previously missing and would have caught the error.
This commit is contained in:
Dan Ribbens
2024-12-14 08:19:53 -05:00
committed by GitHub
parent 050ff8409c
commit f5516b96da
4 changed files with 26 additions and 16 deletions

View File

@@ -283,6 +283,7 @@ jobs:
- admin-root - admin-root
- auth - auth
- auth-basic - auth-basic
- joins
- field-error-states - field-error-states
- fields-relationship - fields-relationship
- fields__collections__Array - fields__collections__Array

View File

@@ -211,6 +211,7 @@ export const buildTableState = async (
overrideAccess: false, overrideAccess: false,
page: query?.page ? parseInt(query.page, 10) : undefined, page: query?.page ? parseInt(query.page, 10) : undefined,
sort: query?.sort, sort: query?.sort,
user: req.user,
where: query?.where, where: query?.where,
}) })

View File

@@ -26,11 +26,12 @@ const dirname = path.dirname(filename)
let payload: PayloadTestSDK<Config> let payload: PayloadTestSDK<Config>
let serverURL: string let serverURL: string
test.describe('Admin Panel', () => { test.describe('Join Field', () => {
let page: Page let page: Page
let categoriesURL: AdminUrlUtil let categoriesURL: AdminUrlUtil
let uploadsURL: AdminUrlUtil let uploadsURL: AdminUrlUtil
let categoriesJoinRestrictedURL: AdminUrlUtil let categoriesJoinRestrictedURL: AdminUrlUtil
let categoryID
test.beforeAll(async ({ browser }, testInfo) => { test.beforeAll(async ({ browser }, testInfo) => {
testInfo.setTimeout(TEST_TIMEOUT_LONG) testInfo.setTimeout(TEST_TIMEOUT_LONG)
@@ -40,6 +41,16 @@ test.describe('Admin Panel', () => {
categoriesURL = new AdminUrlUtil(serverURL, categoriesSlug) categoriesURL = new AdminUrlUtil(serverURL, categoriesSlug)
uploadsURL = new AdminUrlUtil(serverURL, uploadsSlug) uploadsURL = new AdminUrlUtil(serverURL, uploadsSlug)
categoriesJoinRestrictedURL = new AdminUrlUtil(serverURL, categoriesJoinRestrictedSlug) categoriesJoinRestrictedURL = new AdminUrlUtil(serverURL, categoriesJoinRestrictedSlug)
const { docs } = await payload.find({
collection: categoriesSlug,
where: {
name: {
equals: 'example',
},
},
})
;({ id: categoryID } = docs[0])
const context = await browser.newContext() const context = await browser.newContext()
page = await context.newPage() page = await context.newPage()
@@ -111,8 +122,8 @@ test.describe('Admin Panel', () => {
const joinField = page.locator('#field-hiddenPosts.field-type.join') const joinField = page.locator('#field-hiddenPosts.field-type.join')
await expect(joinField).toBeVisible() await expect(joinField).toBeVisible()
await expect(joinField.locator('.relationship-table table')).toBeVisible() await expect(joinField.locator('.relationship-table table')).toBeVisible()
const columns = await joinField.locator('.relationship-table tbody tr').count() const columns = joinField.locator('.relationship-table tbody tr')
expect(columns).toBe(1) await expect(columns).toHaveCount(1)
const button = joinField.locator('button.doc-drawer__toggler.relationship-table__add-new') const button = joinField.locator('button.doc-drawer__toggler.relationship-table__add-new')
await expect(button).toBeVisible() await expect(button).toBeVisible()
await button.click() await button.click()
@@ -122,9 +133,7 @@ test.describe('Admin Panel', () => {
await expect(titleField).toBeVisible() await expect(titleField).toBeVisible()
await titleField.fill('Test Hidden Post') await titleField.fill('Test Hidden Post')
await drawer.locator('button[id="action-save"]').click() await drawer.locator('button[id="action-save"]').click()
await expect(joinField.locator('.relationship-table tbody tr')).toBeVisible() await expect(joinField.locator('.relationship-table tbody tr.row-2')).toBeVisible()
const newColumns = await joinField.locator('.relationship-table tbody tr').count()
expect(newColumns).toBe(2)
}) })
test('should render the create page and create doc with the join field', async () => { test('should render the create page and create doc with the join field', async () => {
@@ -152,11 +161,10 @@ test.describe('Admin Panel', () => {
}) })
test('should render collection type in first column of relationship table', async () => { test('should render collection type in first column of relationship table', async () => {
await navigateToDoc(page, categoriesURL) await page.goto(categoriesURL.edit(categoryID))
const joinField = page.locator('#field-relatedPosts.field-type.join') const joinField = page.locator('#field-relatedPosts.field-type.join')
await expect(joinField).toBeVisible() await expect(joinField).toBeVisible()
const collectionTypeColumn = joinField.locator('thead tr th#heading-collection:first-child') const text = joinField.locator('thead tr th#heading-collection:first-child')
const text = collectionTypeColumn
await expect(text).toHaveText('Type') await expect(text).toHaveText('Type')
const cells = joinField.locator('.relationship-table tbody tr td:first-child .pill__label') const cells = joinField.locator('.relationship-table tbody tr td:first-child .pill__label')
@@ -171,7 +179,7 @@ test.describe('Admin Panel', () => {
}) })
test('should render drawer toggler without document link in second column of relationship table', async () => { test('should render drawer toggler without document link in second column of relationship table', async () => {
await navigateToDoc(page, categoriesURL) await page.goto(categoriesURL.edit(categoryID))
const joinField = page.locator('#field-relatedPosts.field-type.join') const joinField = page.locator('#field-relatedPosts.field-type.join')
await expect(joinField).toBeVisible() await expect(joinField).toBeVisible()
const actionColumn = joinField.locator('tbody tr td:nth-child(2)').first() const actionColumn = joinField.locator('tbody tr td:nth-child(2)').first()
@@ -203,8 +211,8 @@ test.describe('Admin Panel', () => {
}) })
test('should sort relationship table by clicking on column headers', async () => { test('should sort relationship table by clicking on column headers', async () => {
await navigateToDoc(page, categoriesURL) await page.goto(categoriesURL.edit(categoryID))
const joinField = page.locator('#field-relatedPosts.field-type.join') const joinField = page.locator('#field-group__relatedPosts.field-type.join')
await expect(joinField).toBeVisible() await expect(joinField).toBeVisible()
const titleColumn = joinField.locator('thead tr th#heading-title') const titleColumn = joinField.locator('thead tr th#heading-title')
const titleAscButton = titleColumn.locator('button.sort-column__asc') const titleAscButton = titleColumn.locator('button.sort-column__asc')
@@ -223,7 +231,7 @@ test.describe('Admin Panel', () => {
}) })
test('should update relationship table when new document is created', async () => { test('should update relationship table when new document is created', async () => {
await navigateToDoc(page, categoriesURL) await page.goto(categoriesURL.edit(categoryID))
const joinField = page.locator('#field-relatedPosts.field-type.join') const joinField = page.locator('#field-relatedPosts.field-type.join')
await expect(joinField).toBeVisible() await expect(joinField).toBeVisible()
@@ -253,8 +261,8 @@ test.describe('Admin Panel', () => {
}) })
test('should update relationship table when document is updated', async () => { test('should update relationship table when document is updated', async () => {
await navigateToDoc(page, categoriesURL) await page.goto(categoriesURL.edit(categoryID))
const joinField = page.locator('#field-relatedPosts.field-type.join') const joinField = page.locator('#field-group__relatedPosts.field-type.join')
await expect(joinField).toBeVisible() await expect(joinField).toBeVisible()
const editButton = joinField.locator( const editButton = joinField.locator(
'tbody tr:first-child td:nth-child(2) button.doc-drawer__toggler', 'tbody tr:first-child td:nth-child(2) button.doc-drawer__toggler',

View File

@@ -307,7 +307,7 @@ export interface CollectionRestricted {
id: string; id: string;
title?: string | null; title?: string | null;
canRead?: boolean | null; canRead?: boolean | null;
category?: (string | null) | RestrictedCategory; category?: (string | null) | CategoriesJoinRestricted;
updatedAt: string; updatedAt: string;
createdAt: string; createdAt: string;
} }