Skip to content

Commit

Permalink
Adds option to redistribute email for circulars (#2569)
Browse files Browse the repository at this point in the history
Resolves #2562.
  • Loading branch information
dakota002 authored Sep 9, 2024
1 parent d54e509 commit dd4f9d6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
6 changes: 3 additions & 3 deletions app/lib/kafka.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import { Kafka } from 'gcn-kafka'
import memoizee from 'memoizee'

import { domain, getEnvOrDie } from './env.server'
import { domain, getEnvOrDieInProduction } from './env.server'

const client_id = getEnvOrDie('KAFKA_CLIENT_ID')
const client_secret = getEnvOrDie('KAFKA_CLIENT_SECRET')
const client_id = getEnvOrDieInProduction('KAFKA_CLIENT_ID') ?? ''
const client_secret = getEnvOrDieInProduction('KAFKA_CLIENT_SECRET')
const kafka = new Kafka({
client_id,
client_secret,
Expand Down
18 changes: 16 additions & 2 deletions app/routes/circulars.moderation.$circularId.$requestor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import type { SEOHandle } from '@nasa-gcn/remix-seo'
import type { ActionFunctionArgs, LoaderFunctionArgs } from '@remix-run/node'
import { Form, redirect, useLoaderData } from '@remix-run/react'
import { Button, ButtonGroup } from '@trussworks/react-uswds'
import { Button, ButtonGroup, Checkbox } from '@trussworks/react-uswds'
import { diffLines, diffWords } from 'diff'

import { getUser } from './_auth/user.server'
Expand Down Expand Up @@ -41,11 +41,18 @@ export async function action({
throw new Response(null, { status: 403 })
const data = await request.formData()
const intent = getFormDataString(data, 'intent')
const redistribute = getFormDataString(data, 'redistribute') === 'on'

if (!intent || !circularId || !requestor)
throw new Response(null, { status: 400 })
switch (intent) {
case 'approve':
await approveChangeRequest(parseFloat(circularId), requestor, user)
await approveChangeRequest(
parseFloat(circularId),
requestor,
user,
redistribute
)
break
case 'reject':
await deleteChangeRequest(parseFloat(circularId), requestor, user)
Expand Down Expand Up @@ -100,6 +107,13 @@ export default function () {
<h3>Body</h3>
<DiffedContent oldString={circular.body} newString={correction.body} />
<Form method="POST">
<Checkbox
id="redistribute"
name="redistribute"
label="Redistribute new version as an email"
labelDescription="Only select this option if the change alters the factual content of the Circular."
className="margin-y-1"
/>
<ButtonGroup>
<Button type="submit" name="intent" value="approve">
Approve
Expand Down
28 changes: 17 additions & 11 deletions app/routes/circulars/circulars.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type {
import { sendEmail } from '~/lib/email.server'
import { feature, origin } from '~/lib/env.server'
import { closeZendeskTicket } from '~/lib/zendesk.server'
import { send } from '~/table-streams/circulars'

// A type with certain keys required.
type Require<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>
Expand Down Expand Up @@ -516,7 +517,8 @@ async function deleteChangeRequestRaw(
export async function approveChangeRequest(
circularId: number,
requestorSub: string,
user: User
user: User,
redistribute: boolean
) {
if (!user?.groups.includes(moderatorGroup))
throw new Response('User is not in the moderators group', {
Expand All @@ -527,17 +529,19 @@ export async function approveChangeRequest(
const circular = await get(circularId)
const autoincrementVersion = await getDynamoDBVersionAutoIncrement(circularId)

const newVersion = {
...circular,
body: changeRequest.body,
subject: changeRequest.subject,
editedBy: `${formatAuthor(user)} on behalf of ${changeRequest.requestor}`,
editedOn: Date.now(),
format: changeRequest.format,
submitter: changeRequest.submitter,
createdOn: changeRequest.createdOn ?? circular.createdOn, // This is temporary while there are some requests without this property
}

const promises = [
autoincrementVersion.put({
...circular,
body: changeRequest.body,
subject: changeRequest.subject,
editedBy: `${formatAuthor(user)} on behalf of ${changeRequest.requestor}`,
editedOn: Date.now(),
format: changeRequest.format,
submitter: changeRequest.submitter,
createdOn: changeRequest.createdOn ?? circular.createdOn, // This is temporary while there are some requests without this property
}),
autoincrementVersion.put(newVersion),
deleteChangeRequestRaw(circularId, requestorSub),
sendEmail({
to: [changeRequest.requestorEmail],
Expand All @@ -549,6 +553,8 @@ export async function approveChangeRequest(
}),
]

if (redistribute) promises.push(send(newVersion))

if (changeRequest.zendeskTicketId)
promises.push(closeZendeskTicket(changeRequest.zendeskTicketId))

Expand Down
4 changes: 4 additions & 0 deletions app/routes/docs.circulars.corrections/route.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Anyone with a [peer endorsement](/docs/circulars/submitting#to-request-a-peer-en
3. The moderator will either immediately approve or reject the request, or contact the original submitter (if different from the request submitter) via email for clarification or concurrence before accepting or rejecting the request.
4. The requester will receive an email when the ticket is closed.

## Redistribution

Our Kafka producer will always produce a new message whenever a change is made to a circular. We may also redistribute the circular via email. This is up to the discretion of the reviewer, determined by whether or not there is a significant update to anything related to the data in the circular.

## View the revision history

A version history for revised Circulars is publicly viewable in the archive with the "Versions" dropdown. Information about the revision are added to the Circular header including when it was edited, who requested the edit, and which GCN moderator implemented the edits. The path `https://gcn.nasa.gov/circulars/{circularID}` will always point to the latest version of the Circular.
Expand Down
2 changes: 1 addition & 1 deletion app/table-streams/circulars/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async function getLegacyEmails() {
return emails
}

async function send(circular: Circular) {
export async function send(circular: Circular) {
const [emails, legacyEmails] = await Promise.all([
getEmails(),
getLegacyEmails(),
Expand Down

0 comments on commit dd4f9d6

Please sign in to comment.