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

View File

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

View File

@ -1,7 +1,13 @@
// @flow
import { Op } from '../sequelize';
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';
export default class Notifications {
@ -29,6 +35,9 @@ export default class Notifications {
const { collection } = document;
if (!collection) return;
const team = await Team.findByPk(document.teamId);
if (!team) return;
const notificationSettings = await NotificationSetting.findAll({
where: {
userId: {
@ -51,11 +60,11 @@ export default class Notifications {
notificationSettings.forEach(setting => {
// 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
if (
event.name === 'documents.update' &&
document.createdById !== setting.userId
!document.collaboratorIds.includes(setting.userId)
) {
return;
}
@ -64,6 +73,7 @@ export default class Notifications {
to: setting.user.email,
eventName,
document,
team,
collection,
actor: document.updatedBy,
unsubscribeUrl: setting.unsubscribeUrl,