Skip to content

Commit

Permalink
Fixes 400s getting thrown from missing circular id or createdOn date
Browse files Browse the repository at this point in the history
  • Loading branch information
dakota002 authored and lpsinger committed Jun 13, 2024
1 parent 0726e62 commit 95f3360
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
12 changes: 7 additions & 5 deletions app/routes/circulars._archive._index/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,17 @@ export async function action({ request }: ActionFunctionArgs) {
case 'correction':
if (circularId === undefined)
throw new Response('circularId is required', { status: 400 })

if (!user?.name || !user.email) throw new Response(null, { status: 403 })
let submitter, createdOnDate, createdOnTime, createdOn
let submitter
if (user.groups.includes(moderatorGroup)) {
submitter = getFormDataString(data, 'submitter')
createdOnDate = getFormDataString(data, 'createdOnDate')
createdOnTime = getFormDataString(data, 'createdOnTime')
createdOn = Date.parse(`${createdOnDate} ${createdOnTime} UTC`)
if (!submitter) throw new Response(null, { status: 400 })
}
if (!submitter || !createdOnDate || !createdOnTime || !createdOn)
const createdOnDate = getFormDataString(data, 'createdOnDate')
const createdOnTime = getFormDataString(data, 'createdOnTime')
const createdOn = Date.parse(`${createdOnDate} ${createdOnTime} UTC`)
if (!createdOnDate || !createdOnTime || !createdOn)
throw new Response(null, { status: 400 })
await createChangeRequest(
{
Expand Down
2 changes: 1 addition & 1 deletion app/routes/circulars.edit.$circularId/CircularEditForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ export function CircularEditForm({
)}
<Form method="POST" action={`/circulars${formSearchString}`}>
<input type="hidden" name="intent" value={intent} />
<input type="hidden" name="circularId" value={circularId} />
{circularId !== undefined && userIsModerator && (
<>
<input type="hidden" name="circularId" value={circularId} />
<InputGroup
className={classnames('maxw-full', {
'usa-input--error': !submitterValid,
Expand Down
15 changes: 10 additions & 5 deletions app/routes/circulars/circulars.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,16 @@ export async function getVersions(circularId: number): Promise<number[]> {
export async function createChangeRequest(
item: Omit<
Circular,
'sub' | 'submittedHow' | 'bibcode' | 'editedBy' | 'version' | 'editedOn'
>,
user?: User,
submitter?: string,
createdOn?: number
| 'sub'
| 'submittedHow'
| 'bibcode'
| 'editedBy'
| 'version'
| 'editedOn'
| 'submitter'
| 'createdOn'
> & { submitter?: string; createdOn?: number },
user?: User
) {
validateCircular(item)
if (!user)
Expand Down

0 comments on commit 95f3360

Please sign in to comment.