Skip to content

Commit

Permalink
Adds some validations
Browse files Browse the repository at this point in the history
  • Loading branch information
dakota002 committed May 7, 2024
1 parent 0b19738 commit 831dc35
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
15 changes: 9 additions & 6 deletions app/routes/circulars._archive._index/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
createChangeRequest,
get,
getChangeRequests,
moderatorGroup,
put,
putVersion,
search,
Expand Down Expand Up @@ -102,17 +103,19 @@ export async function action({ request }: ActionFunctionArgs) {
if (circularId === undefined)
throw new Response('circularId is required', { status: 400 })
if (!user?.name || !user.email) throw new Response(null, { status: 403 })
const submitter = getFormDataString(data, 'submitter')
const createdOn = getFormDataString(data, 'createdOn')
if (!submitter || !createdOn) throw new Response(null, { status: 400 })
let submitter, createdOn
if (user.groups.includes(moderatorGroup)) {
submitter = getFormDataString(data, 'submitter')
createdOn = getFormDataString(data, 'createdOn')
}
await createChangeRequest(
{
circularId: parseFloat(circularId),
...props,
submitter,
createdOn: parseFloat(createdOn),
},
user
user,
submitter,
createdOn ? parseFloat(createdOn) : undefined
)
await postZendeskRequest({
requester: { name: user.name, email: user.email },
Expand Down
4 changes: 3 additions & 1 deletion app/routes/circulars.edit.$circularId/CircularEditForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { CircularsKeywords } from '~/components/CircularsKeywords'
import CollapsableInfo from '~/components/CollapsableInfo'
import Spinner from '~/components/Spinner'
import TimeAgo from '~/components/TimeAgo'
import { useFeature } from '~/root'
import { useFeature, useModStatus } from '~/root'

function SyntaxExample({
label,
Expand Down Expand Up @@ -179,6 +179,7 @@ export function CircularEditForm({
submitter !== updatedSubmitter?.trim() ||
createdOn !== date

const userIsModerator = useModStatus()
return (
<AstroDataContext.Provider value={{ rel: 'noopener', target: '_blank' }}>
<h1>{headerText} GCN Circular</h1>
Expand All @@ -198,6 +199,7 @@ export function CircularEditForm({
defaultValue={submitter}
onChange={(event) => setUpdatedSubmitter(event.target.value)}
required
disabled={!userIsModerator}
/>
</InputGroup>
</>
Expand Down
20 changes: 16 additions & 4 deletions app/routes/circulars/circulars.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,18 @@ export async function getVersions(circularId: number): Promise<number[]> {
export async function createChangeRequest(
item: Omit<
Circular,
'sub' | 'submittedHow' | 'bibcode' | 'editedBy' | 'version' | 'editedOn'
| 'sub'
| 'submittedHow'
| 'bibcode'
| 'editedBy'
| 'version'
| 'editedOn'
| 'submitter'
| 'createdOn'
>,
user?: User
user?: User,
submitter?: string,
createdOn?: number
) {
validateCircular(item)
if (!user)
Expand All @@ -379,13 +388,16 @@ export async function createChangeRequest(
})
const requestor = formatAuthor(user)
const db = await tables()
const circular = (await db.circulars.get({
circularId: item.circularId,
})) as Circular
await db.circulars_change_requests.put({
...item,
requestorSub: user.sub,
requestorEmail: user.email,
requestor,
createdOn: item.createdOn,
submitter: item.submitter,
createdOn: createdOn ?? circular.createdOn,
submitter: submitter ?? circular.submitter,
})

await sendEmail({
Expand Down

0 comments on commit 831dc35

Please sign in to comment.