mirror of
https://github.com/flarum/core.git
synced 2025-10-12 07:24:27 +02:00
making posts and discussions private (#1153)
* flagrow/byobu#11 making posts and discussions private * tested migrations and tested setting is_private on discussion and post manually * added phpdoc for Post and Discussion and added the casting for these attributes * satisfying styleci * fixes for review * added new private discussion event and included it in the access policy * added new private post event and included it in the access policy
This commit is contained in:
committed by
Toby Zerner
parent
4c0339c30e
commit
04c4806f6f
@@ -15,6 +15,7 @@ use Carbon\Carbon;
|
||||
use Flarum\Core\Post;
|
||||
use Flarum\Core\User;
|
||||
use Flarum\Event\ScopePostVisibility;
|
||||
use Flarum\Event\ScopePrivatePostVisibility;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
@@ -29,13 +30,18 @@ class PostPolicy extends AbstractPolicy
|
||||
* @var SettingsRepositoryInterface
|
||||
*/
|
||||
protected $settings;
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
/**
|
||||
* @param SettingsRepositoryInterface $settings
|
||||
*/
|
||||
public function __construct(SettingsRepositoryInterface $settings)
|
||||
public function __construct(SettingsRepositoryInterface $settings, Dispatcher $events)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
$this->events = $events;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,6 +72,15 @@ class PostPolicy extends AbstractPolicy
|
||||
*/
|
||||
public function scopePostVisibility(ScopePostVisibility $event)
|
||||
{
|
||||
// Hide private posts per default.
|
||||
$event->query->where(function ($query) use ($event) {
|
||||
$query->where('posts.is_private', false);
|
||||
|
||||
$this->events->fire(
|
||||
new ScopePrivatePostVisibility($event->discussion, $query, $event->actor)
|
||||
);
|
||||
});
|
||||
|
||||
// When fetching a discussion's posts: if the user doesn't have permission
|
||||
// to moderate the discussion, then they can't see posts that have been
|
||||
// hidden by someone other than themself.
|
||||
|
Reference in New Issue
Block a user