-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into dupe-rsvp-msg
- Loading branch information
Showing
48 changed files
with
1,134 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
api/db/migrations/20241120055143_add_ignored_emails/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-- CreateTable | ||
CREATE TABLE "IgnoredEmail" ( | ||
"id" SERIAL NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"email" TEXT NOT NULL, | ||
CONSTRAINT "IgnoredEmail_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "IgnoredEmail_email_key" ON "IgnoredEmail"("email"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export const schema = gql` | ||
type IgnoredEmail { | ||
id: Int! | ||
createdAt: DateTime! | ||
updatedAt: DateTime! | ||
email: String! | ||
} | ||
input IgnoredEmailInput { | ||
email: String! | ||
token: String! | ||
} | ||
type Query { | ||
ignoredEmail(input: IgnoredEmailInput!): IgnoredEmail @requireAuth | ||
} | ||
type Mutation { | ||
createIgnoredEmail(input: IgnoredEmailInput!): IgnoredEmail! @requireAuth | ||
deleteIgnoredEmail(input: IgnoredEmailInput!): IgnoredEmail! @requireAuth | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import querystring from 'querystring' | ||
|
||
import { CI, RECAPTCHA_SERVER_KEY } from 'src/app.config' | ||
|
||
import { logger } from './logger' | ||
|
||
const RECAPTCHA_ENDPOINT = 'https://www.google.com/recaptcha/api/siteverify' | ||
|
||
/** Return true if the given captcha token was valid, false otherwise. */ | ||
export async function validateCaptcha(token: string): Promise<boolean> { | ||
if (CI) return true | ||
try { | ||
const data = { secret: RECAPTCHA_SERVER_KEY, response: token } | ||
const res = await fetch(RECAPTCHA_ENDPOINT, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, | ||
body: querystring.stringify(data), | ||
}) | ||
const json = await res.json() | ||
logger.debug({ json }, 'reCAPTCHA response') | ||
return json.success | ||
} catch (err) { | ||
logger.error({ err }, 'Failed to validate reCAPTCHA') | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
import { InMemoryMailHandler } from '@redwoodjs/mailer-handler-in-memory' | ||
|
||
import { db } from '../db' | ||
import { mailer } from '../mailer' | ||
|
||
import { sendEmail } from './send' | ||
|
||
describe('mailer', () => { | ||
const testHandler = mailer.getTestHandler() as InMemoryMailHandler | ||
beforeEach(async () => { | ||
await testHandler.clearInbox() | ||
}) | ||
|
||
it('sends an email', async () => { | ||
const testHandler = mailer.getTestHandler() as InMemoryMailHandler | ||
expect(testHandler.inbox).toHaveLength(0) | ||
|
||
const params = { | ||
|
@@ -27,16 +32,46 @@ describe('mailer', () => { | |
"handler": "nodemailer", | ||
"handlerOptions": undefined, | ||
"headers": {}, | ||
"htmlContent": "Leave this email here", | ||
"htmlContent": null, | ||
"renderer": "plain", | ||
"rendererOptions": {}, | ||
"replyTo": undefined, | ||
"subject": "Don't delete me", | ||
"textContent": "Leave this email here", | ||
"textContent": "Leave this email here | ||
To unsubscribe from all Freevite emails forever, click here: | ||
https://example.com/unsubscribe?email=darlene%40fs0ciety.pizza&token=U4_qTnHZg6tTAKBEdY8C_CxVQsqP12HtTqmhYQ05Ywc", | ||
"to": [ | ||
"[email protected]", | ||
], | ||
} | ||
`) | ||
}) | ||
|
||
describe('when users are on the ignore list', () => { | ||
beforeEach(async () => { | ||
await db.ignoredEmail.create({ data: { email: '[email protected]' } }) | ||
}) | ||
afterEach(async () => { | ||
await db.ignoredEmail.deleteMany() | ||
}) | ||
|
||
it('obeys the ignore list', async () => { | ||
expect(testHandler.inbox).toHaveLength(0) | ||
await sendEmail({ | ||
to: '[email protected]', | ||
subject: "You're invited to End of the World Party", | ||
text: 'Bring your own mask', | ||
}) | ||
expect(testHandler.inbox).toHaveLength(0) | ||
|
||
// but it still sends to other addresses | ||
await sendEmail({ | ||
to: '[email protected]', | ||
subject: 'Looking for an update on the malware presentation', | ||
text: 'Please send ASAP', | ||
}) | ||
expect(testHandler.inbox).toHaveLength(1) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ describe('with test handler', () => { | |
"handler": "nodemailer", | ||
"handlerOptions": undefined, | ||
"headers": {}, | ||
"htmlContent": "Hello from Freevite! Click this link to manage your event details and make it public:<br><br>https://example.com/edit?token=SOME-EDIT-TOKEN<br><br>You must click the above link within 24 hours to confirm your email address.<br>Otherwise, we will automatically delete your event. Feel free to recreate it.<br><br>If you did not create this event, you can ignore this email and this event will be deleted.<br><br>If you need any help, just reply to this email. Thanks for using Freevite!", | ||
"htmlContent": null, | ||
"renderer": "plain", | ||
"rendererOptions": {}, | ||
"replyTo": undefined, | ||
|
@@ -45,7 +45,10 @@ Otherwise, we will automatically delete your event. Feel free to recreate it. | |
If you did not create this event, you can ignore this email and this event will be deleted. | ||
If you need any help, just reply to this email. Thanks for using Freevite!", | ||
If you need any help, just reply to this email. Thanks for using Freevite! | ||
To unsubscribe from all Freevite emails forever, click here: | ||
https://example.com/unsubscribe?email=emma%40example.com&token=8RHP9HXHbkVfnYJ_6H5xSWGL6_5o6Er7aeoYW5SBGNg", | ||
"to": [ | ||
"[email protected]", | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ describe('with test handler', () => { | |
"handler": "nodemailer", | ||
"handlerOptions": undefined, | ||
"headers": {}, | ||
"htmlContent": "Hello from Freevite! You asked for a reminder about this event when you RSVPed:<br><br>Emma's Holiday Party<br>Starts at: Sun Dec 25, 2022, 7:00 AM EST (in a day))<br>Ends at: Sun Dec 25, 2022, 10:00 AM EST (3 hours long)<br><br>View the event here:<br>https://example.com/events/emmas-holiday-party<br><br>Thanks for using Freevite!", | ||
"htmlContent": null, | ||
"renderer": "plain", | ||
"rendererOptions": {}, | ||
"replyTo": undefined, | ||
|
@@ -51,7 +51,10 @@ Ends at: Sun Dec 25, 2022, 10:00 AM EST (3 hours long) | |
View the event here: | ||
https://example.com/events/emmas-holiday-party | ||
Thanks for using Freevite!", | ||
Thanks for using Freevite! | ||
To unsubscribe from all Freevite emails forever, click here: | ||
https://example.com/unsubscribe?email=holmes%40example.com&token=gDd6UhfXCs8ipE9rs9JuUN5lwNUgSJjs6NXyZXdUgm4", | ||
"to": [ | ||
"[email protected]", | ||
], | ||
|
Oops, something went wrong.