diff --git a/packages/next/src/views/Edit/Default/index.tsx b/packages/next/src/views/Edit/Default/index.tsx index 0b4345141..7c1f6bd66 100644 --- a/packages/next/src/views/Edit/Default/index.tsx +++ b/packages/next/src/views/Edit/Default/index.tsx @@ -88,7 +88,7 @@ export const DefaultEditView: React.FC = () => { globalSlug: globalConfig?.slug, }) - const operation = id ? 'update' : 'create' + const operation = collectionSlug && !id ? 'create' : 'update' const auth = collectionConfig ? collectionConfig.auth : undefined const upload = collectionConfig ? collectionConfig.upload : undefined diff --git a/packages/ui/src/elements/DocumentFields/index.tsx b/packages/ui/src/elements/DocumentFields/index.tsx index 0ec5a4580..7d6d46181 100644 --- a/packages/ui/src/elements/DocumentFields/index.tsx +++ b/packages/ui/src/elements/DocumentFields/index.tsx @@ -63,7 +63,7 @@ export const DocumentFields: React.FC = ({ className={`${baseClass}__fields`} fieldMap={mainFields} path="" - permissions={docPermissions?.['fields']} + permissions={docPermissions?.fields} readOnly={readOnly} schemaPath={schemaPath} /> diff --git a/packages/ui/src/providers/DocumentInfo/index.tsx b/packages/ui/src/providers/DocumentInfo/index.tsx index e07215763..bb03fb96d 100644 --- a/packages/ui/src/providers/DocumentInfo/index.tsx +++ b/packages/ui/src/providers/DocumentInfo/index.tsx @@ -81,7 +81,7 @@ export const DocumentInfoProvider: React.FC< } } - const isEditing = Boolean(id) + const operation = collectionSlug && !id ? 'create' : 'update' const shouldFetchVersions = Boolean(versionsConfig && docPermissions?.readVersions?.permission) const getVersions = useCallback(async () => { @@ -286,7 +286,7 @@ export const DocumentInfoProvider: React.FC< docPreferences, globalSlug, locale, - operation: isEditing ? 'update' : 'create', + operation, schemaPath: collectionSlug || globalSlug, }, serverURL, @@ -301,7 +301,7 @@ export const DocumentInfoProvider: React.FC< getDocPreferences, globalSlug, id, - isEditing, + operation, locale, onSaveFromProps, serverURL, @@ -323,7 +323,7 @@ export const DocumentInfoProvider: React.FC< collectionSlug, globalSlug, locale, - operation: isEditing ? 'update' : 'create', + operation, schemaPath: collectionSlug || globalSlug, }, onError: onLoadError, @@ -353,7 +353,7 @@ export const DocumentInfoProvider: React.FC< } }, [ api, - isEditing, + operation, collectionSlug, serverURL, id, diff --git a/test/_community/config.ts b/test/_community/config.ts index 6af2188ed..cb68318a2 100644 --- a/test/_community/config.ts +++ b/test/_community/config.ts @@ -16,10 +16,10 @@ export default buildConfigWithDefaults({ PostsCollection, // MediaCollection ], - // globals: [ - // MenuGlobal, - // // ...add more globals here - // ], + globals: [ + MenuGlobal, + // ...add more globals here + ], cors: ['http://localhost:3000', 'http://localhost:3001'], onInit: async (payload) => { await payload.create({ diff --git a/test/access-control/config.ts b/test/access-control/config.ts index 2f921cda0..259d09121 100644 --- a/test/access-control/config.ts +++ b/test/access-control/config.ts @@ -10,6 +10,7 @@ import { hiddenAccessSlug, hiddenFieldsSlug, noAdminAccessEmail, + readOnlyGlobalSlug, readOnlySlug, relyOnRequestHeadersSlug, restrictedSlug, @@ -73,6 +74,19 @@ export default buildConfigWithDefaults({ }, }, }, + { + slug: readOnlyGlobalSlug, + fields: [ + { + name: 'name', + type: 'text', + }, + ], + access: { + read: () => true, + update: () => false, + }, + }, ], collections: [ { diff --git a/test/access-control/e2e.spec.ts b/test/access-control/e2e.spec.ts index b588e4a84..fc61ee15c 100644 --- a/test/access-control/e2e.spec.ts +++ b/test/access-control/e2e.spec.ts @@ -26,6 +26,7 @@ import { POLL_TOPASS_TIMEOUT } from '../playwright.config.js' import { docLevelAccessSlug, noAdminAccessEmail, + readOnlyGlobalSlug, readOnlySlug, restrictedSlug, restrictedVersionsSlug, @@ -50,7 +51,8 @@ describe('access control', () => { let page: Page let url: AdminUrlUtil let restrictedUrl: AdminUrlUtil - let readOnlyUrl: AdminUrlUtil + let readOnlyCollectionUrl: AdminUrlUtil + let readOnlyGlobalUrl: AdminUrlUtil let restrictedVersionsUrl: AdminUrlUtil let serverURL: string @@ -59,7 +61,8 @@ describe('access control', () => { url = new AdminUrlUtil(serverURL, slug) restrictedUrl = new AdminUrlUtil(serverURL, restrictedSlug) - readOnlyUrl = new AdminUrlUtil(serverURL, readOnlySlug) + readOnlyCollectionUrl = new AdminUrlUtil(serverURL, readOnlySlug) + readOnlyGlobalUrl = new AdminUrlUtil(serverURL, readOnlySlug) restrictedVersionsUrl = new AdminUrlUtil(serverURL, restrictedVersionsSlug) const context = await browser.newContext() @@ -175,12 +178,12 @@ describe('access control', () => { }) test('should have collection url', async () => { - await page.goto(readOnlyUrl.list) - await expect(page).toHaveURL(new RegExp(`${readOnlyUrl.list}.*`)) // will redirect to ?limit=10 at the end, so we have to use a wildcard at the end + await page.goto(readOnlyCollectionUrl.list) + await expect(page).toHaveURL(new RegExp(`${readOnlyCollectionUrl.list}.*`)) // will redirect to ?limit=10 at the end, so we have to use a wildcard at the end }) test('should not have "Create New" button', async () => { - await page.goto(readOnlyUrl.create) + await page.goto(readOnlyCollectionUrl.create) await expect(page.locator('.collection-list__header a')).toHaveCount(0) }) @@ -190,17 +193,20 @@ describe('access control', () => { }) test('edit view should not have actions buttons', async () => { - await page.goto(readOnlyUrl.edit(existingDoc.id)) + await page.goto(readOnlyCollectionUrl.edit(existingDoc.id)) await expect(page.locator('.collection-edit__collection-actions li')).toHaveCount(0) }) test('fields should be read-only', async () => { - await page.goto(readOnlyUrl.edit(existingDoc.id)) + await page.goto(readOnlyCollectionUrl.edit(existingDoc.id)) + await expect(page.locator('#field-name')).toBeDisabled() + + await page.goto(readOnlyGlobalUrl.global(readOnlyGlobalSlug)) await expect(page.locator('#field-name')).toBeDisabled() }) test('should not render dot menu popup when `create` and `delete` access control is set to false', async () => { - await page.goto(readOnlyUrl.edit(existingDoc.id)) + await page.goto(readOnlyCollectionUrl.edit(existingDoc.id)) await expect(page.locator('.collection-edit .doc-controls .doc-controls__popup')).toBeHidden() }) }) diff --git a/test/access-control/shared.ts b/test/access-control/shared.ts index 0063b6da2..5944244ef 100644 --- a/test/access-control/shared.ts +++ b/test/access-control/shared.ts @@ -4,6 +4,7 @@ export const secondArrayText = 'second-array-text' export const slug = 'posts' export const unrestrictedSlug = 'unrestricted' export const readOnlySlug = 'read-only-collection' +export const readOnlyGlobalSlug = 'read-only-global' export const userRestrictedSlug = 'user-restricted' export const restrictedSlug = 'restricted'