1
0
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:
Toby Zerner
2018-11-11 16:54:15 +10:30
parent 9de786d1e6
commit 17fdc0ebe0
2 changed files with 13 additions and 22 deletions

View File

@@ -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)