Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Commit

Permalink
close #50
Browse files Browse the repository at this point in the history
  • Loading branch information
sballesteros committed Dec 14, 2019
1 parent 8d3679d commit 021b14b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ Redis](https://docs.microsoft.com/en-us/azure/azure-cache-for-redis/) to store:
- session data
- cached data for the payload of the public API.

We use [Sendgrid (from the Azure
marketplace)](https://azuremarketplace.microsoft.com/en-us/marketplace/apps/SendGrid.SendGrid)
for emails.

#### Process

##### Cloudant
Expand Down
3 changes: 2 additions & 1 deletion src/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import { createCacheKey } from './middlewares/cache';

const compiler = webpack(webpackConfig);

const logger = pino({ level: 'fatal' });
const logger = pino({ level: 'error' });

const config = {
sendgridApiKey: null, // disable emails
pino: logger,
cache: true,
disableSsr: true
Expand Down
51 changes: 50 additions & 1 deletion src/utils/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
} from '../constants';

export function createSendgridEmailClient(config = {}) {
if (config.sendgridApiKey === null) {
return null;
}
const apiKey = config.sendgridApiKey || process.env.SENDGRID_API_KEY;

if (apiKey) {
Expand All @@ -17,7 +20,10 @@ export function createSendgridEmailClient(config = {}) {
return null;
}

export async function sendEmails({ emailClient, db, redis }, action) {
export async function sendEmails(
{ emailClient, db, redis },
action // result from db.post (so `action.result` is defined)
) {
let subject, text;

switch (action['@type']) {
Expand All @@ -35,6 +41,7 @@ export async function sendEmails({ emailClient, db, redis }, action) {
text = `Hello,
A new user just registered.
- public profile: ${PRODUCTION_DOMAIN}/about/${unprefix(getId(publicRole))}
- anonymous profile: ${PRODUCTION_DOMAIN}/about/${unprefix(getId(anonRole))}
Expand All @@ -44,17 +51,59 @@ Have a good day!
break;

case 'ReportRapidPREreviewAction': {
const reviewAction = action.result;
subject = 'New moderation report';
text = `Hello,
A new moderation report was just posted.
- reported by: ${PRODUCTION_DOMAIN}/about/${unprefix(getId(action.agent))}
- about:
- title: ${reviewAction.object.name}
- url: ${PRODUCTION_DOMAIN}/${unprefix(
getId(reviewAction.object.doi || reviewAction.object.arXivId)
)}?role=${unprefix(getId(reviewAction.agent))}
You can act on it from your moderation panel: ${PRODUCTION_DOMAIN}/moderate
Have a good day!
`;
break;
}

case 'RapidPREreviewAction': {
subject = 'New Rapid PREreview';
text = `Hello,
A new Rapid PREreview was just posted.
- posted by: ${PRODUCTION_DOMAIN}/about/${unprefix(getId(action.agent))}
- about:
- title: ${action.object.name}
- url: ${PRODUCTION_DOMAIN}/${unprefix(
getId(action.object.doi || action.object.arXivId)
)}?role=${unprefix(getId(action.agent))}
Have a good day!
`;
break;
}

case 'RequestForRapidPREreviewAction': {
subject = 'New Request for Rapid PREreview';
text = `Hello,
A new Request for Rapid PREreview was just posted.
- posted by: ${PRODUCTION_DOMAIN}/about/${unprefix(getId(action.agent))}
- about:
- title: ${action.object.name}
- url: ${PRODUCTION_DOMAIN}/${unprefix(
getId(action.object.doi || action.object.arXivId)
)}
Have a good day!
`;
break;
}

Expand Down

0 comments on commit 021b14b

Please sign in to comment.