-
-
Notifications
You must be signed in to change notification settings - Fork 833
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(subscriptions): post notifications not getting access checked
Signed-off-by: Sami Mazouz <[email protected]>
- Loading branch information
Showing
3 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
extensions/subscriptions/src/Notification/FilterVisiblePostsBeforeSending.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Flarum\Subscriptions\Notification; | ||
|
||
use Flarum\Notification\Blueprint\BlueprintInterface; | ||
|
||
class FilterVisiblePostsBeforeSending | ||
{ | ||
public function __invoke(BlueprintInterface $blueprint, array $recipients): array | ||
{ | ||
if ($blueprint instanceof NewPostBlueprint) { | ||
$newRecipients = []; | ||
|
||
// Flarum has built-in access control for the notification subject, | ||
// but subscriptions post notifications has the discussion as the subject. | ||
// We'll add a post visibility check so that users can't get access to hidden replies by subscribing. | ||
foreach ($recipients as $recipient) { | ||
if ($blueprint->post->isVisibleTo($recipient)) { | ||
$newRecipients[] = $recipient; | ||
} | ||
} | ||
|
||
return $newRecipients; | ||
} | ||
|
||
return $recipients; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters