mirror of
https://github.com/flarum/core.git
synced 2025-10-23 20:56:05 +02:00
Consolidate Post visibility logic into the PostPolicy
A post can only be seen if the discussion in which it resides can be seen. The logic for this belongs in the policy, not the model.
This commit is contained in:
@@ -66,6 +66,17 @@ class PostPolicy extends AbstractPolicy
|
||||
*/
|
||||
public function find(User $actor, $query)
|
||||
{
|
||||
// Make sure the post's discussion is visible as well.
|
||||
$query->whereExists(function ($query) use ($actor) {
|
||||
$query->selectRaw('1')
|
||||
->from('discussions')
|
||||
->whereColumn('discussions.id', 'posts.discussion_id');
|
||||
|
||||
$this->events->dispatch(
|
||||
new ScopeModelVisibility(Discussion::query()->setQuery($query), $actor, 'view')
|
||||
);
|
||||
});
|
||||
|
||||
// Hide private posts by default.
|
||||
$query->where(function ($query) use ($actor) {
|
||||
$query->where('posts.is_private', false)
|
||||
|
Reference in New Issue
Block a user