Compare commits

..

8 Commits

Author SHA1 Message Date
Dan Ribbens
44231b55cb fix(db-mongodb): error querying with invalid value on date field 2024-01-15 13:48:56 -05:00
James Mikrut
f9dda628b2 Merge pull request #4730 from payloadcms/feat/4471-add-validation-for-form-submission
feat(plugin-form-builder):Add validation for form ID when creating a form submissions
2024-01-12 15:39:35 -05:00
Elliot DeNolf
93eb0e4a31 chore: update bug report template to renamed possible-bug label 2024-01-12 14:19:43 -05:00
Elliot DeNolf
2e362f44f4 chore(release): payload/2.8.1 [skip ci] 2024-01-12 12:44:15 -05:00
Jarrod Flesch
775502b161 fix: corrects config usage in build bin script (#4796) 2024-01-12 12:40:08 -05:00
Elliot DeNolf
84d75ce6ca chore(release): plugin-form-builder/1.1.2 [skip ci] 2024-01-12 10:47:08 -05:00
Elliot DeNolf
175cf229c0 chore(release): richtext-lexical/0.5.2 [skip ci] 2024-01-12 10:41:55 -05:00
Paul Popus
2b731c1088 feat(plugin-form-builder):Add validation for form ID when creating a submission 2024-01-08 20:35:52 -03:00
11 changed files with 94 additions and 15 deletions

View File

@@ -1,6 +1,6 @@
name: Bug Report
description: Create a bug report for Payload
labels: ['possible-bug']
labels: ['[possible-bug]']
body:
- type: markdown
attributes:

View File

@@ -1,3 +1,10 @@
## [2.8.1](https://github.com/payloadcms/payload/compare/v2.8.0...v2.8.1) (2024-01-12)
### Bug Fixes
* corrects config usage in build bin script ([#4796](https://github.com/payloadcms/payload/issues/4796)) ([775502b](https://github.com/payloadcms/payload/commit/775502b1616c1bd35a3044438e253a0e84219f99))
## [2.8.0](https://github.com/payloadcms/payload/compare/v2.7.0...v2.8.0) (2024-01-12)

View File

@@ -65,7 +65,8 @@ export const sanitizeQueryValue = ({
if (field.type === 'date' && typeof val === 'string') {
formattedValue = new Date(val)
if (Number.isNaN(Date.parse(formattedValue))) {
return undefined
// ignore invalid query
return { rawQuery: {} }
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "payload",
"version": "2.8.0",
"version": "2.8.1",
"description": "Node, React and MongoDB Headless CMS and Application Framework",
"license": "MIT",
"main": "./dist/index.js",

View File

@@ -1,10 +1,9 @@
import payload from '..'
import loadConfig from '../config/load'
export const build = async (): Promise<void> => {
const config = await loadConfig() // Will throw its own error if it fails
await payload.config.admin.bundler.build(config)
await config.admin.bundler.build(config)
}
// when build.js is launched directly

View File

@@ -1,7 +1,7 @@
{
"name": "@payloadcms/plugin-form-builder",
"description": "Form builder plugin for Payload CMS",
"version": "1.1.1",
"version": "1.1.2",
"homepage:": "https://payloadcms.com",
"repository": "git@github.com:payloadcms/plugin-form-builder.git",
"main": "dist/index.js",

View File

@@ -7,6 +7,8 @@ import sendEmail from './hooks/sendEmail'
// all settings can be overridden by the config
export const generateSubmissionCollection = (formConfig: PluginConfig): CollectionConfig => {
const formSlug = formConfig?.formOverrides?.slug || 'forms'
const newConfig: CollectionConfig = {
...(formConfig?.formSubmissionOverrides || {}),
access: {
@@ -25,9 +27,28 @@ export const generateSubmissionCollection = (formConfig: PluginConfig): Collecti
admin: {
readOnly: true,
},
relationTo: formConfig?.formOverrides?.slug || 'forms',
relationTo: formSlug,
required: true,
type: 'relationship',
validate: async (value, { payload }) => {
/* Don't run in the client side */
if (!payload) return true
if (payload) {
let existingForm
try {
existingForm = await payload.findByID({
id: value,
collection: formSlug,
})
return true
} catch (error) {
return 'Cannot create this submission because this form does not exist.'
}
}
},
},
{
name: 'submissionData',

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/richtext-lexical",
"version": "0.5.1",
"version": "0.5.2",
"description": "The officially supported Lexical richtext adapter for Payload",
"repository": "https://github.com/payloadcms/payload",
"license": "MIT",

View File

@@ -100,8 +100,8 @@ describe('Fields', () => {
const { id } = await payload.create({
collection: 'text-fields',
data: {
text,
localizedHasMany,
text,
},
locale: 'en',
})
@@ -112,7 +112,7 @@ describe('Fields', () => {
})
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// @ts-expect-error
expect(localizedDoc.localizedHasMany.en).toEqual(localizedHasMany)
})
})
@@ -257,6 +257,20 @@ describe('Fields', () => {
expect(docs.map(({ id }) => id)).toContain(doc.id)
})
it('should not error using invalid date query', async () => {
const { result, status } = await client.find({
slug: 'date-fields',
query: {
updatedAt: {
like: 'invalid',
},
},
})
expect(status).toStrictEqual(200)
expect(result.docs).toBeDefined()
})
it('should query createdAt', async () => {
const result = await payload.find({
collection: 'date-fields',
@@ -268,7 +282,7 @@ describe('Fields', () => {
},
})
expect(result.docs[0].id).toEqual(doc.id)
expect(result.docs[0].id).toStrictEqual(doc.id)
})
})
@@ -413,7 +427,7 @@ describe('Fields', () => {
})
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// @ts-expect-error
expect(localizedDoc.localizedHasMany.en).toEqual(localizedHasMany)
})
})
@@ -1183,8 +1197,8 @@ describe('Fields', () => {
expect(nodes).toBeDefined()
const child = nodes.flatMap((n) => n.children).find((c) => c.doc)
expect(child).toMatchObject({
linkType: 'internal',
type: 'link',
linkType: 'internal',
})
expect(child.doc.relationTo).toEqual('array-fields')

View File

@@ -5,6 +5,7 @@ import { serializeLexical } from '../../packages/plugin-form-builder/src/utiliti
import { serializeSlate } from '../../packages/plugin-form-builder/src/utilities/slate/serializeSlate'
import { initPayloadTest } from '../helpers/configHelpers'
import { formSubmissionsSlug, formsSlug } from './shared'
import { ValidationError } from '../../packages/payload/src/errors'
describe('Form Builder Plugin', () => {
let form: Form
@@ -42,7 +43,7 @@ describe('Form Builder Plugin', () => {
it('adds form submissions collection', async () => {
const { docs: formSubmissions } = await payload.find({ collection: formSubmissionsSlug })
expect(formSubmissions).toHaveLength(0)
expect(formSubmissions).toHaveLength(1)
})
})
@@ -118,6 +119,25 @@ describe('Form Builder Plugin', () => {
expect(formSubmission.submissionData[0]).toHaveProperty('value', 'Test Submission')
})
it('does not create a form submission for a non-existing form', async () => {
const req = async () =>
payload.create({
collection: formSubmissionsSlug,
data: {
form: '659c7c2f98ffb5d83df9dadb',
submissionData: [
{
field: 'name',
value: 'Test Submission',
},
],
},
depth: 0,
})
await expect(req).rejects.toThrow(ValidationError)
})
it('replaces curly braces with data when using slate serializer', async () => {
const mockName = 'Test Submission'
const mockEmail = 'dev@payloadcms.com'

View File

@@ -1,7 +1,7 @@
import type { Payload } from '../../../packages/payload/src'
import type { PayloadRequest } from '../../../packages/payload/src/express/types'
import { formsSlug, pagesSlug } from '../shared'
import { formSubmissionsSlug, formsSlug, pagesSlug } from '../shared'
export const seed = async (payload: Payload): Promise<boolean> => {
payload.logger.info('Seeding data...')
@@ -53,6 +53,23 @@ export const seed = async (payload: Payload): Promise<boolean> => {
},
})
await payload.create({
collection: formSubmissionsSlug,
data: {
form: formID,
submissionData: [
{
field: 'name',
value: 'Test Submission',
},
{
field: 'email',
value: 'tester@example.com',
},
],
},
})
await payload.create({
collection: pagesSlug,
data: {