From 6ba7269dacb62090f1be6d8cbaad24230d522e10 Mon Sep 17 00:00:00 2001 From: dakota002 Date: Tue, 7 May 2024 10:01:34 -0400 Subject: [PATCH] Adds some validations --- .../circulars._archive._index/route.tsx | 15 ++++++++------ .../CircularEditForm.tsx | 4 +++- app/routes/circulars/circulars.server.ts | 20 +++++++++++++++---- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/app/routes/circulars._archive._index/route.tsx b/app/routes/circulars._archive._index/route.tsx index d6d5a75649..e4a9f80aa1 100644 --- a/app/routes/circulars._archive._index/route.tsx +++ b/app/routes/circulars._archive._index/route.tsx @@ -36,6 +36,7 @@ import { createChangeRequest, get, getChangeRequests, + moderatorGroup, put, putVersion, search, @@ -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 }, diff --git a/app/routes/circulars.edit.$circularId/CircularEditForm.tsx b/app/routes/circulars.edit.$circularId/CircularEditForm.tsx index 1ad7dfcee5..94e0386f9a 100644 --- a/app/routes/circulars.edit.$circularId/CircularEditForm.tsx +++ b/app/routes/circulars.edit.$circularId/CircularEditForm.tsx @@ -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, @@ -179,6 +179,7 @@ export function CircularEditForm({ submitter !== updatedSubmitter?.trim() || createdOn !== date + const userIsModerator = useModStatus() return (

{headerText} GCN Circular

@@ -198,6 +199,7 @@ export function CircularEditForm({ defaultValue={submitter} onChange={(event) => setUpdatedSubmitter(event.target.value)} required + disabled={!userIsModerator} /> diff --git a/app/routes/circulars/circulars.server.ts b/app/routes/circulars/circulars.server.ts index 295857697b..3acf25bf46 100644 --- a/app/routes/circulars/circulars.server.ts +++ b/app/routes/circulars/circulars.server.ts @@ -368,9 +368,18 @@ export async function getVersions(circularId: number): Promise { 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) @@ -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({