fix: Document updated email does include team subdomain in url

fix: Send document updated emails to any collaborators
fix: Correct quotation marks in email subjects
This commit is contained in:
Tom Moor
2020-04-05 16:04:46 -07:00
parent b964bdbe90
commit 02d33267cc
3 changed files with 21 additions and 10 deletions

View File

@ -1,6 +1,6 @@
// @flow // @flow
import * as React from 'react'; import * as React from 'react';
import { User, Document, Collection } from '../models'; import { User, Document, Team, Collection } from '../models';
import EmailTemplate from './components/EmailLayout'; import EmailTemplate from './components/EmailLayout';
import Body from './components/Body'; import Body from './components/Body';
import Button from './components/Button'; import Button from './components/Button';
@ -11,6 +11,7 @@ import EmptySpace from './components/EmptySpace';
export type Props = { export type Props = {
actor: User, actor: User,
team: Team,
document: Document, document: Document,
collection: Collection, collection: Collection,
eventName: string, eventName: string,
@ -19,6 +20,7 @@ export type Props = {
export const documentNotificationEmailText = ({ export const documentNotificationEmailText = ({
actor, actor,
team,
document, document,
collection, collection,
eventName = 'published', eventName = 'published',
@ -29,11 +31,12 @@ ${actor.name} ${eventName} the document "${document.title}", in the ${
collection.name collection.name
} collection. } collection.
Open Document: ${process.env.URL}${document.url} Open Document: ${team.url}${document.url}
`; `;
export const DocumentNotificationEmail = ({ export const DocumentNotificationEmail = ({
actor, actor,
team,
document, document,
collection, collection,
eventName = 'published', eventName = 'published',
@ -56,9 +59,7 @@ export const DocumentNotificationEmail = ({
<p>{document.getSummary()}</p> <p>{document.getSummary()}</p>
<EmptySpace height={10} /> <EmptySpace height={10} />
<p> <p>
<Button href={`${process.env.URL}${document.url}`}> <Button href={`${team.url}${document.url}`}>Open Document</Button>
Open Document
</Button>
</p> </p>
</Body> </Body>

View File

@ -139,7 +139,7 @@ export class Mailer {
) => { ) => {
this.sendMail({ this.sendMail({
to: opts.to, to: opts.to,
title: `"${opts.document.title}" ${opts.eventName}`, title: `${opts.document.title} ${opts.eventName}`,
previewText: `${opts.actor.name} ${opts.eventName} a new document`, previewText: `${opts.actor.name} ${opts.eventName} a new document`,
html: <DocumentNotificationEmail {...opts} />, html: <DocumentNotificationEmail {...opts} />,
text: documentNotificationEmailText(opts), text: documentNotificationEmailText(opts),
@ -151,7 +151,7 @@ export class Mailer {
) => { ) => {
this.sendMail({ this.sendMail({
to: opts.to, to: opts.to,
title: `"${opts.collection.name}" ${opts.eventName}`, title: `${opts.collection.name} ${opts.eventName}`,
previewText: `${opts.actor.name} ${opts.eventName} a collection`, previewText: `${opts.actor.name} ${opts.eventName} a collection`,
html: <CollectionNotificationEmail {...opts} />, html: <CollectionNotificationEmail {...opts} />,
text: collectionNotificationEmailText(opts), text: collectionNotificationEmailText(opts),

View File

@ -1,7 +1,13 @@
// @flow // @flow
import { Op } from '../sequelize'; import { Op } from '../sequelize';
import type { DocumentEvent, CollectionEvent, Event } from '../events'; import type { DocumentEvent, CollectionEvent, Event } from '../events';
import { Document, Collection, User, NotificationSetting } from '../models'; import {
Document,
Team,
Collection,
User,
NotificationSetting,
} from '../models';
import mailer from '../mailer'; import mailer from '../mailer';
export default class Notifications { export default class Notifications {
@ -29,6 +35,9 @@ export default class Notifications {
const { collection } = document; const { collection } = document;
if (!collection) return; if (!collection) return;
const team = await Team.findByPk(document.teamId);
if (!team) return;
const notificationSettings = await NotificationSetting.findAll({ const notificationSettings = await NotificationSetting.findAll({
where: { where: {
userId: { userId: {
@ -51,11 +60,11 @@ export default class Notifications {
notificationSettings.forEach(setting => { notificationSettings.forEach(setting => {
// For document updates we only want to send notifications if // For document updates we only want to send notifications if
// the document creator matches the notification setting. // the document has been edited by the user with this notification setting
// This could be replaced with ability to "follow" in the future // This could be replaced with ability to "follow" in the future
if ( if (
event.name === 'documents.update' && event.name === 'documents.update' &&
document.createdById !== setting.userId !document.collaboratorIds.includes(setting.userId)
) { ) {
return; return;
} }
@ -64,6 +73,7 @@ export default class Notifications {
to: setting.user.email, to: setting.user.email,
eventName, eventName,
document, document,
team,
collection, collection,
actor: document.updatedBy, actor: document.updatedBy,
unsubscribeUrl: setting.unsubscribeUrl, unsubscribeUrl: setting.unsubscribeUrl,