mirror of
https://github.com/flarum/framework.git
synced 2024-12-12 14:13:37 +08:00
Fix post visibility scoping
This commit is contained in:
parent
8d89b4a776
commit
2e5cccd5e6
|
@ -5,6 +5,7 @@ use Flarum\Events\DiscussionWasDeleted;
|
|||
use Flarum\Events\DiscussionWasStarted;
|
||||
use Flarum\Events\DiscussionWasRenamed;
|
||||
use Flarum\Events\PostWasDeleted;
|
||||
use Flarum\Events\ScopePostVisibility;
|
||||
use Flarum\Core\Posts\Post;
|
||||
use Flarum\Core\Posts\MergeablePost;
|
||||
use Flarum\Core\Users\Guest;
|
||||
|
@ -65,13 +66,6 @@ class Discussion extends Model
|
|||
*/
|
||||
protected static $stateUser;
|
||||
|
||||
/**
|
||||
* An array of callables that apply constraints to the postsVisibleTo query.
|
||||
*
|
||||
* @var callable[]
|
||||
*/
|
||||
protected static $postVisibilityScopes = [];
|
||||
|
||||
/**
|
||||
* Boot the model.
|
||||
*
|
||||
|
@ -262,11 +256,9 @@ class Discussion extends Model
|
|||
*/
|
||||
public function postsVisibleTo(User $user)
|
||||
{
|
||||
$query = $this->posts();
|
||||
$query = $this->posts()->getQuery();
|
||||
|
||||
foreach (static::$postVisibilityScopes as $scope) {
|
||||
$scope($query, $user, $this);
|
||||
}
|
||||
event(new ScopePostVisibility($this, $query, $user));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
@ -393,16 +385,4 @@ class Discussion extends Model
|
|||
{
|
||||
static::$stateUser = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constrain which posts are visible to a user.
|
||||
*
|
||||
* @param callable $scope A callback that applies constraints to the posts
|
||||
* query. It is passed three parameters: the query builder object, the
|
||||
* user to constrain posts for, and the discussion instance.
|
||||
*/
|
||||
public static function addPostVisibilityScope(callable $scope)
|
||||
{
|
||||
static::$postVisibilityScopes[] = $scope;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user