fix: versions not loading properly (#11256)
### What? The admin panel was not respecting where constraints returned from the readAccess function. ### Why? `getEntityPolicies` was always using `find` when looping over the operations, but `readVersions` should be using `findVersions`. ### How? When the operation is `readVersions` run the `findVersions` operation. Fixes https://github.com/payloadcms/payload/issues/11240
This commit is contained in:
@@ -22,14 +22,13 @@ import {
|
||||
hiddenAccessSlug,
|
||||
hiddenFieldsSlug,
|
||||
nonAdminEmail,
|
||||
nonAdminUserEmail,
|
||||
nonAdminUserSlug,
|
||||
publicUserEmail,
|
||||
publicUsersSlug,
|
||||
readNotUpdateGlobalSlug,
|
||||
readOnlyGlobalSlug,
|
||||
readOnlySlug,
|
||||
relyOnRequestHeadersSlug,
|
||||
restrictedVersionsAdminPanelSlug,
|
||||
restrictedVersionsSlug,
|
||||
secondArrayText,
|
||||
siblingDataSlug,
|
||||
@@ -324,6 +323,35 @@ export default buildConfigWithDefaults(
|
||||
],
|
||||
versions: true,
|
||||
},
|
||||
{
|
||||
slug: restrictedVersionsAdminPanelSlug,
|
||||
access: {
|
||||
read: ({ req: { user } }) => {
|
||||
if (user) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
},
|
||||
readVersions: () => {
|
||||
return {
|
||||
'version.hidden': {
|
||||
not_equals: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: 'name',
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
name: 'hidden',
|
||||
type: 'checkbox',
|
||||
},
|
||||
],
|
||||
versions: true,
|
||||
},
|
||||
{
|
||||
slug: siblingDataSlug,
|
||||
access: openAccess,
|
||||
|
||||
@@ -35,6 +35,7 @@ import {
|
||||
readNotUpdateGlobalSlug,
|
||||
readOnlyGlobalSlug,
|
||||
readOnlySlug,
|
||||
restrictedVersionsAdminPanelSlug,
|
||||
restrictedVersionsSlug,
|
||||
slug,
|
||||
unrestrictedSlug,
|
||||
@@ -63,6 +64,7 @@ describe('Access Control', () => {
|
||||
let richTextUrl: AdminUrlUtil
|
||||
let readOnlyGlobalUrl: AdminUrlUtil
|
||||
let restrictedVersionsUrl: AdminUrlUtil
|
||||
let restrictedVersionsAdminPanelUrl: AdminUrlUtil
|
||||
let userRestrictedCollectionURL: AdminUrlUtil
|
||||
let userRestrictedGlobalURL: AdminUrlUtil
|
||||
let disabledFields: AdminUrlUtil
|
||||
@@ -81,6 +83,7 @@ describe('Access Control', () => {
|
||||
readOnlyCollectionUrl = new AdminUrlUtil(serverURL, readOnlySlug)
|
||||
readOnlyGlobalUrl = new AdminUrlUtil(serverURL, readOnlySlug)
|
||||
restrictedVersionsUrl = new AdminUrlUtil(serverURL, restrictedVersionsSlug)
|
||||
restrictedVersionsAdminPanelUrl = new AdminUrlUtil(serverURL, restrictedVersionsAdminPanelSlug)
|
||||
userRestrictedCollectionURL = new AdminUrlUtil(serverURL, userRestrictedCollectionSlug)
|
||||
userRestrictedGlobalURL = new AdminUrlUtil(serverURL, userRestrictedGlobalSlug)
|
||||
disabledFields = new AdminUrlUtil(serverURL, disabledSlug)
|
||||
@@ -557,16 +560,26 @@ describe('Access Control', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
existingDoc = await payload.create({
|
||||
collection: restrictedVersionsSlug,
|
||||
collection: restrictedVersionsAdminPanelSlug,
|
||||
data: {
|
||||
name: 'name',
|
||||
},
|
||||
})
|
||||
|
||||
await payload.update({
|
||||
collection: restrictedVersionsAdminPanelSlug,
|
||||
id: existingDoc.id,
|
||||
data: {
|
||||
hidden: true,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test('versions sidebar should not show', async () => {
|
||||
await page.goto(restrictedVersionsUrl.edit(existingDoc.id))
|
||||
await expect(page.locator('.versions-count')).toBeHidden()
|
||||
test('versions tab should not show', async () => {
|
||||
await page.goto(restrictedVersionsAdminPanelUrl.edit(existingDoc.id))
|
||||
await page.locator('.doc-tabs__tabs').getByLabel('Versions').click()
|
||||
const rows = page.locator('.versions table tbody tr')
|
||||
await expect(rows).toHaveCount(1)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -6,66 +6,11 @@
|
||||
* and re-run `payload generate:types` to regenerate this file.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Supported timezones in IANA format.
|
||||
*
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "supportedTimezones".
|
||||
*/
|
||||
export type SupportedTimezones =
|
||||
| 'Pacific/Midway'
|
||||
| 'Pacific/Niue'
|
||||
| 'Pacific/Honolulu'
|
||||
| 'Pacific/Rarotonga'
|
||||
| 'America/Anchorage'
|
||||
| 'Pacific/Gambier'
|
||||
| 'America/Los_Angeles'
|
||||
| 'America/Tijuana'
|
||||
| 'America/Denver'
|
||||
| 'America/Phoenix'
|
||||
| 'America/Chicago'
|
||||
| 'America/Guatemala'
|
||||
| 'America/New_York'
|
||||
| 'America/Bogota'
|
||||
| 'America/Caracas'
|
||||
| 'America/Santiago'
|
||||
| 'America/Buenos_Aires'
|
||||
| 'America/Sao_Paulo'
|
||||
| 'Atlantic/South_Georgia'
|
||||
| 'Atlantic/Azores'
|
||||
| 'Atlantic/Cape_Verde'
|
||||
| 'Europe/London'
|
||||
| 'Europe/Berlin'
|
||||
| 'Africa/Lagos'
|
||||
| 'Europe/Athens'
|
||||
| 'Africa/Cairo'
|
||||
| 'Europe/Moscow'
|
||||
| 'Asia/Riyadh'
|
||||
| 'Asia/Dubai'
|
||||
| 'Asia/Baku'
|
||||
| 'Asia/Karachi'
|
||||
| 'Asia/Tashkent'
|
||||
| 'Asia/Calcutta'
|
||||
| 'Asia/Dhaka'
|
||||
| 'Asia/Almaty'
|
||||
| 'Asia/Jakarta'
|
||||
| 'Asia/Bangkok'
|
||||
| 'Asia/Shanghai'
|
||||
| 'Asia/Singapore'
|
||||
| 'Asia/Tokyo'
|
||||
| 'Asia/Seoul'
|
||||
| 'Australia/Sydney'
|
||||
| 'Pacific/Guam'
|
||||
| 'Pacific/Noumea'
|
||||
| 'Pacific/Auckland'
|
||||
| 'Pacific/Fiji';
|
||||
|
||||
export interface Config {
|
||||
auth: {
|
||||
users: UserAuthOperations;
|
||||
'public-users': PublicUserAuthOperations;
|
||||
};
|
||||
blocks: {};
|
||||
collections: {
|
||||
users: User;
|
||||
'public-users': PublicUser;
|
||||
@@ -77,6 +22,7 @@ export interface Config {
|
||||
'user-restricted-collection': UserRestrictedCollection;
|
||||
'create-not-update-collection': CreateNotUpdateCollection;
|
||||
'restricted-versions': RestrictedVersion;
|
||||
'restricted-versions-admin-panel': RestrictedVersionsAdminPanel;
|
||||
'sibling-data': SiblingDatum;
|
||||
'rely-on-request-headers': RelyOnRequestHeader;
|
||||
'doc-level-access': DocLevelAccess;
|
||||
@@ -104,6 +50,7 @@ export interface Config {
|
||||
'user-restricted-collection': UserRestrictedCollectionSelect<false> | UserRestrictedCollectionSelect<true>;
|
||||
'create-not-update-collection': CreateNotUpdateCollectionSelect<false> | CreateNotUpdateCollectionSelect<true>;
|
||||
'restricted-versions': RestrictedVersionsSelect<false> | RestrictedVersionsSelect<true>;
|
||||
'restricted-versions-admin-panel': RestrictedVersionsAdminPanelSelect<false> | RestrictedVersionsAdminPanelSelect<true>;
|
||||
'sibling-data': SiblingDataSelect<false> | SiblingDataSelect<true>;
|
||||
'rely-on-request-headers': RelyOnRequestHeadersSelect<false> | RelyOnRequestHeadersSelect<true>;
|
||||
'doc-level-access': DocLevelAccessSelect<false> | DocLevelAccessSelect<true>;
|
||||
@@ -309,6 +256,17 @@ export interface RestrictedVersion {
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "restricted-versions-admin-panel".
|
||||
*/
|
||||
export interface RestrictedVersionsAdminPanel {
|
||||
id: string;
|
||||
name?: string | null;
|
||||
hidden?: boolean | null;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "sibling-data".
|
||||
@@ -714,6 +672,10 @@ export interface PayloadLockedDocument {
|
||||
relationTo: 'restricted-versions';
|
||||
value: string | RestrictedVersion;
|
||||
} | null)
|
||||
| ({
|
||||
relationTo: 'restricted-versions-admin-panel';
|
||||
value: string | RestrictedVersionsAdminPanel;
|
||||
} | null)
|
||||
| ({
|
||||
relationTo: 'sibling-data';
|
||||
value: string | SiblingDatum;
|
||||
@@ -924,6 +886,16 @@ export interface RestrictedVersionsSelect<T extends boolean = true> {
|
||||
updatedAt?: T;
|
||||
createdAt?: T;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "restricted-versions-admin-panel_select".
|
||||
*/
|
||||
export interface RestrictedVersionsAdminPanelSelect<T extends boolean = true> {
|
||||
name?: T;
|
||||
hidden?: T;
|
||||
updatedAt?: T;
|
||||
createdAt?: T;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "sibling-data_select".
|
||||
|
||||
@@ -12,6 +12,7 @@ export const createNotUpdateCollectionSlug = 'create-not-update-collection'
|
||||
export const userRestrictedGlobalSlug = 'user-restricted-global'
|
||||
export const readNotUpdateGlobalSlug = 'read-not-update-global'
|
||||
export const restrictedVersionsSlug = 'restricted-versions'
|
||||
export const restrictedVersionsAdminPanelSlug = 'restricted-versions-admin-panel'
|
||||
export const siblingDataSlug = 'sibling-data'
|
||||
export const relyOnRequestHeadersSlug = 'rely-on-request-headers'
|
||||
export const docLevelAccessSlug = 'doc-level-access'
|
||||
|
||||
Reference in New Issue
Block a user