fix(next,ui): properly sets document operation for globals (#6116)
This commit is contained in:
@@ -88,7 +88,7 @@ export const DefaultEditView: React.FC = () => {
|
|||||||
globalSlug: globalConfig?.slug,
|
globalSlug: globalConfig?.slug,
|
||||||
})
|
})
|
||||||
|
|
||||||
const operation = id ? 'update' : 'create'
|
const operation = collectionSlug && !id ? 'create' : 'update'
|
||||||
|
|
||||||
const auth = collectionConfig ? collectionConfig.auth : undefined
|
const auth = collectionConfig ? collectionConfig.auth : undefined
|
||||||
const upload = collectionConfig ? collectionConfig.upload : undefined
|
const upload = collectionConfig ? collectionConfig.upload : undefined
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ export const DocumentFields: React.FC<Args> = ({
|
|||||||
className={`${baseClass}__fields`}
|
className={`${baseClass}__fields`}
|
||||||
fieldMap={mainFields}
|
fieldMap={mainFields}
|
||||||
path=""
|
path=""
|
||||||
permissions={docPermissions?.['fields']}
|
permissions={docPermissions?.fields}
|
||||||
readOnly={readOnly}
|
readOnly={readOnly}
|
||||||
schemaPath={schemaPath}
|
schemaPath={schemaPath}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -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 shouldFetchVersions = Boolean(versionsConfig && docPermissions?.readVersions?.permission)
|
||||||
|
|
||||||
const getVersions = useCallback(async () => {
|
const getVersions = useCallback(async () => {
|
||||||
@@ -286,7 +286,7 @@ export const DocumentInfoProvider: React.FC<
|
|||||||
docPreferences,
|
docPreferences,
|
||||||
globalSlug,
|
globalSlug,
|
||||||
locale,
|
locale,
|
||||||
operation: isEditing ? 'update' : 'create',
|
operation,
|
||||||
schemaPath: collectionSlug || globalSlug,
|
schemaPath: collectionSlug || globalSlug,
|
||||||
},
|
},
|
||||||
serverURL,
|
serverURL,
|
||||||
@@ -301,7 +301,7 @@ export const DocumentInfoProvider: React.FC<
|
|||||||
getDocPreferences,
|
getDocPreferences,
|
||||||
globalSlug,
|
globalSlug,
|
||||||
id,
|
id,
|
||||||
isEditing,
|
operation,
|
||||||
locale,
|
locale,
|
||||||
onSaveFromProps,
|
onSaveFromProps,
|
||||||
serverURL,
|
serverURL,
|
||||||
@@ -323,7 +323,7 @@ export const DocumentInfoProvider: React.FC<
|
|||||||
collectionSlug,
|
collectionSlug,
|
||||||
globalSlug,
|
globalSlug,
|
||||||
locale,
|
locale,
|
||||||
operation: isEditing ? 'update' : 'create',
|
operation,
|
||||||
schemaPath: collectionSlug || globalSlug,
|
schemaPath: collectionSlug || globalSlug,
|
||||||
},
|
},
|
||||||
onError: onLoadError,
|
onError: onLoadError,
|
||||||
@@ -353,7 +353,7 @@ export const DocumentInfoProvider: React.FC<
|
|||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
api,
|
api,
|
||||||
isEditing,
|
operation,
|
||||||
collectionSlug,
|
collectionSlug,
|
||||||
serverURL,
|
serverURL,
|
||||||
id,
|
id,
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ export default buildConfigWithDefaults({
|
|||||||
PostsCollection,
|
PostsCollection,
|
||||||
// MediaCollection
|
// MediaCollection
|
||||||
],
|
],
|
||||||
// globals: [
|
globals: [
|
||||||
// MenuGlobal,
|
MenuGlobal,
|
||||||
// // ...add more globals here
|
// ...add more globals here
|
||||||
// ],
|
],
|
||||||
cors: ['http://localhost:3000', 'http://localhost:3001'],
|
cors: ['http://localhost:3000', 'http://localhost:3001'],
|
||||||
onInit: async (payload) => {
|
onInit: async (payload) => {
|
||||||
await payload.create({
|
await payload.create({
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
hiddenAccessSlug,
|
hiddenAccessSlug,
|
||||||
hiddenFieldsSlug,
|
hiddenFieldsSlug,
|
||||||
noAdminAccessEmail,
|
noAdminAccessEmail,
|
||||||
|
readOnlyGlobalSlug,
|
||||||
readOnlySlug,
|
readOnlySlug,
|
||||||
relyOnRequestHeadersSlug,
|
relyOnRequestHeadersSlug,
|
||||||
restrictedSlug,
|
restrictedSlug,
|
||||||
@@ -73,6 +74,19 @@ export default buildConfigWithDefaults({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
slug: readOnlyGlobalSlug,
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: 'name',
|
||||||
|
type: 'text',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
access: {
|
||||||
|
read: () => true,
|
||||||
|
update: () => false,
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
collections: [
|
collections: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import { POLL_TOPASS_TIMEOUT } from '../playwright.config.js'
|
|||||||
import {
|
import {
|
||||||
docLevelAccessSlug,
|
docLevelAccessSlug,
|
||||||
noAdminAccessEmail,
|
noAdminAccessEmail,
|
||||||
|
readOnlyGlobalSlug,
|
||||||
readOnlySlug,
|
readOnlySlug,
|
||||||
restrictedSlug,
|
restrictedSlug,
|
||||||
restrictedVersionsSlug,
|
restrictedVersionsSlug,
|
||||||
@@ -50,7 +51,8 @@ describe('access control', () => {
|
|||||||
let page: Page
|
let page: Page
|
||||||
let url: AdminUrlUtil
|
let url: AdminUrlUtil
|
||||||
let restrictedUrl: AdminUrlUtil
|
let restrictedUrl: AdminUrlUtil
|
||||||
let readOnlyUrl: AdminUrlUtil
|
let readOnlyCollectionUrl: AdminUrlUtil
|
||||||
|
let readOnlyGlobalUrl: AdminUrlUtil
|
||||||
let restrictedVersionsUrl: AdminUrlUtil
|
let restrictedVersionsUrl: AdminUrlUtil
|
||||||
let serverURL: string
|
let serverURL: string
|
||||||
|
|
||||||
@@ -59,7 +61,8 @@ describe('access control', () => {
|
|||||||
|
|
||||||
url = new AdminUrlUtil(serverURL, slug)
|
url = new AdminUrlUtil(serverURL, slug)
|
||||||
restrictedUrl = new AdminUrlUtil(serverURL, restrictedSlug)
|
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)
|
restrictedVersionsUrl = new AdminUrlUtil(serverURL, restrictedVersionsSlug)
|
||||||
|
|
||||||
const context = await browser.newContext()
|
const context = await browser.newContext()
|
||||||
@@ -175,12 +178,12 @@ describe('access control', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('should have collection url', async () => {
|
test('should have collection url', async () => {
|
||||||
await page.goto(readOnlyUrl.list)
|
await page.goto(readOnlyCollectionUrl.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 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 () => {
|
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)
|
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 () => {
|
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)
|
await expect(page.locator('.collection-edit__collection-actions li')).toHaveCount(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('fields should be read-only', async () => {
|
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()
|
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 () => {
|
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()
|
await expect(page.locator('.collection-edit .doc-controls .doc-controls__popup')).toBeHidden()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ export const secondArrayText = 'second-array-text'
|
|||||||
export const slug = 'posts'
|
export const slug = 'posts'
|
||||||
export const unrestrictedSlug = 'unrestricted'
|
export const unrestrictedSlug = 'unrestricted'
|
||||||
export const readOnlySlug = 'read-only-collection'
|
export const readOnlySlug = 'read-only-collection'
|
||||||
|
export const readOnlyGlobalSlug = 'read-only-global'
|
||||||
|
|
||||||
export const userRestrictedSlug = 'user-restricted'
|
export const userRestrictedSlug = 'user-restricted'
|
||||||
export const restrictedSlug = 'restricted'
|
export const restrictedSlug = 'restricted'
|
||||||
|
|||||||
Reference in New Issue
Block a user