From 02d33267ccfe9fdcc9d9f7516dc509d58f26b463 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 5 Apr 2020 16:04:46 -0700 Subject: [PATCH] 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 --- server/emails/DocumentNotificationEmail.js | 11 ++++++----- server/mailer.js | 4 ++-- server/services/notifications.js | 16 +++++++++++++--- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/server/emails/DocumentNotificationEmail.js b/server/emails/DocumentNotificationEmail.js index 11c6af8d..dc3199ae 100644 --- a/server/emails/DocumentNotificationEmail.js +++ b/server/emails/DocumentNotificationEmail.js @@ -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 = ({

{document.getSummary()}

- +

diff --git a/server/mailer.js b/server/mailer.js index 72f724e1..985c85bc 100644 --- a/server/mailer.js +++ b/server/mailer.js @@ -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: , 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: , text: collectionNotificationEmailText(opts), diff --git a/server/services/notifications.js b/server/services/notifications.js index 80bfd57c..badc321a 100644 --- a/server/services/notifications.js +++ b/server/services/notifications.js @@ -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,