mirror of
https://github.com/outline/outline.git
synced 2026-11-25 23:24:06 +03:00
fix: Permissions checks on notification emails do not take into account shares (#8109)
* fix: Comment notifications not sent on drafts outside collection, shared docs * fix: DocumentPublishedOrUpdatedEmail not sent for drafts * tsc
This commit is contained in:
1 parent
e89c32424f
commit
8b15cc45b0
3 files changed
+21
-23
No files matched your search
@@ -24,7 +24,7 @@ type InputProps = EmailProps & {
|
||||
|
||||
type BeforeSend = {
|
||||
document: Document;
|
||||
collection: Collection;
|
||||
collection: Collection | null;
|
||||
body: string | undefined;
|
||||
isFirstComment: boolean;
|
||||
isReply: boolean;
|
||||
@@ -52,14 +52,10 @@ export default class CommentCreatedEmail extends BaseEmail<
|
||||
return false;
|
||||
}
|
||||
|
||||
const collection = await document.$get("collection");
|
||||
if (!collection) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const [comment, team] = await Promise.all([
|
||||
const [comment, team, collection] = await Promise.all([
|
||||
Comment.findByPk(commentId),
|
||||
document.$get("team"),
|
||||
document.$get("collection"),
|
||||
]);
|
||||
if (!comment || !team) {
|
||||
return false;
|
||||
@@ -129,7 +125,7 @@ export default class CommentCreatedEmail extends BaseEmail<
|
||||
return `
|
||||
${actorName} ${isReply ? "replied to a thread in" : "commented on"} "${
|
||||
document.title
|
||||
}"${collection.name ? `in the ${collection.name} collection` : ""}.
|
||||
}"${collection?.name ? `in the ${collection.name} collection` : ""}.
|
||||
|
||||
Open Thread: ${teamUrl}${document.url}?commentId=${commentId}
|
||||
`;
|
||||
@@ -160,7 +156,7 @@ Open Thread: ${teamUrl}${document.url}?commentId=${commentId}
|
||||
<p>
|
||||
{actorName} {isReply ? "replied to a thread in" : "commented on"}{" "}
|
||||
<a href={threadLink}>{document.title}</a>{" "}
|
||||
{collection.name ? `in the ${collection.name} collection` : ""}.
|
||||
{collection?.name ? `in the ${collection.name} collection` : ""}.
|
||||
</p>
|
||||
{body && (
|
||||
<>
|
||||
|
||||
@@ -31,7 +31,7 @@ type InputProps = EmailProps & {
|
||||
|
||||
type BeforeSend = {
|
||||
document: Document;
|
||||
collection: Collection;
|
||||
collection: Collection | null;
|
||||
unsubscribeUrl: string;
|
||||
body: string | undefined;
|
||||
};
|
||||
@@ -63,9 +63,6 @@ export default class DocumentPublishedOrUpdatedEmail extends BaseEmail<
|
||||
document.$get("collection"),
|
||||
document.$get("team"),
|
||||
]);
|
||||
if (!collection) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let body;
|
||||
if (revisionId && team?.getPreference(TeamPreference.PreviewsInEmails)) {
|
||||
@@ -149,7 +146,9 @@ export default class DocumentPublishedOrUpdatedEmail extends BaseEmail<
|
||||
return `
|
||||
"${document.title}" ${eventName}
|
||||
|
||||
${actorName} ${eventName} the document "${document.title}", in the ${collection.name} collection.
|
||||
${actorName} ${eventName} the document "${document.title}"${
|
||||
collection?.name ? `, in the ${collection.name} collection` : ""
|
||||
}.
|
||||
|
||||
Open Document: ${teamUrl}${document.url}
|
||||
`;
|
||||
@@ -181,8 +180,9 @@ Open Document: ${teamUrl}${document.url}
|
||||
</Heading>
|
||||
<p>
|
||||
{actorName} {eventName} the document{" "}
|
||||
<a href={documentLink}>{document.title}</a>, in the{" "}
|
||||
{collection.name} collection.
|
||||
<a href={documentLink}>{document.title}</a>
|
||||
{collection?.name ? <>, in the {collection.name} collection</> : ""}
|
||||
.
|
||||
</p>
|
||||
{body && (
|
||||
<>
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
Comment,
|
||||
View,
|
||||
} from "@server/models";
|
||||
import { can } from "@server/policies";
|
||||
|
||||
export default class NotificationHelper {
|
||||
/**
|
||||
@@ -161,17 +162,18 @@ export default class NotificationHelper {
|
||||
const filtered = [];
|
||||
|
||||
for (const recipient of recipients) {
|
||||
const collectionIds = await recipient.collectionIds();
|
||||
if (!recipient.email || recipient.isSuspended) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check the recipient has access to the collection this document is in. Just
|
||||
// because they are subscribed doesn't mean they still have access to read
|
||||
// the document.
|
||||
if (
|
||||
recipient.email &&
|
||||
!recipient.isSuspended &&
|
||||
document.collectionId &&
|
||||
collectionIds.includes(document.collectionId)
|
||||
) {
|
||||
const doc = await Document.findByPk(document.id, {
|
||||
userId: recipient.id,
|
||||
});
|
||||
|
||||
if (can(recipient, "read", doc)) {
|
||||
filtered.push(recipient);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user