Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Permissions checks on notification emails do not take into account shares #8109

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Comment notifications not sent on drafts outside collection, sha…
…red docs
  • Loading branch information
tommoor committed Dec 12, 2024
commit a642a81e4739e2cd9bcaaeb9dd8c35bc07dfae03
12 changes: 4 additions & 8 deletions server/emails/templates/CommentCreatedEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}
`;
Expand Down Expand Up @@ -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 && (
<>
Expand Down
16 changes: 9 additions & 7 deletions server/models/helpers/NotificationHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Comment,
View,
} from "@server/models";
import { can } from "@server/policies";

export default class NotificationHelper {
/**
Expand Down Expand Up @@ -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);
}
}
Expand Down