1
0
mirror of https://github.com/flarum/core.git synced 2025-07-22 01:01:28 +02:00
Files
php-flarum/src/Core/Access/UserPolicy.php
Toby Zerner beb2f91fef Fix posts being incorrectly visible on user page. closes #680
- When no discussions are visible, the query that filters posts by discussion visibility was incorrectly making all posts visible.
- Also hide user profiles altogether if discussions are not visible.
2016-03-10 17:50:29 +10:30

46 lines
921 B
PHP

<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Core\Access;
use Flarum\Core\User;
use Illuminate\Database\Eloquent\Builder;
class UserPolicy extends AbstractPolicy
{
/**
* {@inheritdoc}
*/
protected $model = User::class;
/**
* @param User $actor
* @param string $ability
* @return bool|null
*/
public function before(User $actor, $ability)
{
if ($actor->hasPermission('user.'.$ability)) {
return true;
}
}
/**
* @param User $actor
* @param Builder $query
*/
public function find(User $actor, Builder $query)
{
if ($actor->cannot('viewDiscussions')) {
$query->whereRaw('FALSE');
}
}
}