Skip to content

Commit

Permalink
Updates the moderation flow to include emails for creation, approval,…
Browse files Browse the repository at this point in the history
… and rejection of requests (nasa-gcn#2074)

Fixes nasa-gcn#2066.
  • Loading branch information
dakota002 authored Mar 11, 2024
1 parent be20f92 commit f2ee090
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/routes/_gcn.circulars/circulars.lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface CircularChangeRequest extends CircularMetadata {
body: string
requestor: string
requestorSub: string
requestorEmail: string
format: CircularFormat
}

Expand Down
33 changes: 33 additions & 0 deletions app/routes/_gcn.circulars/circulars.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '@nasa-gcn/dynamodb-autoincrement'
import { redirect } from '@remix-run/node'
import memoizee from 'memoizee'
import { dedent } from 'ts-dedent'

import { type User, getUser } from '../_gcn._auth/user.server'
import {
Expand All @@ -29,6 +30,8 @@ import type {
CircularChangeRequest,
CircularMetadata,
} from './circulars.lib'
import { sendEmail } from '~/lib/email.server'
import { origin } from '~/lib/env.server'

// A type with certain keys required.
type Require<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>
Expand Down Expand Up @@ -385,8 +388,18 @@ export async function createChangeRequest(
await db.circulars_change_requests.put({
...item,
requestorSub: user.sub,
requestorEmail: user.email,
requestor,
})

await sendEmail({
to: [user.email],
fromName: 'GCN Circulars',
subject: 'GCN Circulars Change Request: Received',
body: dedent`Your change request has been created for GCN Circular ${item.circularId}.
You will receive another email when your request has been reviewed.`,
})
}

/**
Expand Down Expand Up @@ -432,7 +445,18 @@ export async function deleteChangeRequest(
{ status: 403 }
)

const requestorEmail = (await getChangeRequest(circularId, requestorSub))
.requestorEmail
await deleteChangeRequestRaw(circularId, requestorSub)

await sendEmail({
to: [requestorEmail],
fromName: 'GCN Circulars',
subject: 'GCN Circulars Change Request: Rejected',
body: dedent`Your change request has been rejected for GCN Circular ${circularId}.
View the Circular at ${origin}/circulars/${circularId}`,
})
}

/**
Expand Down Expand Up @@ -485,6 +509,15 @@ export async function approveChangeRequest(
})

await deleteChangeRequestRaw(circularId, requestorSub)

await sendEmail({
to: [changeRequest.requestorEmail],
fromName: 'GCN Circulars',
subject: 'GCN Circulars Change Request: Approved',
body: dedent`Your change request has been approved for GCN Circular ${changeRequest.circularId}.
View the Circular at ${origin}/circulars/${changeRequest.circularId}`,
})
}

/**
Expand Down

0 comments on commit f2ee090

Please sign in to comment.